Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用ESP32 SQLite3执行SQL计数?_Sqlite_Arduino_Esp32 - Fatal编程技术网

如何使用ESP32 SQLite3执行SQL计数?

如何使用ESP32 SQLite3执行SQL计数?,sqlite,arduino,esp32,Sqlite,Arduino,Esp32,我花了很长时间寻找这个问题的答案,但我不能完全理解它 基本上,我有一个连接到esp32的sd卡上的sqlite db。SQLite可以完美地工作,并且在使用标准示例代码时会返回。例如: rc = db_exec(db2, "Select * from domain_rank where domain between 'google.com' and 'google.com.z'"); if (rc != SQLITE_OK) { sqlite3_close(db1); sql

我花了很长时间寻找这个问题的答案,但我不能完全理解它

基本上,我有一个连接到esp32的sd卡上的sqlite db。SQLite可以完美地工作,并且在使用标准示例代码时会返回。例如:

rc = db_exec(db2, "Select * from domain_rank where domain between 'google.com' and 'google.com.z'");
if (rc != SQLITE_OK) {
sqlite3_close(db1);
sqlite3_close(db2);
return;
}`
这将查看草图中的“db_exec”函数,然后将其传递给“callback”函数。没有这个有什么办法吗?我要做的就是计算select语句中的记录数

谢谢


安德鲁

好的,我想我可能已经找到了解决办法

把它放在这里以防其他人感兴趣

 String sql = "Select count(*) from surnames where name = 'MICHELLE'";
 rc = sqlite3_prepare_v2(db1, sql.c_str(), 1000, &res, &tail);
 if (rc != SQLITE_OK) {
      String resp = "Failed to fetch data: ";
      Serial.println(resp.c_str());
      return;
  }
 while (sqlite3_step(res) == SQLITE_ROW) {
      rec_count = sqlite3_column_int(res, 0);
 }

      Serial.println(rec_count);
我不能完全理解while循环是如何计算单元格的,我认为sqlcount*查询只会返回一个我可以直接使用的int值。所以我还是有点困惑

欢迎评论!如果有人有更好的想法

谢谢

安德鲁