|
From: <dav...@us...> - 2007-04-10 21:25:13
|
Revision: 1653
http://svn.sourceforge.net/frontierkernel/?rev=1653&view=rev
Author: davidgewirtz
Date: 2007-04-10 14:25:09 -0700 (Tue, 10 Apr 2007)
Log Message:
-----------
Added getErrorNumber and getErrorMessage verbs.
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-10 15:17:15 UTC (rev 1652)
+++ Frontier/branches/mysql/Common/headers/langmysql.h 2007-04-10 21:25:09 UTC (rev 1653)
@@ -27,20 +27,24 @@
/* prototypes */
-extern boolean mysqlinitverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
+extern boolean mysqlinitverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
-extern boolean mysqlconnectverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
+extern boolean mysqlconnectverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
-extern boolean mysqlcompilequeryverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-09 gewirtz */
+extern boolean mysqlcompilequeryverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-09 gewirtz */
-extern boolean mysqlclearqueryverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-09 gewirtz */
+extern boolean mysqlclearqueryverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-09 gewirtz */
-extern boolean mysqlfetchrowverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-09 gewirtz */
+extern boolean mysqlgetrowverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-09 gewirtz */
-extern boolean mysqlcloseverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
+extern boolean mysqlgeterrornumberverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-10 gewirtz */
+extern boolean mysqlgeterrormessageverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-10 gewirtz */
+extern boolean mysqlcloseverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
+
+
extern boolean mysqlinitverbs (void); /* 2007-04-08 gewirtz */
/* boolean hmacmd5 (unsigned char *, int, unsigned char *, int, unsigned char *);*/ /* 2006-03-05 creedon */
Modified: Frontier/branches/mysql/Common/resources/Mac/kernelverbs.r
===================================================================
--- Frontier/branches/mysql/Common/resources/Mac/kernelverbs.r 2007-04-10 15:17:15 UTC (rev 1652)
+++ Frontier/branches/mysql/Common/resources/Mac/kernelverbs.r 2007-04-10 21:25:09 UTC (rev 1653)
@@ -1174,7 +1174,9 @@
"connect",
"compileQuery",
"clearQuery",
- "fetchRow",
+ "getRow",
+ "getErrorNumber",
+ "getErrorMessage",
"close"
}
}
Modified: Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc
===================================================================
--- Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc 2007-04-10 15:17:15 UTC (rev 1652)
+++ Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc 2007-04-10 21:25:09 UTC (rev 1653)
@@ -1106,11 +1106,13 @@
1, // Number of "blocks" in this resource
"mysql\0", // Function Processor name
false, // Window required
- 6, // Count of verbs
+ 8, // Count of verbs
"init\0",
"connect\0",
"compileQuery\0",
"clearQuery\0",
- "fetchRow\0",
+ "getRow\0",
+ "getErrorNumber\0",
+ "getErrorMessage\0",
"close\0"
END
Modified: Frontier/branches/mysql/Common/source/langmysql.c
===================================================================
--- Frontier/branches/mysql/Common/source/langmysql.c 2007-04-10 15:17:15 UTC (rev 1652)
+++ Frontier/branches/mysql/Common/source/langmysql.c 2007-04-10 21:25:09 UTC (rev 1653)
@@ -77,7 +77,9 @@
connectfunc,
compilequeryfunc,
clearqueryfunc,
- fetchrowfunc,
+ getrowfunc,
+ geterrornumberfunc,
+ geterrormessagefunc,
closefunc,
ctmysqlverbs
} tymysqlverbtoken;
@@ -112,11 +114,21 @@
return (mysqlclearqueryverb (hp1, v, bserror));
} /* clearqueryfunc */
- case fetchrowfunc: { /* 2007-04-09 gewirtz: get a full row from a query */
+ case getrowfunc: { /* 2007-04-09 gewirtz: get a full row from a query */
- return (mysqlfetchrowverb (hp1, v, bserror));
- } /* fetchrowfunc */
+ return (mysqlgetrowverb (hp1, v, bserror));
+ } /* getrowfunc */
+ case geterrornumberfunc: { /* 2007-04-09 gewirtz: get the error number from the most recent call */
+
+ return (mysqlgeterrornumberverb (hp1, v, bserror));
+ } /* geterrornumberfunc */
+
+ case geterrormessagefunc: { /* 2007-04-09 gewirtz: get the error message from the most recent call */
+
+ return (mysqlgeterrormessageverb (hp1, v, bserror));
+ } /* geterrormessagefunc */
+
case closefunc: { /* 2007-04-08 gewirtz: close a MySQL db */
return (mysqlcloseverb (hp1, v, bserror));
@@ -180,6 +192,9 @@
//
// 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);
@@ -287,9 +302,9 @@
}
queryid = mysql_store_result(dbid);
- if(mysql_errno(dbid) != 0) {
+ if(mysql_errno(dbid) != 0) {
langerrormessage ("\x21""Could initialize MySQL query.");
- return (false);
+ return (false);
}
return (setlongvalue ((long) queryid, vreturned)); /* return the db address to the scripter */
@@ -325,17 +340,15 @@
} /* mysqlclearqueryverb */
-boolean mysqlfetchrowverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
- long fieldNumber; /* field number */
+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_RES *queryid; /* query id */
MYSQL_ROW row;
MYSQL_FIELD *field;
hdllistrecord hlist;
- int returnCode; /* return code from SQLite call */
- double returnDouble; /* double value returned from SQLite call */
Handle returnH;
const unsigned char *column_text;
@@ -360,40 +373,40 @@
}
fieldCount = mysql_num_fields(queryid);
- if (fieldCount == 0) {
- langerrormessage ("\x2F""MySQL.fetchRow 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
+ 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:
-
+
+ Formats supported and returned as string:
+
MYSQL_TYPE_TINY
MYSQL_TYPE_SHORT
MYSQL_TYPE_LONG
@@ -410,51 +423,110 @@
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);
+ */
+
+ 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);
}
-} /* mysqlfetchrow */
\ No newline at end of file
+} /* 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);
+
+ /* 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);
+
+ /* 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 */
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|