Support for LIMIT/OFFSET in SQLite3_result()

pull/2612/head
René Cannaò 6 years ago
parent 5552c7568f
commit cec0404cba

@ -44,10 +44,11 @@ class SQLite3_result {
SQLite3_result(SQLite3_result *);
unsigned long long get_size();
void add_column_definition(int a, const char *b);
int add_row(sqlite3_stmt *stmt);
int add_row(sqlite3_stmt *stmt, bool skip=false);
int add_row(char **_fields);
int add_row(SQLite3_row *old_row);
SQLite3_result(sqlite3_stmt *stmt);
SQLite3_result(sqlite3_stmt *stmt, int *found_rows, unsigned int offset, unsigned int limit);
SQLite3_result(int num_columns, bool en_mutex=false);
~SQLite3_result();
void dump_to_stderr();

@ -554,13 +554,15 @@ void SQLite3_result::add_column_definition(int a, const char *b) {
column_definition.push_back(cf);
}
int SQLite3_result::add_row(sqlite3_stmt *stmt) {
int SQLite3_result::add_row(sqlite3_stmt *stmt, bool skip) {
int rc=sqlite3_step(stmt);
if (rc!=SQLITE_ROW) return rc;
SQLite3_row *row=new SQLite3_row(columns);
row->add_fields(stmt);
rows.push_back(row);
rows_count++;
if (skip==false) {
SQLite3_row *row=new SQLite3_row(columns);
row->add_fields(stmt);
rows.push_back(row);
rows_count++;
}
return SQLITE_ROW;
}
@ -595,6 +597,31 @@ SQLite3_result::SQLite3_result(sqlite3_stmt *stmt) {
while (add_row(stmt)==SQLITE_ROW) {};
}
SQLite3_result::SQLite3_result(sqlite3_stmt *stmt, int * found_rows, unsigned int offset, unsigned int limit) {
rows_count=0;
int fr = 0;
columns=sqlite3_column_count(stmt);
for (int i=0; i<columns; i++) {
add_column_definition(sqlite3_column_type(stmt,i), sqlite3_column_name(stmt,i));
}
int rc = SQLITE_ROW;
while (offset > 0 && rc==SQLITE_ROW) {
rc = add_row(stmt, true);
if (rc == SQLITE_ROW) fr++;
offset--;
}
while (limit > 0 && rc==SQLITE_ROW) {
rc = add_row(stmt, false);
if (rc == SQLITE_ROW) fr++;
limit--;
}
while (rc == SQLITE_ROW) {
rc=add_row(stmt, true);
if (rc == SQLITE_ROW) fr++;
}
*found_rows = fr;
}
SQLite3_result::SQLite3_result(int num_columns, bool en_mutex) {
rows_count=0;
columns=num_columns;

Loading…
Cancel
Save