David A O L wrote:
Im using 3.3.13, I will like if you can show a little snipped of how
to go
with something like the next..
(The following at sqlite prompt)
create table some(xthing varchar, count integer);
insert into some values("hi", 0);
insert into some values("hi there", 0);
update some set count = count +1 where xthing="hi";
update some set count = count +1 where xthing="hi";
update some set count = count +1 where xthing="hi";
update some set count = count +1 where xthing="hi there";
The following in C
select * from some;
// and in the callback after print the value of count and extract a
random
value...
David,
I'm not sure what you are asking for, but if you are looking for sample
C code that shows how to use the SQLite API in C I would suggest you
look at the source of the sqlite shell program at
http://www.sqlite.org/cvstrac/fileview?f=sqlite/src/shell.c&v=1.160 or
try a google search like this
http://www.google.ca/search?hl=en&q=SQLite+tutorial&btnG=Google+Search.
The following sample shows the basic use of sqlite C API functions
neglecting the error handling for improved clarity.
#include "sqlite3.h"
#define dim(x) (sizeof(x)/sizeof(x[0]))
void sample()
{
sqlite3* db = NULL;
// open a database file
sqlite3_open("sample.db3", &db);
// create and populate a table
char* sqlx[] = {
"create table some(xthing varchar, count integer)",
"insert into some values('hi', 0)",
"insert into some values('hi there', 0)",
"update some set count = count +1 where xthing='hi'",
"update some set count = count +1 where xthing='hi'",
"update some set count = count +1 where xthing='hi'",
"update some set count = count +1 where xthing='hi there'"
};
// execute the non-query statements one at a time
for (int i = 0; i < dim(sqlx); ++i)
sqlite3_exec(db, sqlx[i], NULL, NULL, NULL);
// read back the table contents
char* sql = "select * from some";
// prepare the query
sqlite3_stmt* s = NULL;
sqlite3_prepare_v2(db, sql, -1, &s, NULL);
// execute the query in a loop to print the results
bool do_headings = true;
do {
int rc = sqlite3_step(s);
if (rc == SQLITE_ROW) {
// get the number of columns returned
int cols = sqlite3_column_count(s);
// print headings if needed
if (do_headings) {
// loop over the columns
for (int c = 0; c < cols; ++c) {
// print separator
if (c != 0)
putchar('|');
// print column heading
printf("%s", sqlite3_column_name(s, c));
}
putchar('\n');
do_headings = false;
}
// loop over the columns
for (int c = 0; c < cols; ++c) {
// print separator
if (c != 0)
putchar('|');
// get the column data type
int ct = sqlite3_column_type(s, c);
// reteive and print the column data
switch (ct) {
case SQLITE_INTEGER:
printf("%d", sqlite3_column_int(s, c));
break;
case SQLITE_FLOAT:
printf("%f", sqlite3_column_double(s, c));
break;
case SQLITE_BLOB:
// fall through to print blob as text
case SQLITE_TEXT:
printf("%s", sqlite3_column_text(s, c));
break;
case SQLITE_NULL:
printf("<null>");
break;
}
}
putchar('\n');
}
} while (rc != SQLITE_DONE);
// destroy the prepared statement
sqlite3_finalize(s);
// close the database
sqlite3_close(db);
}
HTH
Dennis Cote
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------