|
From: <cre...@us...> - 2007-05-31 22:22:14
|
Revision: 1664
http://svn.sourceforge.net/frontierkernel/?rev=1664&view=rev
Author: creecode
Date: 2007-05-31 15:22:15 -0700 (Thu, 31 May 2007)
Log Message:
-----------
in function mysqlgetrowverb, fix for crash when column_text is NULL, return nil
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-05-30 22:26:15 UTC (rev 1663)
+++ Frontier/branches/mysql/Common/source/langmysql.c 2007-05-31 22:22:15 UTC (rev 1664)
@@ -440,7 +440,73 @@
} /* mysqlclearqueryverb */
+
boolean mysqlgetrowverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
+
+ //
+ // 2007-05-31 creedon, asseily: fix for crash when column_text is NULL, return nil
+ //
+ // 2007-05-29 gewirtz: created
+ //
+
+ /*
+
+ 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 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
+
+ More info: http://dev.mysql.com/doc/refman/5.1/en/c-api-datatypes.html
+
+ */
+
unsigned int fieldNumber; /* field number */
unsigned int fieldCount; /* number of fields */
MYSQL_RES *queryid; /* query id */
@@ -451,63 +517,7 @@
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 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
-
- More info: 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 */
@@ -555,12 +565,21 @@
case MYSQL_TYPE_VAR_STRING:
{
column_text = row[fieldNumber];
+
+ if ( column_text == NULL )
+
+ setnilvalue ( &val );
+
+ else {
- // 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;
+ // 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;
@@ -581,6 +600,7 @@
} /* mysqlgetrow */
+
boolean mysqlgeterrornumberverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
MYSQL *dbid; // the MySQL object handle
unsigned int returnCode; // return code from MySQL call
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|