|
From: <dav...@us...> - 2006-04-19 06:21:47
|
Revision: 1310 Author: davidgewirtz Date: 2006-04-18 23:21:33 -0700 (Tue, 18 Apr 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1310&view=rev Log Message: ----------- First actual working SQLite code, integrated into Frontier. Code is still messy, needs tuning and debugging, but basic queries now work. -- DG Modified Paths: -------------- Frontier/branches/SQLite/Common/headers/kernelverbs.h Frontier/branches/SQLite/Common/headers/langsqlite.h Frontier/branches/SQLite/Common/resources/Mac/kernelverbs.r Frontier/branches/SQLite/Common/resources/Win32/kernelverbs.rc Frontier/branches/SQLite/Common/source/langsqlite.c Frontier/branches/SQLite/Common/source/shell.c Modified: Frontier/branches/SQLite/Common/headers/kernelverbs.h =================================================================== --- Frontier/branches/SQLite/Common/headers/kernelverbs.h 2006-04-19 00:24:16 UTC (rev 1309) +++ Frontier/branches/SQLite/Common/headers/kernelverbs.h 2006-04-19 06:21:33 UTC (rev 1310) @@ -56,3 +56,4 @@ extern boolean cryptinitverbs (void); /* langcrypt.c */ +extern boolean sqliteinitverbs (void); /* langsqlite.c */ \ No newline at end of file Modified: Frontier/branches/SQLite/Common/headers/langsqlite.h =================================================================== --- Frontier/branches/SQLite/Common/headers/langsqlite.h 2006-04-19 00:24:16 UTC (rev 1309) +++ Frontier/branches/SQLite/Common/headers/langsqlite.h 2006-04-19 06:21:33 UTC (rev 1310) @@ -33,6 +33,24 @@ extern boolean sqliteexecverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-03-18 gewirtz */ +extern boolean sqliteprepareverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + +extern boolean sqlitefinalizeverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + +extern boolean sqlitestepverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + +extern boolean sqlitecolumncountverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + +extern boolean sqlitecolumntypeverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + +extern boolean sqlitecolumnintverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + +extern boolean sqlitecolumndoubleverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + +extern boolean sqlitecolumntextverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + +extern boolean sqlitecolumnnameverb (hdltreenode, tyvaluerecord *, bigstring); /* 2006-04-18 gewirtz */ + extern boolean sqliteinitverbs (void); /* 2006-03-15 gewirtz */ /* boolean hmacmd5 (unsigned char *, int, unsigned char *, int, unsigned char *);*/ /* 2006-03-05 creedon */ Modified: Frontier/branches/SQLite/Common/resources/Mac/kernelverbs.r =================================================================== --- Frontier/branches/SQLite/Common/resources/Mac/kernelverbs.r 2006-04-19 00:24:16 UTC (rev 1309) +++ Frontier/branches/SQLite/Common/resources/Mac/kernelverbs.r 2006-04-19 06:21:33 UTC (rev 1310) @@ -1141,6 +1141,15 @@ "open", "exec", + "prepare", + "finalize", + "step", + "column_count", + "column_type", + "column_int", + "column_double", + "column_text", + "column_name", "close" } } Modified: Frontier/branches/SQLite/Common/resources/Win32/kernelverbs.rc =================================================================== --- Frontier/branches/SQLite/Common/resources/Win32/kernelverbs.rc 2006-04-19 00:24:16 UTC (rev 1309) +++ Frontier/branches/SQLite/Common/resources/Win32/kernelverbs.rc 2006-04-19 06:21:33 UTC (rev 1310) @@ -1078,9 +1078,18 @@ 1, // Number of "blocks" in this resource "sqlite\0", // Function Processor name false, // Window required - 3, // Count of verbs + 12, // Count of verbs "open\0", "exec\0", + "prepare\0", + "finalize\0", + "step\0", + "column_count\0", + "column_type\0", + "column_int\0", + "column_double\0", + "column_text\0", + "column_name\0", "close\0" END Modified: Frontier/branches/SQLite/Common/source/langsqlite.c =================================================================== --- Frontier/branches/SQLite/Common/source/langsqlite.c 2006-04-19 00:24:16 UTC (rev 1309) +++ Frontier/branches/SQLite/Common/source/langsqlite.c 2006-04-19 06:21:33 UTC (rev 1310) @@ -49,7 +49,25 @@ openfunc, execfunc, + + preparefunc, + + finalizefunc, + + stepfunc, + + columncountfunc, + + columntypefunc, + + columnintfunc, + + columndoublefunc, + + columntextfunc, + columnnamefunc, + closefunc, ctsqliteverbs @@ -79,11 +97,55 @@ return (sqliteexecverb (hp1, v, bserror)); } /* execfunc */ + case preparefunc: { /* 2006-04-18 gewirtz: prepare an SQLite statement */ + + return (sqliteprepareverb (hp1, v, bserror)); + } /* preparefunc */ + + case finalizefunc: { /* 2006-04-18 gewirtz: finalize an SQLite statement */ + + return (sqlitefinalizeverb (hp1, v, bserror)); + } /* finalizefunc */ + + case stepfunc: { /* 2006-04-18 gewirtz: finalize an SQLite statement */ + + return (sqlitestepverb (hp1, v, bserror)); + } /* stepfunc */ + + case columncountfunc: { /* 2006-04-18 gewirtz: finalize an SQLite statement */ + + return (sqlitecolumncountverb (hp1, v, bserror)); + } /* columncountfunc */ + + case columntypefunc: { /* 2006-04-18 gewirtz: finalize an SQLite statement */ + + return (sqlitecolumntypeverb (hp1, v, bserror)); + } /* columntypefunc */ + + case columnintfunc: { /* 2006-04-18 gewirtz: finalize an SQLite statement */ + + return (sqlitecolumnintverb (hp1, v, bserror)); + } /* columnintfunc */ + + case columndoublefunc: { /* 2006-04-18 gewirtz: finalize an SQLite statement */ + + return (sqlitecolumndoubleverb (hp1, v, bserror)); + } /* columndoublefunc */ + + case columntextfunc: { /* 2006-04-18 gewirtz: finalize an SQLite statement */ + + return (sqlitecolumntextverb (hp1, v, bserror)); + } /* columntextfunc */ + + case columnnamefunc: { /* 2006-04-18 gewirtz: finalize an SQLite statement */ + + return (sqlitecolumnnameverb (hp1, v, bserror)); + } /* columnnamefunc */ + case closefunc: { /* 2006-03-15 gewirtz: close an SQLite db */ return (sqlitecloseverb (hp1, v, bserror)); } /* closefunc */ - default: getstringlist (langerrorlist, unimplementedverberror, bserror); @@ -139,11 +201,6 @@ flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ - /* This routine takes one parameter: the filename. - It returns a handle and a result code. See: - http://www.sqlite.org/capi3ref.html#sqlite3_open - */ - /* Enter the verb, convert the param to null-terminated string */ if (!getexempttextvalue (hparam1, 1, &h)) return (false); @@ -161,15 +218,7 @@ } return (setheapvalue ((Handle) db, longvaluetype, vreturned)); /* return the db address to the scripter */ - - /* for now, close the database, simply because we don't have any other code */ - /* sqlite3_close(db); */ - /* Exit the verb, converting string back to Frontier handle */ - /* newfilledhandle (*h, strlen (*h), &returnH); */ - /* disposehandle (h); */ /* get rid of the provided, original handle */ - /* return (setheapvalue (returnH, stringvaluetype, vreturned)); */ - } /* sqliteopenverb */ boolean sqlitecloseverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { @@ -180,11 +229,6 @@ flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ - /* This routine takes one parameter: the database. - It true if the file closed successfully, or throws a script error if not. See: - http://www.sqlite.org/capi3ref.html#sqlite3_close - */ - if (!getlongvalue (hparam1, 1, &db)) /* Get the long value, which becomes the db pointer */ return (false); @@ -207,18 +251,6 @@ sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ int returnCode; /* return code from SQLite call */ - /* - This routine takes one parameter: the filename. - It returns a handle and a result code. See: - http://www.sqlite.org/capi3ref.html#sqlite3_exec - - We're not going to use the SQLite callback mechanism for the sqlite3_exec - function. The most obvious approach inside Frontier would be to pass a script - into SQLite, but the potential problems, bugs, and difficulty in debugging makes - this an unnecessary exercise. The sqlite3_exec function will return data, which - can then be munged by a script once it leaves SQLite. So sayeth the coder. -- DG - */ - if (!getlongvalue (hparam1, 1, &db)) /* Get the long value, which becomes the db pointer */ return (false); @@ -241,17 +273,261 @@ } return (setheapvalue ((Handle) db, longvaluetype, vreturned)); /* return the db address to the scripter */ - - /* for now, close the database, simply because we don't have any other code */ - /* sqlite3_close(db); */ - /* Exit the verb, converting string back to Frontier handle */ - /* newfilledhandle (*h, strlen (*h), &returnH); */ - /* disposehandle (h); */ /* get rid of the provided, original handle */ - /* return (setheapvalue (returnH, stringvaluetype, vreturned)); */ - } /* sqliteexecverb */ +boolean sqliteprepareverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char **pzTail; /* remainder of the statement, not used, ignored for now */ + sqlite3_stmt *plineInfo = 0; /* the compiled query */ + int returnCode; /* return code from SQLite call */ + + /* + Code that is a good example of prepare in use: + + http://souptonuts.sourceforge.net/code/eatblob.c.html + */ + + if (!getlongvalue (hparam1, 1, &db)) /* Get the long value, which becomes the db pointer */ + return (false); + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + /* Enter the verb, convert the param to null-terminated string */ + if (!getexempttextvalue (hparam1, 2, &h)) + return (false); + + pushcharhandle (0x00, h); /* this should convert *h to a string */ + + /* Process the SQLite sequence */ + + returnCode = sqlite3_prepare(db, *h, -1, &plineInfo, 0); + if(returnCode != SQLITE_OK || plineInfo == NULL) { + sqliteDatabaseError(sqlite3_errmsg(db), bserror); /* send database error */ + disposehandle(h); /* get rid of the provided, original handle */ + sqlite3_close(db); + return (false); + } + + return (setheapvalue ((Handle) plineInfo, longvaluetype, vreturned)); /* return the db address to the scripter */ + +} /* sqliteprepareverb */ + +boolean sqlitefinalizeverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + char *zErrMsg = 0; /* SQLite's error message */ + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char **pzTail; /* remainder of the statement, not used, ignored for now */ + sqlite3_stmt *plineInfo = 0; + int returnCode; /* return code from SQLite call */ + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + if (!getlongvalue (hparam1, 1, &plineInfo)) /* Get the long value, which becomes the pline pointer */ + return (false); + + /* Process the SQLite sequence */ + + returnCode = sqlite3_finalize(plineInfo); + if(returnCode != SQLITE_OK) { + sqliteDatabaseError(zErrMsg, bserror); /* send database open error */ + sqlite3_close(db); + return (false); + } + + return setbooleanvalue (true, vreturned); + +} /* sqlitefinalizeverb */ + +boolean sqlitestepverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + char *zErrMsg = 0; /* SQLite's error message */ + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char **pzTail; /* remainder of the statement, not used, ignored for now */ + sqlite3_stmt *plineInfo = 0; + int returnCode; /* return code from SQLite call */ + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + if (!getlongvalue (hparam1, 1, &plineInfo)) /* Get the long value, which becomes the pline pointer */ + return (false); + + /* Process the SQLite sequence */ + + returnCode = sqlite3_step(plineInfo); + if(returnCode == SQLITE_ERROR || returnCode == SQLITE_MISUSE) { + sqliteDatabaseError(zErrMsg, bserror); /* send database open error */ + sqlite3_close(db); + return (false); + } + + return setintvalue ((short) returnCode, vreturned); + +} /* sqlitestepverb */ + +boolean sqlitecolumntypeverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + char *zErrMsg = 0; /* SQLite's error message */ + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char **pzTail; /* remainder of the statement, not used, ignored for now */ + sqlite3_stmt *plineInfo = 0; + int returnCode; /* return code from SQLite call */ + + if (!getlongvalue (hparam1, 1, &plineInfo)) /* Get the long value, which becomes the pline pointer */ + return (false); + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + /* Enter the verb, convert the param to null-terminated string */ + if (!getlongvalue (hparam1, 2, &h)) + return (false); + + /* Process the SQLite sequence */ + + returnCode = sqlite3_column_type(plineInfo, h); + + return setintvalue ((short) returnCode, vreturned); + +} /* sqlitecolumntypeverb */ + +boolean sqlitecolumnnameverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + char *zErrMsg = 0; /* SQLite's error message */ + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char *column_name; + sqlite3_stmt *plineInfo = 0; + int returnCode; /* return code from SQLite call */ + + if (!getlongvalue (hparam1, 1, &plineInfo)) /* Get the long value, which becomes the pline pointer */ + return (false); + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + /* Enter the verb, convert the param to null-terminated string */ + if (!getlongvalue (hparam1, 2, &h)) + return (false); + + /* Process the SQLite sequence */ + + column_name = sqlite3_column_name(plineInfo, h); + + /* Exit the verb, converting column_name back to Frontier handle */ + + newfilledhandle (column_name, strlen (column_name), &returnH); + return (setheapvalue (returnH, stringvaluetype, vreturned)); + +} /* sqlitecolumnnameverb */ + +boolean sqlitecolumncountverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + char *zErrMsg = 0; /* SQLite's error message */ + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char **pzTail; /* remainder of the statement, not used, ignored for now */ + sqlite3_stmt *plineInfo = 0; + int returnCode; /* return code from SQLite call */ + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + if (!getlongvalue (hparam1, 1, &plineInfo)) /* Get the long value, which becomes the pline pointer */ + return (false); + + /* Process the SQLite sequence */ + + returnCode = sqlite3_column_count(plineInfo); + + return setintvalue ((short) returnCode, vreturned); + +} /* sqlitecolumncountverb */ + +boolean sqlitecolumnintverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + char *zErrMsg = 0; /* SQLite's error message */ + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char **pzTail; /* remainder of the statement, not used, ignored for now */ + sqlite3_stmt *plineInfo = 0; + long returnCode; /* return code from SQLite call */ + + if (!getlongvalue (hparam1, 1, &plineInfo)) /* Get the long value, which becomes the pline pointer */ + return (false); + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + /* Enter the verb, convert the param to null-terminated string */ + if (!getlongvalue (hparam1, 2, &h)) + return (false); + + /* Process the SQLite sequence */ + + returnCode = sqlite3_column_int(plineInfo, h); + + return (setlongvalue ((long) returnCode, vreturned)); + +} /* sqlitecolumnintverb */ + +boolean sqlitecolumndoubleverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + char *zErrMsg = 0; /* SQLite's error message */ + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char **pzTail; /* remainder of the statement, not used, ignored for now */ + sqlite3_stmt *plineInfo = 0; + double returnCode; /* return code from SQLite call */ + + if (!getlongvalue (hparam1, 1, &plineInfo)) /* Get the long value, which becomes the pline pointer */ + return (false); + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + /* Enter the verb, convert the param to null-terminated string */ + if (!getlongvalue (hparam1, 2, &h)) + return (false); + + /* Process the SQLite sequence */ + + returnCode = sqlite3_column_double(plineInfo, h); + + return (setlongvalue ((double) returnCode, vreturned)); + +} /* sqlitecolumndoubleverb */ + +boolean sqlitecolumntextverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { + Handle h = nil; + Handle returnH = nil; + char *zErrMsg = 0; /* SQLite's error message */ + sqlite3 *db; /* the SQLite DB handle, be careful to not pass this across threads */ + const char **pzTail; /* remainder of the statement, not used, ignored for now */ + sqlite3_stmt *plineInfo = 0; + int returnCode; /* return code from SQLite call */ + const unsigned char *column_text; + + if (!getlongvalue (hparam1, 1, &plineInfo)) /* Get the long value, which becomes the pline pointer */ + return (false); + + flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */ + + /* Enter the verb, convert the param to null-terminated string */ + if (!getlongvalue (hparam1, 2, &h)) + return (false); + + /* Process the SQLite sequence */ + + column_text = sqlite3_column_text(plineInfo, h); + + /* Exit the verb, converting column_name back to Frontier handle */ + + newfilledhandle (column_text, strlen (column_text), &returnH); + return (setheapvalue (returnH, stringvaluetype, vreturned)); + +} /* sqlitecolumntextverb */ + /* boolean hmacmd5 (unsigned char * text, int text_len, unsigned char * key, int key_len, unsigned char * digest) function code went here Modified: Frontier/branches/SQLite/Common/source/shell.c =================================================================== --- Frontier/branches/SQLite/Common/source/shell.c 2006-04-19 00:24:16 UTC (rev 1309) +++ Frontier/branches/SQLite/Common/source/shell.c 2006-04-19 06:21:33 UTC (rev 1310) @@ -1335,6 +1335,8 @@ cryptinitverbs (); /* 2006-03-07 creedon: langcrypt.c */ + sqliteinitverbs (); /* 2006-03-15 gewirtz: langsqlite.c */ + if (keyboardescape ()) /*check again before landinit; after this, must do shellquit*/ exittooperatingsystem (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |