|
From: <dav...@us...> - 2007-04-09 03:48:45
|
Revision: 1650
http://svn.sourceforge.net/frontierkernel/?rev=1650&view=rev
Author: davidgewirtz
Date: 2007-04-08 20:48:44 -0700 (Sun, 08 Apr 2007)
Log Message:
-----------
Successfully connecting to MySQL database, added verbs mysql.init, mysql.connect, mysql.close.
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-08 23:09:35 UTC (rev 1649)
+++ Frontier/branches/mysql/Common/headers/langmysql.h 2007-04-09 03:48:44 UTC (rev 1650)
@@ -29,6 +29,8 @@
extern boolean mysqlinitverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 gewirtz */
+extern boolean mysqlconnectverb (hdltreenode, tyvaluerecord *, bigstring); /* 2007-04-08 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-08 23:09:35 UTC (rev 1649)
+++ Frontier/branches/mysql/Common/resources/Mac/kernelverbs.r 2007-04-09 03:48:44 UTC (rev 1650)
@@ -1171,6 +1171,7 @@
"mysql", false, {
"init",
+ "connect",
"close"
}
}
Modified: Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc
===================================================================
--- Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc 2007-04-08 23:09:35 UTC (rev 1649)
+++ Frontier/branches/mysql/Common/resources/Win32/kernelverbs.rc 2007-04-09 03:48:44 UTC (rev 1650)
@@ -1106,7 +1106,8 @@
1, // Number of "blocks" in this resource
"mysql\0", // Function Processor name
false, // Window required
- 2, // Count of verbs
+ 3, // Count of verbs
"init\0",
+ "connect\0",
"close\0"
END
Modified: Frontier/branches/mysql/Common/source/langmysql.c
===================================================================
--- Frontier/branches/mysql/Common/source/langmysql.c 2007-04-08 23:09:35 UTC (rev 1649)
+++ Frontier/branches/mysql/Common/source/langmysql.c 2007-04-09 03:48:44 UTC (rev 1650)
@@ -74,6 +74,7 @@
typedef enum tymysqlverbtoken { /* verbs that are processed by langmysql.c */
initfunc,
+ connectfunc,
closefunc,
ctmysqlverbs
} tymysqlverbtoken;
@@ -93,6 +94,11 @@
return (mysqlinitverb (hp1, v, bserror));
} /* initfunc */
+ case connectfunc: { /* 2007-04-08 gewirtz: initialize MySQL */
+
+ return (mysqlconnectverb (hp1, v, bserror));
+ } /* connectfunc */
+
case closefunc: { /* 2007-04-08 gewirtz: close a MySQL db */
return (mysqlcloseverb (hp1, v, bserror));
@@ -113,56 +119,86 @@
boolean mysqlinitverb ( hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror ) {
- Handle dbfile; // path to database file
MYSQL *dbid; // the MySQL object handle
- int returnCode; // return code from SQLite call
- tyfilespec fs; // file specification
-
+
//
- // 2007-04-08 DG: hacked up from sqlite for mysql
- // 2006-11-06 creedon: use filespec as parameter, convert dbfile to UTF-8 for sqlite3_open
+ // 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
//
- // 2006-10-08 DG: created
- //
- #ifdef WIN95VERSION
+ // Initialize the MySQL object
+ dbid = mysql_init((MYSQL*) 0);
+ if (dbid == NULL) {
+ langerrormessage ("\x23""MySQL did not initialize correctly.");
+ return (false);
+ }
+
+ return (setlongvalue ((long) dbid, vreturned));
- bigstring bs;
- Handle handletext;
-
- #endif // WIN95VERSION
-
+} // mysqlinitverb
+
+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
+
//
- // sqlite.open ( dbfile )
+ // mysql.connect (host, user, password, database, port)
//
- // Action: opens a SQLite database
- // Params: a file path to the database file
- // Returns: a value that corresponds to the opened database ID
+ // 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
- // Notes: do not pass the opened database ID across threads
//
- // SQLite docs: http://www.sqlite.org/capi3ref.html#sqlite3_open
+ // MySQL docs: http://dev.mysql.com/doc/refman/5.1/en/mysql-real-connect.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);
+
+ if (!getreadonlytextvalue (hparam1, 2, &host)) /* get the host param */
+ return (false);
+
+ if (!getreadonlytextvalue (hparam1, 3, &user)) /* get the user param */
+ return (false);
+
+ if (!getreadonlytextvalue (hparam1, 4, &passwd)) /* get the passwd param */
+ return (false);
+
+ if (!getreadonlytextvalue (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 */
+ return (false);
+
+ // Null terminate strings
+ pushcharhandle (0x00, host);
+ pushcharhandle (0x00, user);
+ pushcharhandle (0x00, passwd);
+ pushcharhandle (0x00, dbname);
+
+ // 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);
+ }
- // Process the SQLite sequence
-
- dbid = mysql_init((MYSQL*) 0);
-
-// if(returnCode) {
-// sqliteOpenError(sqlite3_errmsg(dbid), bserror); // send database open error
-// sqlite3_close(dbid);
-// return (false);
-// }
-
- // return the db address to the scripter
- // return (setheapvalue ((Handle) dbid, longvaluetype, vreturned));
- // 2006-09-06 - kw - simply return a long
-
return (setlongvalue ((long) dbid, vreturned));
- } // mysqlinitverb
+} // mysqlconnectverb
boolean mysqlcloseverb (hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|