Re: [sqlite] Need a sqlite c api that wrires data into a table.

2012-01-13 Thread Steve and Amy
If I understand your question, the answer is NO.  There is NO function 
like sqlite3_insert_data_into_table(TableName, Data, FieldName).  The 
SQL engine responsible for reading and writing data from and to tables 
only responds to SQL queries passed to it via functions like sqlite3_exec().


For multiple INSERTions you can prepare a parameterized SQL query using 
sqlite3_prepare().  The query would look something like "INSERT INTO 
my_table (FirstField, SecondField) VALUES (:FirstField, :SecondField)".  
After preparing the query, the parameters (FirstField, SecondField) can 
be accessed individually via a simple function:  sqlite3_bind_...()


Steve.

On 1/13/2012 1:29 AM, bhaskarReddy wrote:

Hi friends,


   I check all the C APIs which are provided by sqlite.  I can able
to write data to a table, using sqlite3_exec() function.

But i need a C API that will write data into table, i.e., sqlite3_exec().

Ex: if i give "database name", table name and values to that
function, the particular function will enter the record of values into that
table.

Is there any C API like that in SQlite.


Regards,
Bhaskar


___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Example Showing ACTUAL Use of sqlite3_auto_extension()

2011-06-07 Thread Steve and Amy
Would someone, please, show me an example (several actual, successive 
lines of code) in C (or C++) showing a proper use of

sqlite3_auto_extension()?  I have searched the web looking for examples, but 
there are none that I can tell.  I have also, to the best of my understanding, 
readhttp://www.sqlite.org/c3ref/auto_extension.html  numerous times and I have 
had no success.  I am trying to use SQLite with extensionfunctions.c, but 
extensionfunctions.c lacks a function called "xEntryPoint()".  I do not know if 
I am actually supposed to pass a pointer to a function called "xEntryPoint()" 
or not.  I am leaning toward 'no' and in reality I would think "xEntryPoint()" 
is merely to represent some function found in extensionfunctions.c.

Below is code I have tried:
if (sqlite3Database)
sqlite3_close(sqlite3Database);
iCommandResult = sqlite3_open(":memory:",);
bContinue = (iCommandResult == 0);
if (bContinue)
{
iCommandResult = sqlite3_exec(sqlite3Database,
"CREATE TABLE data_table 
(DataID INT, RandomData INT, V_In INT);",
,
0,
);
... Some Code to Fill the sqlite3Database in memory with data
bContinue = (iCommandResult == 0);
}
if (bContinue)
{
iCommandResult = sqlite3_exec(sqlite3Database,
"SELECT DataID, RandomData, 
V_In FROM data_table",
,
this,
);
}

if (sqlite3Database)
{
iCommandResult = sqlite3_auto_extension(0);
if (iCommandResult == 0)
iCommandResult = sqlite3_exec(sqlite3Database,
"SELECT 
STDEV(RandomData) AS RandomData_STDEV, V_In FROM data_table GROUP BY V_In",
,
this,
);
}

Since I cannot find a function called "xEntryPoint()", I tried zero as an 
argument to sqlite3_auto_extension().  Not surprisingly, that did not work.


Here is some more code I tried ('adapted' from the commented out help section 
at the top of extensionfunctions.c):
if (sqlite3Database)
sqlite3_close(sqlite3Database);
iCommandResult = sqlite3_open(":memory:",);
iCommandResult = sqlite3_enable_load_extension(sqlite3Database, 1);
bContinue = (iCommandResult == 0);
if (bContinue)
{
iCommandResult = sqlite3_exec(sqlite3Database,
"CREATE TABLE data_table 
(DataID INT, RandomData INT, V_In INT);",
,
0,
);
... Some Code to Fill the sqlite3Database in memory with data
bContinue = (iCommandResult == 0);
}
if (bContinue)
{
iCommandResult = sqlite3_exec(sqlite3Database,
"SELECT DataID, RandomData, 
V_In FROM data_table",
,
this,
);
}


if (sqlite3Database)
{
iCommandResult = sqlite3_load_extension(sqlite3Database, 0, 0, 
ppcLoadExtErrorMessage);
if (iCommandResult == 0)
iCommandResult = sqlite3_exec(sqlite3Database,
"SELECT 
STDEV(RandomData) AS RandomData_STDEV, V_In FROM data_table GROUP BY V_In",
,
this,
);
}
After executing sqlite3_load_extension, iCommandResult was set to SQLITE_ERROR 
(exactly what I expected), but ppcLoadExtErrorMessage was NULL, so I could not 
tell what the error was about.

Usage instructions from top of extensionfunctions.c:
Usage instructions for applications calling the sqlite3 API functions:
In your application, call sqlite3_enable_load_extension(db,1) to
allow loading external libraries.  Then load the library 
libsqlitefunctions
using sqlite3_load_extension; the third argument should be 0.
See http://www.sqlite.org/cvstrac/wiki?p=LoadableExtensions.
Select statements may now use these functions, as in