SQLiteCpp
SQLiteCpp copied to clipboard
How to get the records count ?
How to obtain the records count ?
std::string sql = "SELECT COUNT(*) FROM ";
sql += DB_KEY_TAB;
sql += " WHERE uuid = '";
sql += uuid;
sql += "';";
@pengweichu you can do it like this:
string count = db.execAndGet("SELECT COUNT(*) FROM test");
cout << "COUNT(*) = "<< count << '\n';
@tiendq When I add conditionals to the COUNT(*), it always returns zero..
` SQLite::Statement query(db, "SELECT COUNT(*) FROM room_cache WHERE room_path = :room_path");
// Bind the integer value 6 to the first parameter of the SQL query
query.bind(":room_path", room_path);
std::string count = db.execAndGet(query.getQuery());
std::cout << "COUNT(*) = "<< count << '\n';`
@CalielOfSeptem did you look at what query.getQuery()
return? :)
You need something like this:
while (query.executeStep())
cout << "COUNT(*) " << query.getColumn(0) << '\n';
@KennethThompson Have you slove this issue? I've met this, too. Both execAndGet
and executeStep
have I tried, but both of them return 0 (my table has 1 data). Hope for you reply:)
@KennethThompson Have you slove this issue? I've met this, too. Both
execAndGet
andexecuteStep
have I tried, but both of them return 0 (my table has 1 data). Hope for you reply:)
My fault, I just figure out I use the wrong db file:(