|
From: <dav...@us...> - 2007-05-01 16:04:09
|
Revision: 1657
http://svn.sourceforge.net/frontierkernel/?rev=1657&view=rev
Author: davidgewirtz
Date: 2007-05-01 09:04:10 -0700 (Tue, 01 May 2007)
Log Message:
-----------
Tested and documented MySQL integrated source. No Mac testing in this build.
Modified Paths:
--------------
Frontier/branches/mysql/Common/source/langmysql.c
Modified: Frontier/branches/mysql/Common/source/langmysql.c
===================================================================
--- Frontier/branches/mysql/Common/source/langmysql.c 2007-04-15 23:37:08 UTC (rev 1656)
+++ Frontier/branches/mysql/Common/source/langmysql.c 2007-05-01 16:04:10 UTC (rev 1657)
@@ -1,1258 +1,1350 @@
-
-/* $Id: langmysql.c,v 2007/04/08 18:32:00 davidgewirtz Exp $ */
-
-/******************************************************************************
-
- UserLand Frontier(tm) -- High performance Web content management,
- object database, system-level and Internet scripting environment,
- including source code editing and debugging.
-
- Copyright (C) 1992-2004 UserLand Software, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-******************************************************************************/
-
-#include "frontier.h"
-#include "standard.h"
-
-#include "frontierconfig.h"
-
-#include "error.h"
-#include "ops.h"
-#include "langinternal.h"
-#include "kernelverbs.h"
-#include "kernelverbdefs.h"
-#include "resources.h"
-#include "strings.h"
-#include "tablestructure.h"
-#include "lang.h"
-#include "oplist.h"
-#include "langsystem7.h"
-#include "langexternal.h"
-
-#include "langmysql.h"
-#include <mysql.h>
-
-#ifdef MACVERSION
-
- #include <sys/param.h>
-
-#endif // MACVERSION
-
-#include "file.h"
-
-#ifdef WIN95VERSION
-
- #define MAXPATHLEN 1024
-
-#endif // WIN95VERSION
-
-
-/* Building MySQL into Frontier
-
-See the Frontier Lab Notebook article:
-
-http://manila.zatz.com/frontierkernel/stories/storyReader$33
-
--- DG
-
-*/
-
-typedef enum tymysqlverbtoken { /* verbs that are processed by langmysql.c */
-
- initfunc,
- endfunc,
- connectfunc,
- compilequeryfunc,
- clearqueryfunc,
- getrowfunc,
- geterrornumberfunc,
- geterrormessagefunc,
- getclientinfofunc,
- getclientversionfunc,
- gethostinfofunc,
- getserverversionfunc,
- getprotocolinfofunc,
- getserverinfofunc,
- getqueryinfofunc,
- getaffectedrowcountfunc,
- getselectedrowcountfunc,
- getcolumncountfunc,
- getserverstatusfunc,
- getquerywarningcountfunc,
- pingserverfunc,
- seekrowfunc,
- selectdatabasefunc,
- getsqlstatefunc,
- escapestringfunc,
- isthreadsafefunc,
- closefunc,
- ctmysqlverbs
- } tymysqlverbtoken;
-
-
-static boolean mysqlfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
-
- hdltreenode hp1 = hparam1;
- tyvaluerecord *v = vreturned;
-
- setbooleanvalue (false, v); /* by default, sqlite functions return false */
-
- switch (token) {
-
- case initfunc: { /* 2007-04-08 gewirtz: initialize MySQL */
- return (mysqlinitverb (hp1, v, bserror));
- } /* initfunc */
- case endfunc: { /* 2007-04-08 gewirtz: initialize MySQL */
- return (mysqlendverb (hp1, v, bserror));
- } /* endfunc */
- case connectfunc: { /* 2007-04-08 gewirtz: initialize MySQL */
- return (mysqlconnectverb (hp1, v, bserror));
- } /* connectfunc */
- case compilequeryfunc: { /* 2007-04-09 gewirtz: prepare a MySQL query */
- return (mysqlcompilequeryverb (hp1, v, bserror));
- } /* compilequeryfunc */
- case clearqueryfunc: { /* 2007-04-09 gewirtz: clear a MySQL query from memory */
- return (mysqlclearqueryverb (hp1, v, bserror));
- } /* clearqueryfunc */
- case getrowfunc: { /* 2007-04-09 gewirtz: get a full row from a query */
- return (mysqlgetrowverb (hp1, v, bserror));
- } /* getrowfunc */
- case geterrornumberfunc: { /* 2007-04-10 gewirtz: get the error number from the most recent call */
- return (mysqlgeterrornumberverb (hp1, v, bserror));
- } /* geterrornumberfunc */
- case geterrormessagefunc: { /* 2007-04-10 gewirtz: get the error message from the most recent call */
- return (mysqlgeterrormessageverb (hp1, v, bserror));
- } /* geterrormessagefunc */
- case getclientinfofunc: { /* 2007-04-10 gewirtz: get the MySQL client info */
- return (mysqlgetclientinfoverb (hp1, v, bserror));
- } /* getclientinfofunc */
- case getclientversionfunc: { /* 2007-04-10 gewirtz: get the MySQL client version */
- return (mysqlgetclientversionverb (hp1, v, bserror));
- } /* getclientversionfunc */
- case gethostinfofunc: { /* 2007-04-10 gewirtz: get the MySQL host info */
- return (mysqlgethostinfoverb (hp1, v, bserror));
- } /* gethostinfofunc */
- case getserverversionfunc: { /* 2007-04-10 gewirtz: get the MySQL server version */
- return (mysqlgetserverversionverb (hp1, v, bserror));
- } /* getserverversionfunc */
- case getprotocolinfofunc: { /* 2007-04-10 gewirtz: get the MySQL protocol info */
- return (mysqlgetprotocolinfoverb (hp1, v, bserror));
- } /* getprotocolinfofunc */
- case getserverinfofunc: { /* 2007-04-10 gewirtz: get the MySQL server info */
- return (mysqlgetserverinfoverb (hp1, v, bserror));
- } /* getserverinfofunc */
- case getqueryinfofunc: { /* 2007-04-10 gewirtz: get the results messages from the last query */
- return (mysqlgetqueryinfoverb (hp1, v, bserror));
- } /* getqueryinfofunc */
- case getaffectedrowcountfunc: { /* 2007-04-11 gewirtz: get the rows added, deleted, updated */
- return (mysqlgetaffectedrowcountverb (hp1, v, bserror));
- } /* getaffectedrowcountfunc */
- case getselectedrowcountfunc: { /* 2007-04-11 gewirtz: get the rows selected in last query */
- return (mysqlgetselectedrowcountverb (hp1, v, bserror));
- } /* getselectedrowcountfunc */
- case getcolumncountfunc: { /* 2007-04-11 gewirtz: get the columns returned in last query */
- return (mysqlgetcolumncountverb (hp1, v, bserror));
- } /* getcolumncountfunc */
- case getserverstatusfunc: { /* 2007-04-11 gewirtz: get the MySQL server status */
- return (mysqlgetserverstatusverb (hp1, v, bserror));
- } /* getserverstatusfunc */
- case getquerywarningcountfunc: { /* 2007-04-11 gewirtz: get the number of warnings returned by the last query */
- return (mysqlgetquerywarningcountverb (hp1, v, bserror));
- } /* getquerywarningcountfunc */
- case pingserverfunc: { /* 2007-04-11 gewirtz: check to see if there's still a connection with the server */
- return (mysqlpingserververb (hp1, v, bserror));
- } /* pingserverfunc */
- case seekrowfunc: { /* 2007-04-11 gewirtz: move to specific row in query result set */
- return (mysqlseekrowverb (hp1, v, bserror));
- } /* seekrowfunc */
- case selectdatabasefunc: { /* 2007-04-11 gewirtz: choose a MySQL database as current */
- return (mysqlselectdatabaseverb (hp1, v, bserror));
- } /* selectdatabasefunc */
- case getsqlstatefunc: { /* 2007-04-11 gewirtz: choose a MySQL database as current */
- return (mysqlgetsqlstateverb (hp1, v, bserror));
- } /* getsqlstatefunc */
- case escapestringfunc: { /* 2007-04-11 gewirtz: choose a MySQL database as current */
- return (mysqlescapestringverb (hp1, v, bserror));
- } /* escapestringfunc */
- case isthreadsafefunc: { /* 2007-04-11 gewirtz: choose a MySQL database as current */
- return (mysqlisthreadsafeverb (hp1, v, bserror));
- } /* isthreadsafefunc */
- case closefunc: { /* 2007-04-08 gewirtz: close a MySQL db */
- return (mysqlcloseverb (hp1, v, bserror));
- } /* closefunc */
- default:
- getstringlist (langerrorlist, unimplementedverberror, bserror);
- return (false);
- } /* switch */
- } /* mysqlfunctionvalue */
-
-
-boolean mysqlinitverbs (void) {
-
- return (loadfunctionprocessor (idmysqlverbs, &mysqlfunctionvalue));
- } /* mysqlinitverbs */
-
-boolean mysqlinitverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
- int resultCode;
+
+/* $Id: langmysql.c,v 2007/04/08 18:32:00 davidgewirtz Exp $ */
+
+/******************************************************************************
+
+ UserLand Frontier(tm) -- High performance Web content management,
+ object database, system-level and Internet scripting environment,
+ including source code editing and debugging.
+
+ Copyright (C) 1992-2004 UserLand Software, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+******************************************************************************/
+
+#include "frontier.h"
+#include "standard.h"
+
+#include "frontierconfig.h"
+
+#include "error.h"
+#include "ops.h"
+#include "langinternal.h"
+#include "kernelverbs.h"
+#include "kernelverbdefs.h"
+#include "resources.h"
+#include "strings.h"
+#include "tablestructure.h"
+#include "lang.h"
+#include "oplist.h"
+#include "langsystem7.h"
+#include "langexternal.h"
+
+#include "langmysql.h"
+#include <mysql.h>
+
+#ifdef MACVERSION
+
+ #include <sys/param.h>
+
+#endif // MACVERSION
+
+#include "file.h"
+
+#ifdef WIN95VERSION
+
+ #define MAXPATHLEN 1024
+
+#endif // WIN95VERSION
+
+
+/* Building MySQL into Frontier
+
+See the Frontier Lab Notebook article:
+
+http://manila.zatz.com/frontierkernel/stories/storyReader$33
+
+-- DG
+
+*/
+
+typedef enum tymysqlverbtoken { /* verbs that are processed by langmysql.c */
+
+ initfunc,
+ endfunc,
+ connectfunc,
+ compilequeryfunc,
+ clearqueryfunc,
+ getrowfunc,
+ geterrornumberfunc,
+ geterrormessagefunc,
+ getclientinfofunc,
+ getclientversionfunc,
+ gethostinfofunc,
+ getserverversionfunc,
+ getprotocolinfofunc,
+ getserverinfofunc,
+ getqueryinfofunc,
+ getaffectedrowcountfunc,
+ getselectedrowcountfunc,
+ getcolumncountfunc,
+ getserverstatusfunc,
+ getquerywarningcountfunc,
+ pingserverfunc,
+ seekrowfunc,
+ selectdatabasefunc,
+ getsqlstatefunc,
+ escapestringfunc,
+ isthreadsafefunc,
+ closefunc,
+ ctmysqlverbs
+ } tymysqlverbtoken;
+
+
+static boolean mysqlfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
+
+ hdltreenode hp1 = hparam1;
+ tyvaluerecord *v = vreturned;
+
+ setbooleanvalue (false, v); /* by default, sqlite functions return false */
+
+ switch (token) {
+
+ case initfunc: { /* 2007-04-08 gewirtz: initialize MySQL */
+ return (mysqlinitverb (hp1, v, bserror));
+ } /* initfunc */
+ case endfunc: { /* 2007-04-08 gewirtz: initialize MySQL */
+ return (mysqlendverb (hp1, v, bserror));
+ } /* endfunc */
+ case connectfunc: { /* 2007-04-08 gewirtz: initialize MySQL */
+ return (mysqlconnectverb (hp1, v, bserror));
+ } /* connectfunc */
+ case compilequeryfunc: { /* 2007-04-09 gewirtz: prepare a MySQL query */
+ return (mysqlcompilequeryverb (hp1, v, bserror));
+ } /* compilequeryfunc */
+ case clearqueryfunc: { /* 2007-04-09 gewirtz: clear a MySQL query from memory */
+ return (mysqlclearqueryverb (hp1, v, bserror));
+ } /* clearqueryfunc */
+ case getrowfunc: { /* 2007-04-09 gewirtz: get a full row from a query */
+ return (mysqlgetrowverb (hp1, v, bserror));
+ } /* getrowfunc */
+ case geterrornumberfunc: { /* 2007-04-10 gewirtz: get the error number from the most recent call */
+ return (mysqlgeterrornumberverb (hp1, v, bserror));
+ } /* geterrornumberfunc */
+ case geterrormessagefunc: { /* 2007-04-10 gewirtz: get the error message from the most recent call */
+ return (mysqlgeterrormessageverb (hp1, v, bserror));
+ } /* geterrormessagefunc */
+ case getclientinfofunc: { /* 2007-04-10 gewirtz: get the MySQL client info */
+ return (mysqlgetclientinfoverb (hp1, v, bserror));
+ } /* getclientinfofunc */
+ case getclientversionfunc: { /* 2007-04-10 gewirtz: get the MySQL client version */
+ return (mysqlgetclientversionverb (hp1, v, bserror));
+ } /* getclientversionfunc */
+ case gethostinfofunc: { /* 2007-04-10 gewirtz: get the MySQL host info */
+ return (mysqlgethostinfoverb (hp1, v, bserror));
+ } /* gethostinfofunc */
+ case getserverversionfunc: { /* 2007-04-10 gewirtz: get the MySQL server version */
+ return (mysqlgetserverversionverb (hp1, v, bserror));
+ } /* getserverversionfunc */
+ case getprotocolinfofunc: { /* 2007-04-10 gewirtz: get the MySQL protocol info */
+ return (mysqlgetprotocolinfoverb (hp1, v, bserror));
+ } /* getprotocolinfofunc */
+ case getserverinfofunc: { /* 2007-04-10 gewirtz: get the MySQL server info */
+ return (mysqlgetserverinfoverb (hp1, v, bserror));
+ } /* getserverinfofunc */
+ case getqueryinfofunc: { /* 2007-04-10 gewirtz: get the results messages from the last query */
+ return (mysqlgetqueryinfoverb (hp1, v, bserror));
+ } /* getqueryinfofunc */
+ case getaffectedrowcountfunc: { /* 2007-04-11 gewirtz: get the rows added, deleted, updated */
+ return (mysqlgetaffectedrowcountverb (hp1, v, bserror));
+ } /* getaffectedrowcountfunc */
+ case getselectedrowcountfunc: { /* 2007-04-11 gewirtz: get the rows selected in last query */
+ return (mysqlgetselectedrowcountverb (hp1, v, bserror));
+ } /* getselectedrowcountfunc */
+ case getcolumncountfunc: { /* 2007-04-11 gewirtz: get the columns returned in last query */
+ return (mysqlgetcolumncountverb (hp1, v, bserror));
+ } /* getcolumncountfunc */
+ case getserverstatusfunc: { /* 2007-04-11 gewirtz: get the MySQL server status */
+ return (mysqlgetserverstatusverb (hp1, v, bserror));
+ } /* getserverstatusfunc */
+ case getquerywarningcountfunc: { /* 2007-04-11 gewirtz: get the number of warnings returned by the last query */
+ return (mysqlgetquerywarningcountverb (hp1, v, bserror));
+ } /* getquerywarningcountfunc */
+ case pingserverfunc: { /* 2007-04-11 gewirtz: check to see if there's still a connection with the server */
+ return (mysqlpingserververb (hp1, v, bserror));
+ } /* pingserverfunc */
+ case seekrowfunc: { /* 2007-04-11 gewirtz: move to specific row in query result set */
+ return (mysqlseekrowverb (hp1, v, bserror));
+ } /* seekrowfunc */
+ case selectdatabasefunc: { /* 2007-04-11 gewirtz: choose a MySQL database as current */
+ return (mysqlselectdatabaseverb (hp1, v, bserror));
+ } /* selectdatabasefunc */
+ case getsqlstatefunc: { /* 2007-04-11 gewirtz: choose a MySQL database as current */
+ return (mysqlgetsqlstateverb (hp1, v, bserror));
+ } /* getsqlstatefunc */
+ case escapestringfunc: { /* 2007-04-11 gewirtz: choose a MySQL database as current */
+ return (mysqlescapestringverb (hp1, v, bserror));
+ } /* escapestringfunc */
+ case isthreadsafefunc: { /* 2007-04-11 gewirtz: choose a MySQL database as current */
+ return (mysqlisthreadsafeverb (hp1, v, bserror));
+ } /* isthreadsafefunc */
+ case closefunc: { /* 2007-04-08 gewirtz: close a MySQL db */
+ return (mysqlcloseverb (hp1, v, bserror));
+ } /* closefunc */
+ default:
+ getstringlist (langerrorlist, unimplementedverberror, bserror);
+ return (false);
+ } /* switch */
+ } /* mysqlfunctionvalue */
+
+
+boolean mysqlinitverbs (void) {
+
+ return (loadfunctionprocessor (idmysqlverbs, &mysqlfunctionvalue));
+ } /* mysqlinitverbs */
+
+boolean mysqlinitverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
+ int resultCode;
static char *server_args[] = {
"this_program" // this string is not used
// "--datadir=.", // these arguments aren't, either, since we're not using
// "--key_buffer_size=32M" // the embedded server
- };
-
- //
- // mysql.init()
- //
- // Action: initializes the mySQL connection object
- // Params: none
- // Returns: a MySQL object handle or an error
- // Usage: call in a try statement, call before any other MySQL call
- //
- // MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-init.html
- //
-
- // Initialize the MySQL object
- resultCode = mysql_library_init(-1, server_args, NULL); // -1 means don't start embedded server
- if (resultCode != 0) {
- langerrormessage ("\x1B""MySQL could not initialize.");
- return (false);
- }
-
- return (setlongvalue ((long) resultCode, vreturned));
-
-} // mysqlinitverb
-
-boolean mysqlendverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
-
- //
- // mysql.init()
- //
- // Action: initializes the mySQL connection object
- // Params: none
- // Returns: a MySQL object handle or an error
- // Usage: call in a try statement, call before any other MySQL call
- //
- // MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-init.html
- //
-
- // Close out the library
- mysql_library_end();
-
- return(setbooleanvalue (true, vreturned));
-
-} // mysqlendverb
-
-boolean mysqlconnectverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
-
- MYSQL *dbid; // the MySQL object handle
- Handle host; // hostname of the MySQL server
- Handle user; // valid username on the MySQL server
- Handle passwd; // password for user on MySQL server
- Handle dbname; // existing database on MySQL server
- long port; // TCP/IP port for the connection
-
- //
- // mysql.connect (dbid, host, user, password, database, port)
- //
- // Action: connects to a MySQL server and database, initializing the mySQL connection object
- // Params: dbid (the MySQL object) the hostname, user id, password, existing database name, and port
- // Returns: a MySQL object handle or an error
- // Usage: call in a try statement
- //
- // MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-real-connect.html
- //
- // If problems are encountered connecting to a Windows-based MySQL server, see:
- // http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html#can-not-connect-to-server-on-windows
- //
-
- if (!gettextvalue (hparam1, 1, &host)) /* get the host param */
- return (false);
-
- if (!gettextvalue (hparam1, 2, &user)) /* get the user param */
- return (false);
-
- if (!gettextvalue (hparam1, 3, &passwd)) /* get the passwd param */
- return (false);
-
- if (!gettextvalue (hparam1, 4, &dbname)) /* get the dbname param */
- return (false);
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 5, &port)) /* get the port param */
- return (false);
-
- // Null terminate strings
- if (!pushcharhandle (0x00, host)) return (false);
- if (!pushcharhandle (0x00, user)) return (false);
- if (!pushcharhandle (0x00, passwd)) return (false);
- if (!pushcharhandle (0x00, dbname)) return (false);
-
- // Initialize the MySQL object
- dbid = mysql_init((MYSQL*) 0);
- if (dbid == NULL) {
- langerrormessage ("\x2D""MySQL could not allocate a connection object.");
- return (false);
- }
- // Attempt the connection
- dbid = mysql_real_connect(dbid, *host, *user, *passwd, *dbname, (unsigned int) port, NULL, 0 );
- if (dbid == NULL) {
- langerrormessage ("\x22""Could not connect to MySQL server.");
- return (false);
- }
-
- return (setlongvalue ((long) dbid, vreturned));
-
-} // mysqlconnectverb
-
-
-boolean mysqlcloseverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- int returnCode; // return code from close call
-
- //
- // mysql.close(dbid)
- //
- // Action: close a MySQL session
- // Params: dbid, the MySQL object
- // Returns: nothing
- // Usage: there doesn't appear to be a way to check for success or failure
- //
- // MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-close.html
- //
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- mysql_close(dbid);
- returnCode = 0; // placeholder for debugging. mysql_close doesn't return anything.
-
- return setlongvalue (returnCode, vreturned);
-
-} /* mysqlcloseverb */
-
-boolean mysqlcompilequeryverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- Handle query; // the SQL query passed to the MySQL server
- MYSQL *dbid; // the MySQL object handle
- MYSQL_RES *queryid; // the returned MySQL query id
- int returnCode; // return code from MySQL query
-
- /*
- sqlite.compileQuery(dbid, query)
-
- Action: compile an SQLite query
- Params: a database id and a query string
- Returns: a query id
- Usage: call in a try statement
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_prepare.
-
- Code that is a good example of prepare in use:
- http://souptonuts.sourceforge.net/code/eatblob.c.html
- */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* 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 */
-
- if (!gettextvalue (hparam1, 2, &query)) /* get the query param */
- return (false);
-
- // Null terminate strings
- if (!pushcharhandle (0x00, query))
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the initial query sequence */
- returnCode = mysql_query(dbid, *query);
- if(returnCode != 0) {
- langerrormessage ("\x21""Could not initialize MySQL query.");
- return (false);
- }
-
- queryid = mysql_store_result(dbid);
- if(mysql_errno(dbid) != 0) {
- langerrormessage ("\x21""Could initialize MySQL query.");
- return (false);
- }
-
- if (mysql_field_count(dbid) == 0)
- return (setlongvalue ((long) 0, vreturned)); /* return 0 to the scripter */
- else
- return (setlongvalue ((long) queryid, vreturned)); /* return the db address to the scripter */
-} /* mysqlcompilequeryverb */
-
-boolean mysqlclearqueryverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL_RES *queryid; // the returned MySQL query id
- int returnCode;
-
- /*
- sqlite.clearQuery(queryid)
-
- Action: clear an SQLite query
- Params: a query id
- Returns: an SQLite result code
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_finalize.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &queryid)) /* Get the long value, which becomes the queryid pointer */
- return (false);
-
- /* Process the MySQL sequence */
- mysql_free_result(queryid);
-
- returnCode = 0; // placeholder for debugging. mysql_free_result doesn't return anything.
- return setlongvalue (returnCode, vreturned);
-
-} /* mysqlclearqueryverb */
-
-boolean mysqlgetrowverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- unsigned int fieldNumber; /* field number */
- unsigned int fieldCount; /* number of fields */
- MYSQL_RES *queryid; /* query id */
- MYSQL_ROW row;
- MYSQL_FIELD *field;
-
- hdllistrecord hlist;
-
- Handle returnH;
- const unsigned char *column_text;
-
- tyvaluerecord val;
-
-
- /*
- http://dev.mysql.com/doc/refman/5.1/en/c-api-datatypes.html
-
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &queryid)) /* Get the long value, which becomes the queryid pointer */
- return (false);
-
- row = mysql_fetch_row(queryid);
- if (row == NULL) {
- // return 0, meaning no more rows
- // **** NOTE THIS COULD ALSO MEAN AN ERROR, MIGHT BE GOOD TO CHECK
- return (setlongvalue ((long) 0, vreturned));
- }
-
- fieldCount = mysql_num_fields(queryid);
-
- if (fieldCount == 0) {
- langerrormessage ("\x2D""MySQL.getRow requires a minimum of one field.");
- return (false);
- }
-
- mysql_field_seek(queryid, 0); // restart gathering field data from the first field
-
- if (!opnewlist (&hlist, false)) /* fail out if we can't create the list */
- return (false);
-
- for (fieldNumber=0; fieldNumber<fieldCount; ++fieldNumber) {
-
- field = mysql_fetch_field(queryid);
-
- switch(field->type) {
-
- /*
- The MySQL fetch_row function is interesting, in that it looks like
- each field returned is returned as a string. This is great for Frontier,
- since Frontier can't handle some of MySQL's bigger number types (like double),
- but it can handle strings. So everything that's supported is returned as
- a string to Frontier. The Frontier programmer can then do whatever
- coercing is necessary.
-
- The only formats we explicitly don't support are:
-
- MYSQL_TYPE_BIT
- MYSQL_TYPE_BLOB
- MYSQL_TYPE_SET
- MYSQL_TYPE_ENUM
- MYSQL_TYPE_GEOMETRY
- MYSQL_TYPE_NULL
-
- Formats supported and returned as string:
-
- MYSQL_TYPE_TINY
- MYSQL_TYPE_SHORT
- MYSQL_TYPE_LONG
- MYSQL_TYPE_INT24
- MYSQL_TYPE_LONGLONG
- MYSQL_TYPE_DECIMAL
- MYSQL_TYPE_NEWDECIMAL
- MYSQL_TYPE_FLOAT
- MYSQL_TYPE_DOUBLE
- MYSQL_TYPE_TIMESTAMP
- MYSQL_TYPE_DATE
- MYSQL_TYPE_TIME
- MYSQL_TYPE_DATETIME
- MYSQL_TYPE_YEAR
- MYSQL_TYPE_STRING
- MYSQL_TYPE_VAR_STRING
- */
-
- case MYSQL_TYPE_TINY:
- case MYSQL_TYPE_SHORT:
- case MYSQL_TYPE_LONG:
- case MYSQL_TYPE_INT24:
- case MYSQL_TYPE_LONGLONG:
- case MYSQL_TYPE_DECIMAL:
- case MYSQL_TYPE_NEWDECIMAL:
- case MYSQL_TYPE_FLOAT:
- case MYSQL_TYPE_DOUBLE:
- case MYSQL_TYPE_TIMESTAMP:
- case MYSQL_TYPE_DATE:
- case MYSQL_TYPE_TIME:
- case MYSQL_TYPE_DATETIME:
- case MYSQL_TYPE_YEAR:
- case MYSQL_TYPE_STRING:
- case MYSQL_TYPE_VAR_STRING:
- {
- column_text = row[fieldNumber];
-
- /* Exit the verb, converting column_name back to Frontier handle */
- if (!newfilledhandle ((ptrvoid) column_text, strlen (column_text), &returnH))
- return false; /* Allocation failed */
- if (!setheapvalue (returnH, stringvaluetype, &val)) /* convert handle to value */
- goto error;
- if (!langpushlistval (hlist, nil, &val))
- goto error;
- break;
- }
- default: {
- /* SQLite spec says sqlite3_column_type only returns the above 5 types. But,
- just in case it lied, this time we return a 0, so the rest of the fields
- can be read properly. */
- if (!langpushlistlong (hlist, (long) 0))
- goto error;
- }
- } /* switch */
- } /* for */
-
- return (setheapvalue ((Handle) hlist, listvaluetype, vreturned));
-
- error: {
- opdisposelist (hlist);
- return (false);
- }
-
-} /* mysqlgetrow */
-
-boolean mysqlgeterrornumberverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- unsigned int returnCode; // return code from MySQL call
-
- /*
- sqlite.getColumnInt(queryid, columnNumber)
-
- Action: Retrieve the value of the specified integer-type column
- Params: a query id and the number of the column (1 base)
- Returns: an SQLite result code
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_column_int.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the pline pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the MySQL call */
- returnCode = mysql_errno(dbid);
-
- return (setlongvalue ((long) returnCode, vreturned));
-
-} /* mysqlgeterrornumberverb */
-
-boolean mysqlgeterrormessageverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- const char *mysqlError; // pointer to the error message
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- mysqlError = mysql_error(dbid);
-
- /* Exit the verb, converting errMsg back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) mysqlError, strlen (mysqlError), &returnH))
- return false; /* Allocation failed */
-
- return (setheapvalue (returnH, stringvaluetype, vreturned));
-
-} /* mysqlgeterrormessageverb */
-
-boolean mysqlgetclientinfoverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- const char *mysqlMsg; // pointer to the message
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- /* Process the SQLite sequence */
- mysqlMsg = mysql_get_client_info();
-
- /* Exit the verb, converting errMsg back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) mysqlMsg, strlen (mysqlMsg), &returnH))
- return false; /* Allocation failed */
-
- return (setheapvalue (returnH, stringvaluetype, vreturned));
-
-} /* mysqlgetclientinfoverb */
-
-boolean mysqlgetclientversionverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- unsigned long returnCode; // The number being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- /* Process the MySQL call */
- returnCode = mysql_get_client_version();
-
- return (setlongvalue ((long) returnCode, vreturned));
-
-} /* mysqlgetclientversionverb */
-
-boolean mysqlgethostinfoverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- const char *mysqlMsg; // pointer to the message
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- mysqlMsg = mysql_get_host_info(dbid);
-
- /* Exit the verb, converting errMsg back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) mysqlMsg, strlen (mysqlMsg), &returnH))
- return false; /* Allocation failed */
-
- return (setheapvalue (returnH, stringvaluetype, vreturned));
-
-} /* mysqlgethostinfoverb */
-
-boolean mysqlgetserverversionverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- unsigned long returnCode; // the return code
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- returnCode = mysql_get_server_version(dbid);
-
- /* Exit the verb, converting errMsg back to Frontier handle */
- return (setlongvalue ((long) returnCode, vreturned));
-
-} /* mysqlgetserverversionverb */
-
-boolean mysqlgetprotocolinfoverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- unsigned int returnCode; // the return code
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- returnCode = mysql_get_proto_info(dbid);
-
- /* Exit the verb, converting errMsg back to Frontier handle */
- return (setlongvalue ((long) returnCode, vreturned));
-
-} /* mysqlgetprotocolinfoverb */
-
-boolean mysqlgetserverinfoverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- const char *mysqlMsg; // pointer to the message
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- mysqlMsg = mysql_get_server_info(dbid);
-
- /* Exit the verb, converting errMsg back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) mysqlMsg, strlen (mysqlMsg), &returnH))
- return false; /* Allocation failed */
-
- return (setheapvalue (returnH, stringvaluetype, vreturned));
-
-} /* mysqlgetserverinfoverb */
-
-boolean mysqlgetqueryinfoverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- const char *mysqlMsg; // pointer to the message
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- mysqlMsg = mysql_info(dbid);
-
- if (mysqlMsg == NULL) {
- /* Exit the verb, converting errMsg back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) "", 0, &returnH))
- return false; /* Allocation failed */
- } else {
- /* Exit the verb, converting errMsg back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) mysqlMsg, strlen (mysqlMsg), &returnH))
- return false; /* Allocation failed */
- }
-
- return (setheapvalue (returnH, stringvaluetype, vreturned));
-
-} /* mysqlgetqueryinfoverb */
-
-boolean mysqlgetaffectedrowcountverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- my_ulonglong rowCount; // this datastructure is too big for Frontier
-
- /*
- sqlite.getColumnInt(queryid, columnNumber)
-
- Action: Retrieve the value of the specified integer-type column
- Params: a query id and the number of the column (1 base)
- Returns: an SQLite result code
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_column_int.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the MySQL call */
- rowCount = mysql_affected_rows(dbid);
-
- return (setdoublevalue ((double) rowCount, vreturned));
-
-} /* mysqlgetaffectedrowcountverb */
-
-boolean mysqlgetselectedrowcountverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL_RES *queryid; // query id
- my_ulonglong rowCount; // this datastructure is too big for Frontier
-
- /*
- sqlite.getColumnInt(queryid, columnNumber)
-
- Action: Retrieve the value of the specified integer-type column
- Params: a query id and the number of the column (1 base)
- Returns: an SQLite result code
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_column_int.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &queryid)) /* Get the long value, which becomes the pointer */
- return (false);
-
- /* Process the MySQL call */
- rowCount = mysql_num_rows(queryid);
-
- return (setdoublevalue ((double) rowCount, vreturned));
-
-} /* mysqlgetselectedrowcountverb */
-
-boolean mysqlgetcolumncountverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- unsigned int returnCode; // return code from MySQL call
-
- /*
- sqlite.getColumnInt(queryid, columnNumber)
-
- Action: Retrieve the value of the specified integer-type column
- Params: a query id and the number of the column (1 base)
- Returns: an SQLite result code
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_column_int.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the pline pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the MySQL call */
- returnCode = mysql_field_count(dbid);
-
- return (setlongvalue ((long) returnCode, vreturned));
-
-} /* mysqlgetcolumncountverb */
-
-boolean mysqlgetserverstatusverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- const char *mysqlStatus; // pointer to the status message
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- Status will fail/crash if mysql.connect hasn't previously succeeded
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- mysqlStatus = mysql_stat(dbid);
-
- if (mysqlStatus == NULL) {
- return (setlongvalue ((long) 0, vreturned));
- }
- else {
- /* Exit the verb, converting errMsg back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) mysqlStatus, strlen (mysqlStatus), &returnH))
- return false; /* Allocation failed */
- }
-
- return (setheapvalue (returnH, stringvaluetype, vreturned));
-
-} /* mysqlgetserverstatusverb */
-
-boolean mysqlgetquerywarningcountverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- unsigned int returnCode; // return code from MySQL call
-
- /*
- sqlite.getColumnInt(queryid, columnNumber)
-
- Action: Retrieve the value of the specified integer-type column
- Params: a query id and the number of the column (1 base)
- Returns: an SQLite result code
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_column_int.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the pline pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the MySQL call */
- returnCode = mysql_warning_count(dbid);
-
- return (setlongvalue ((long) returnCode, vreturned));
-
-} /* mysqlgetquerywarningcountverb */
-
-boolean mysqlpingserververb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- unsigned int returnCode; // return code from MySQL call
-
- /*
- sqlite.getColumnInt(queryid, columnNumber)
-
- Action: Retrieve the value of the specified integer-type column
- Params: a query id and the number of the column (1 base)
- Returns: an SQLite result code
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_column_int.
- */
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the pline pointer */
- return (false);
-
- /* Process the MySQL call */
- returnCode = mysql_ping(dbid);
-
- return (setlongvalue ((long) returnCode, vreturned));
-
-} /* mysqlpingserververb */
-
-boolean mysqlseekrowverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL_RES *queryid; // the returned MySQL query id
- tyvaluerecord v1;
- double row; // row to seek
-
- /*
- sqlite.compileQuery(dbid, query)
-
- Action: compile an SQLite query
- Params: a database id and a query string
- Returns: a query id
- Usage: call in a try statement
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_prepare.
-
- Code that is a good example of prepare in use:
- http://souptonuts.sourceforge.net/code/eatblob.c.html
- */
-
- if (!getlongvalue (hparam1, 1, (long *) &queryid)) /* Get the long value, which becomes the query pointer */
- return (false);
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getdoubleparam (hparam1, 2, &v1)) /* get the seek row */
- return (false);
-
- row = **v1.data.doublevalue;
-
- mysql_data_seek(queryid, (my_ulonglong) row);
-
- return (setlongvalue ((long) 0, vreturned));
-
-} /* mysqlseekrowverb */
-
-boolean mysqlselectdatabaseverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
-
- MYSQL *dbid; // the MySQL object handle
- int resultCode; // result code
- Handle dbname; // existing database on MySQL server
-
- //
- // mysql.connect (dbid, host, user, password, database, port)
- //
- // Action: connects to a MySQL server and database, initializing the mySQL connection object
- // Params: dbid (the MySQL object) the hostname, user id, password, existing database name, and port
- // Returns: a MySQL object handle or an error
- // Usage: call in a try statement
- //
- // MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-real-connect.html
- //
- // If problems are encountered connecting to a Windows-based MySQL server, see:
- // http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html#can-not-connect-to-server-on-windows
- //
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* 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 */
-
- if (!gettextvalue (hparam1, 2, &dbname)) /* get the dbname param */
- return (false);
-
- // Null terminate strings
- if (!pushcharhandle (0x00, dbname))
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- // Process the MySQL request
- resultCode = mysql_select_db(dbid, *dbname);
- if (resultCode != 0) {
- langerrormessage ("\x24""Could not connect to MySQL database.");
- return (false);
- }
-
- return (setlongvalue ((long) 0, vreturned));
-
-} // mysqlselectdatabaseverb
-
-boolean mysqlgetsqlstateverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- const char *mysqlStatus; // pointer to the status message
- Handle returnH = nil; // The handle being returned back to Frontier
-
- flnextparamislast = true; /* makes sure Frontier throws an error if more than one param is passed */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the db pointer */
- return (false);
-
- // Check that server's still alive
- if (mysql_ping(dbid) != 0) {
- langerrormessage ("\x20""Lost connection to MySQL server.");
- return (false);
- }
-
- /* Process the SQLite sequence */
- mysqlStatus = mysql_sqlstate(dbid);
-
- /* Exit the verb, converting errMsg back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) mysqlStatus, strlen (mysqlStatus), &returnH))
- return false; /* Allocation failed */
-
- return (setheapvalue (returnH, stringvaluetype, vreturned));
-
-} /* mysqlgetsqlstateverb */
-
-boolean mysqlescapestringverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- MYSQL *dbid; // the MySQL object handle
- Handle fromstring;
- Handle tostring;
- unsigned long size;
- unsigned long encodedSize;
- Handle returnH = nil; // The handle being returned back to Frontier
-
- /*
- sqlite.getColumnInt(queryid, columnNumber)
-
- Action: Retrieve the value of the specified integer-type column
- Params: a query id and the number of the column (1 base)
- Returns: an SQLite result code
- Notes: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_column_int.
- */
-
- if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* Get the long value, which becomes the pline pointer */
- return (false);
-
- flnextparamislast = true; /* makes sure Frontier throws an error */
-
- if (!gettextvalue (hparam1, 2, &fromstring)) /* get the from param */
- return (false);
-
- // Null terminate strings
- if (!pushcharhandle (0x00, fromstring))
- return (false);
-
- size = strlen(*fromstring);
-
- if(!newhandle (size*2+1, &tostring)) {
- return false;
- }
-
- encodedSize = mysql_real_escape_string(dbid, *tostring, *fromstring, size);
-
- /* Exit the verb, converting the allocated string back to Frontier handle */
- if(!newfilledhandle ((ptrvoid) *tostring, encodedSize, &returnH)) {
- return false; /* Allocation failed */
- }
-
- disposehandle(tostring);
-
- return (setheapvalue (returnH, stringvaluetype, vreturned));
-
-} /* mysqlescapestringverb */
-
-boolean mysqlisthreadsafeverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- unsigned long returnCode; // The number being returned back to Frontier
-
- /*
- Frontier verb: sqlite.getErrorMessage(dbfile)
-
- Returns the error message for the most recent SQLite API call.
- Takes a database ID.
- Returns a string containing the error message.
- NOTE: do not pass the opened database ID across threads.
-
- SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_errmsg.
- */
-
- /* Process the MySQL call */
- returnCode = mysql_thread_safe();
-
- if (returnCode == 1)
- return(setbooleanvalue (true, vreturned));
- else
- return(setbooleanvalue (false, vreturned));
-
+ };
+
+ /*
+ mysql.init()
+
+ Action: initializes the mySQL library.
+ Params: none
+ Returns: a MySQL object handle or an error
+ Usage: call in a try statement, call before any other MySQL call
+
+ MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-library-init.html
+ */
+
+ // Initialize the MySQL object
+ resultCode = mysql_library_init(-1, server_args, NULL); // -1 means don't start embedded server
+ if (resultCode != 0) {
+ langerrormessage ("\x1B""MySQL could not initialize.");
+ return (false);
+ }
+
+ return (setlongvalue ((long) resultCode, vreturned));
+
+} // mysqlinitverb
+
+boolean mysqlendverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
+
+ /*
+ mysql.end()
+
+ Action: closes out the MySQL library
+ Params: none
+ Returns: a MySQL object handle or an error
+ Usage: call in a try statement, call after any other MySQL call
+
+ MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-library-end.html
+ */
+
+ // Close out the library
+ mysql_library_end();
+
+ return(setbooleanvalue (true, vreturned));
+
+} // mysqlendverb
+
+boolean mysqlconnectverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
+
+ MYSQL *dbid; // the MySQL object handle
+ Handle host; // hostname of the MySQL server
+ Handle user; // valid username on the MySQL server
+ Handle passwd; // password for user on MySQL server
+ Handle dbname; // existing database on MySQL server
+ long port; // TCP/IP port for the connection
+
+ /*
+ mysql.connect (host, user, password, database, port)
+
+ Action: connects to a MySQL server and database, initializing the mySQL connection object
+ Params: the hostname, user id, password, existing database name, and port
+ Returns: a MySQL object handle or an error
+ Usage: call in a try statement
+
+ MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-real-connect.html
+
+ If problems are encountered connecting to a Windows-based MySQL server, see:
+ http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html#can-not-connect-to-server-on-windows
+ */
+
+ if (!gettextvalue (hparam1, 1, &host)) // get the host param
+ return (false);
+
+ if (!gettextvalue (hparam1, 2, &user)) // get the user param
+ return (false);
+
+ if (!gettextvalue (hparam1, 3, &passwd)) // get the passwd param
+ return (false);
+
+ if (!gettextvalue (hparam1, 4, &dbname)) // get the dbname param
+ return (false);
+
+ flnextparamislast = true; // makes sure Frontier throws an error if more than one param is passed
+
+ if (!getlongvalue (hparam1, 5, &port)) // get the port param
+ return (false);
+
+ // Null terminate strings
+ if (!pushcharhandle (0x00, host)) return (false);
+ if (!pushcharhandle (0x00, user)) return (false);
+ if (!pushcharhandle (0x00, passwd)) return (false);
+ if (!pushcharhandle (0x00, dbname)) return (false);
+
+ // Initialize the MySQL object
+ dbid = mysql_init((MYSQL*) 0);
+ if (dbid == NULL) {
+ langerrormessage ("\x2D""MySQL could not allocate a connection object.");
+ return (false);
+ }
+ // Attempt the connection
+ dbid = mysql_real_connect(dbid, *host, *user, *passwd, *dbname, (unsigned int) port, NULL, 0 );
+ if (dbid == NULL) {
+ langerrormessage ("\x22""Could not connect to MySQL server.");
+ return (false);
+ }
+
+ return (setlongvalue ((long) dbid, vreturned));
+
+} // mysqlconnectverb
+
+
+boolean mysqlcloseverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
+ MYSQL *dbid; // the MySQL object handle
+ int returnCode; // return code from close call
+
+ /*
+ mysql.close(dbid)
+
+ Action: close a MySQL session
+ Params: a database connection id, the MySQL object
+ Returns: nothing
+ Usage: there doesn't appear to be a way to check for success or failure
+
+ MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-close.html
+ */
+
+ flnextparamislast = true; // makes sure Frontier throws an error if more than one param is passed
+
+ if (!getlongvalue (hparam1, 1, (long *) &dbid)) // Get the long value, which becomes the db pointer
+ return (false);
+
+ // Check that server's still alive
+ if (mysql_ping(dbid) != 0) {
+ langerrormessage ("\x20""Lost connection to MySQL server.");
+ return (false);
+ }
+
+ // Process the MySQL sequence
+ mysql_close(dbid);
+ returnCode = 0; // placeholder for debugging. mysql_close doesn't return anything.
+
+ return setlongvalue (returnCode, vreturned);
+
+} /* mysqlcloseverb */
+
+boolean mysqlcompilequeryverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
+ Handle query; // the SQL query passed to the MySQL server
+ MYSQL *dbid; // the MySQL object handle
+ MYSQL_RES *queryid; // the returned MySQL query id
+ int returnCode; // return code from MySQL query
+
+ /*
+ mysql.compileQuery(dbid, query)
+
+ Action: compile a MySQL query
+ Params: a database connection id and a query string
+ Returns: a query id
+ Usage: call in a try statement
+ Notes: there are a lot of possible approaches to queries in MySQL. We're using the
+ mysql_store_result version, which is more flexible, but which could have
+ some issues with large dataset returns.
+
+ MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-query.html
+ http://dev.mysql.com/doc/refman/5.1/en/mysql-store-result.html
+ */
+
+ if (!getlongvalue (hparam1, 1, (long *) &dbid)) /* 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 */
+
+ if (!gettextvalue (hparam1, 2, &query)) // get the query param
+ return (false);
+
+ // Null terminate strings
+ if (!pushcharhandle (0x00, query))
+ return (false);
+
+ // Check that server's still alive
+ if (mysql_ping(dbid) != 0) {
+ langerrormessage ("\x20""Lost connection to MySQL server.");
+ return (false);
+ }
+
+ // Process the initial query sequence
+ returnCode = mysql_query(dbid, *query);
+ if(returnCode != 0) {
+ langerrormessage ("\x21""Could not initialize MySQL query.");
+ return (false);
+ }
+
+ queryid = mysql_store_result(dbid);
+ if(mysql_errno(dbid) != 0) {
+ langerrormessage ("\x21""Could initialize MySQL query.");
+ return (false);
+ }
+
+ if (mysql_field_count(dbid) == 0)
+ return (setlongvalue ((long) 0, vreturned)); // return 0 to the scripter
+ else
+ return (setlongvalue ((long) queryid, vreturned)); // return the db address to the scripter
+} /* mysqlcompilequeryverb */
+
+boolean mysqlclearqueryverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
+ MYSQL_RES *queryid; // the returned MySQL query id
+ int returnCode;
+
+ /*
+ mysql.clearQuery(queryid)
+
+ Action: clear a MySQL query
+ Params: a query id
+ Returns: 0 (MySQL doesn't return anything)
+
+ MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-free-result.html
+ */
+
+ flnextparamislast = true; // makes sure Frontier throws an error if more than one param is passed
+
+ if (!getlongvalue (hparam1, 1, (long *) &queryid)) // Get the long value, which becomes the queryid pointer
+ return (false);
+
+ // Process the MySQL sequence
+ mysql_free_result(queryid);
+
+ returnCode = 0; // placeholder. mysql_free_result doesn't return anything.
+ return setlongvalue (returnCode, vreturned);
+
+} /* mysqlclearqueryverb */
+
+boolean mysqlgetrowverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
+ unsigned int fieldNumber; /* field number */
+ unsigned int fieldCount; /* number of fields */
+ MYSQL_RES *queryid; /* query id */
+ MYSQL_ROW row;
+ MYSQL_FIELD *field;
+ hdllistrecord hlist;
+ Handle returnH;
+ const unsigned char *column_text;
+ tyvaluerecord val;
+
+ /*
+ mysql.getRow(queryid)
+
+ Action: return the next row from the query result set
+ Params: a query id
+ Returns: 0 if no more rows, or a Frontier list containing data
+
+ MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-fetch-row.html
+ http://dev.mysql.com/doc/refman/5.1/en/mysql-num-fields.html
+ http://dev.mysql.com/doc/refman/5.1/en/mysql-field-seek.html
+ http://dev.mysql.com/doc/refman/5.1/en/mysql-fetch-field.html
+
+ Notes:
+
+ MySQL might also return a 0 if there's an error. It's important to check
+ for an error if a zero value is returned to differentiate between end of
+ dataset and last row.
+
+ The MySQL fetch_row function is interesting, in that it looks like
+ each field returned is returned as a string. This is great for Frontier,
+ since Frontier can't handle some of MySQL's bigger number types (like double),
+ but it can handle strings. So everything that's supported is returned as
+ a string to Frontier. The Frontier programmer can then do whatever
+ coercing is necessary.
+
+ The only formats we explicitly don't support are:
+
+ MYSQL_TYPE_BIT
+ MYSQL_TYPE_BLOB
+ MYSQL_TYPE_SET
+ MYSQL_TYPE_ENUM
+ MYSQL_TYPE_GEOMETRY
+ MYSQL_TYPE_NULL
+
+ Formats supported and returned as s...
[truncated message content] |