|
From: <dav...@us...> - 2007-04-15 23:37:15
|
Revision: 1656
http://svn.sourceforge.net/frontierkernel/?rev=1656&view=rev
Author: davidgewirtz
Date: 2007-04-15 16:37:08 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
Full set of MySQL API functions implemented in Frontier.
Modified Paths:
--------------
Frontier/branches/mysql/Common/headers/langmysql.h
Frontier/branches/mysql/Common/resources/Mac/kernelverbs.r
Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc
Frontier/branches/mysql/Common/source/langmysql.c
Modified: Frontier/branches/mysql/Common/headers/langmysql.h
===================================================================
--- Frontier/branches/mysql/Common/headers/langmysql.h 2007-04-12 22:39:57 UTC (rev 1655)
+++ Frontier/branches/mysql/Common/headers/langmysql.h 2007-04-15 23:37:08 UTC (rev 1656)
@@ -29,6 +29,8 @@
extern boolean mysqlinitverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
+extern boolean mysqlendverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-15 gewirtz */
+
extern boolean mysqlconnectverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
extern boolean mysqlcompilequeryverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-09 gewirtz */
@@ -73,6 +75,10 @@
extern boolean mysqlgetsqlstateverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-12 gewirtz */
+extern boolean mysqlescapestringverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-15 gewirtz */
+
+extern boolean mysqlisthreadsafeverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-15 gewirtz */
+
extern boolean mysqlcloseverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
Modified: Frontier/branches/mysql/Common/resources/Mac/kernelverbs.r
===================================================================
--- Frontier/branches/mysql/Common/resources/Mac/kernelverbs.r 2007-04-12 22:39:57 UTC (rev 1655)
+++ Frontier/branches/mysql/Common/resources/Mac/kernelverbs.r 2007-04-15 23:37:08 UTC (rev 1656)
@@ -1170,6 +1170,7 @@
{
"mysql", false, {
"init",
+ "end",
"connect",
"compileQuery",
"clearQuery",
@@ -1192,6 +1193,8 @@
"seekRow",
"selectDatabase",
"getSQLSTATE",
+ "escapeString",
+ "isThreadSafe",
"close"
}
}
Modified: Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc
===================================================================
--- Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc 2007-04-12 22:39:57 UTC (rev 1655)
+++ Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc 2007-04-15 23:37:08 UTC (rev 1656)
@@ -1106,8 +1106,9 @@
1, // Number of "blocks" in this resource
"mysql\0", // Function Processor name
false, // Window required
- 24, // Count of verbs
+ 27, // Count of verbs
"init\0",
+ "end\0",
"connect\0",
"compileQuery\0",
"clearQuery\0",
@@ -1130,5 +1131,7 @@
"seekRow\0",
"selectDatabase\0",
"getSQLSTATE\0",
+ "escapeString\0",
+ "isThreadSafe\0",
"close\0"
END
Modified: Frontier/branches/mysql/Common/source/langmysql.c
===================================================================
--- Frontier/branches/mysql/Common/source/langmysql.c 2007-04-12 22:39:57 UTC (rev 1655)
+++ Frontier/branches/mysql/Common/source/langmysql.c 2007-04-15 23:37:08 UTC (rev 1656)
@@ -74,6 +74,7 @@
typedef enum tymysqlverbtoken { /* verbs that are processed by langmysql.c */
initfunc,
+ endfunc,
connectfunc,
compilequeryfunc,
clearqueryfunc,
@@ -96,6 +97,8 @@
seekrowfunc,
selectdatabasefunc,
getsqlstatefunc,
+ escapestringfunc,
+ isthreadsafefunc,
closefunc,
ctmysqlverbs
} tymysqlverbtoken;
@@ -113,6 +116,9 @@
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 */
@@ -179,6 +185,12 @@
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 */
@@ -195,7 +207,12 @@
} /* mysqlinitverbs */
boolean mysqlinitverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
- MYSQL *dbid; // the MySQL object handle
+ 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()
@@ -209,16 +226,36 @@
//
// Initialize the MySQL object
- dbid = mysql_init((MYSQL*) 0);
- if (dbid == NULL) {
- langerrormessage ("\x23""MySQL did not initialize correctly.");
+ 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) dbid, vreturned));
+ 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
@@ -242,24 +279,21 @@
// 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 */
+ if (!gettextvalue (hparam1, 1, &host)) /* get the host param */
return (false);
- if (!gettextvalue (hparam1, 2, &host)) /* get the host param */
+ if (!gettextvalue (hparam1, 2, &user)) /* get the user param */
return (false);
- if (!gettextvalue (hparam1, 3, &user)) /* get the user param */
+ if (!gettextvalue (hparam1, 3, &passwd)) /* get the passwd param */
return (false);
- if (!gettextvalue (hparam1, 4, &passwd)) /* get the passwd param */
+ if (!gettextvalue (hparam1, 4, &dbname)) /* get the dbname param */
return (false);
- if (!gettextvalue (hparam1, 5, &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, 6, &port)) /* get the port param */
+ if (!getlongvalue (hparam1, 5, &port)) /* get the port param */
return (false);
// Null terminate strings
@@ -268,6 +302,12 @@
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) {
@@ -1141,4 +1181,78 @@
return (setheapvalue (returnH, stringvaluetype, vreturned));
-} /* mysqlgetsqlstateverb */
\ No newline at end of file
+} /* 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));
+
+} /* mysqlisthreadsafeverb */
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|