Raised This Month: $32 Target: $400
 8% 

NEW DBI API (MySQL /SQL)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
BAILOPAN
Join Date: Jan 2004
Old 06-11-2004 , 18:22   NEW DBI API (MySQL /SQL)
Reply With Quote #1

This is very important for scripters! For AMXx 0.20, I have significantly changed the SQL interface. All plugins will be rendered broken, so you will need to upgrade.

If you need any help with this, just ask. I can help you convert your plugin or answer technical questions. Remember though, this is for 0.20 and you should be prepared to swap in the new code close to the release date (we will announce this).

This new DBI is important because it gets rid of the shoddy interface from AMX 0.9.x. Plugin writers now get resource handles for both result sets and connections, as well as a better guarantee that the driver will not crash.

To best explain this, here is a sample program:

Code:
//Create a connection     new Sql:mysql = dbi_connect("localhost", "dvander", "pass", "dbase") //If the connection is less than 1, it is bad        if (mysql < SQL_OK) {         new err[255]         new errNum = dbi_error(mysql, err, 254)         server_print("error1: %s|%d", err, errNum)         return 1     }         server_print("Connection handle: %d", mysql) //Run a query     new Result:ret = dbi_query(mysql, "INSERT INTO config (keyname, val) VALUES ('amx', 'yes')") //If the query is less than 0, it failed        if (ret < RESULT_NONE) {         new err[255]         new errNum = dbi_error(mysql, err, 254)         server_print("error2: %s|%d", err, errNum)         return 1     } //Do a select query      new Result:res = dbi_query(mysql, "SELECT * FROM config") //If the query is greater than 0, you got a handle to the result set        if (res <= RESULT_NONE) {         new err[255]         new errNum = dbi_error(mysql, err, 254)         server_print("error3: %s|%d", err, errNum)         return 1     }         server_print("Result handle: %d", res) //Loop through the result set        while (res && dbi_nextrow(res)>0) {         new qry[32] //Get the column/field called "keyname" from the result set         dbi_result(res, "keyname", qry, 32)         server_print("result: %s", qry)     } //Free the result set        dbi_free_result(res) //Close the connection      ret = dbi_close(mysql)     if (ret <= RESULT_NONE) {         new err[255]         new errNum = dbi_error(mysql, err, 254)         server_print("error4: %s|%d", err, errNum)         return 1     }

These differences are subtle and important. It means you can create nested or recursive SQL queries and not have the previous ones erased. It also gives you much better errorchecking/debugging control. You can also reference fields by name instead of number.

To see more, look in the dbi.inc file from CVS.
__________________
egg
BAILOPAN is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode