| 900 | } |
| 901 | |
| 902 | bool db_sqlite::prepare(sqlite_cursor& cursor) |
| 903 | { |
| 904 | const string& sql = cursor.get_sql(); |
| 905 | int ret = __sqlite3_prepare_v2(db_, sql.c_str(), -1, |
| 906 | &cursor.stmt_, NULL); |
| 907 | if (ret != SQLITE_OK) { |
| 908 | logger_error("prepare error=%s, sql=%s", |
| 909 | get_error(), sql.c_str()); |
| 910 | return false; |
| 911 | } |
| 912 | |
| 913 | cursor.free_callback = __sqlite3_finalize; |
| 914 | |
| 915 | int n = __sqlite3_column_count(cursor.stmt_); |
| 916 | if (n <= 0) { |
| 917 | logger_error("invalid column count=%d", n); |
| 918 | return false; |
| 919 | } |
| 920 | for (int i = 0; i < n; i++) { |
| 921 | const char* name = __sqlite3_column_name(cursor.stmt_, i); |
| 922 | if (name == NULL) { |
| 923 | logger_error("column name null, i=%d, sql=%s", |
| 924 | i, cursor.get_sql().c_str()); |
| 925 | return false; |
| 926 | } |
| 927 | cursor.add_column_name(name); |
| 928 | } |
| 929 | cursor.create_row(); |
| 930 | return true; |
| 931 | } |
| 932 | |
| 933 | bool db_sqlite::next(sqlite_cursor& cursor, bool* done) |
| 934 | { |
nothing calls this directly
no test coverage detected