Pub.ISQLDB and friends

BlitzMax Forums/BlitzMax Module Tweaks/Pub.ISQLDB and friends

gman(Posted 2006) [#1]
FYI, i have just released the Pub.ISQLDB database interface module for BlitzMax and its first complete implementation (Pub.MySQL).

Pub.ISQLDB is meant to provide a common interface for accessing different database engines from within BlitzMax.

Pub.MySQL is an implementation of Pub.ISQLDB that allows basic client access to a MySQL server.

each are documented using bbdoc and there is a brief, but hopefully adequate install TXT file included with the zips.

for a free and remotely accessable MySQL database server to test with checkout:

http://www.freesql.org

a simple example of using the MySQL mod:
SuperStrict

Framework BRL.Blitz

Import Pub.MySQL

Local conn:ISQLDB=SetISQLDBDriver(GetMySQLDBDriver(True,"www.freesql.org","username","password","database"))

Local result:ISQLResult=conn.execute("SELECT * FROM demotable")

DebugLog("rows: "+result.getNumRows())
DebugLog(result.getValByName(0,"id"))
DebugLog(result.getValByName(2,"DEMODATA"))

result=Null
conn=Null

downloads are available from the Pub.ISQLDB section of my forums (see sig).

the future is very bright as i am already nearing completion of Pub.PostgreSQL and should have it ready by the weekend. next is planned a proxy implementation that will allow you to work with a database via HTTP (which is what i was originally going to write), bypassing the issue with host providers not allowing external access to the DB server. after that, will be an implementation of SQLite3.

and of course, all of the mods are/will be free :) enjoy!

on a side note, id love to get the implementation mods cross platform but do not have linux or mac to test with. if anyone is interested in working with me on this please lmk.


xlsior(Posted 2006) [#2]
Sounds very interesting!


assari(Posted 2006) [#3]
This look very promising.
Your effort is very much appreciated. I'm hoping to get into this soon.


gman(Posted 2006) [#4]
greetings assari :) thx. as i need things i try to further the community as well (as do many others). giving a little back to the community that gives so much :)

on a side note, i notice you are from the Netherlands. have you heard of/listen to Bambix? my fav band... man id love to see them live. their music keeps my blood pumping hard and the developing fast :)


Difference(Posted 2006) [#5]
Very interesting.
Hoping to look into it soon!


assari(Posted 2006) [#6]
gman,
I was in the netherlands a few years back. Now I'm in the US. Forgot to update my profile :( . I really enjoyed the netherlands.


Gavin Beard(Posted 2006) [#7]
Thanks for this, MySql is a great help to me, will attempt some tests connecting to my sql server when i get home :D


degac(Posted 2006) [#8]
Very very very interesting...thank you very much...this evening I have to test it...


Gavin Beard(Posted 2006) [#9]
i'm getting error E:/Program Files/BlitzMax/bin/ld.exe: cannot find -lmySQL

i've put the folders in the right place and it wont go


gman(Posted 2006) [#10]
hi gavin_b :) looks like blitzmax isnt finding the libmySQL.a file. there is a lib directory under the mysql.mod directory. copy the libmySQL.a into your blitzmax\lib folder and then try rebuilding.


Gavin Beard(Posted 2006) [#11]
Thanks GMan, now it compiles the sample code above buy gives error 'Unhandled Memory Exception Error' it seems to be the getValByName functions


gman(Posted 2006) [#12]
does a regular getVal work? also, what does getNumRows() say? any sample code of what you are trying?

thx.


Gavin Beard(Posted 2006) [#13]
SuperStrict

Framework BRL.Blitz

Import Pub.MySQL

Local conn:ISQLDB=SetISQLDBDriver(GetMySQLDBDriver(True,"xxx","xxx","xxx","xxx"))

Local result:ISQLResult=conn.execute("SELECT * FROM test1")

DebugLog("rows: "+result.getNumRows())

result=Null
conn=Null

doesnt throw an error but doesnt actually show n e thing, just a blank result?

if i use getval(0,0) or or (1,0) i get a blank result however if i use (0,1) i get Invalid Column 1 which is right...


gman(Posted 2006) [#14]
try this:
SuperStrict

Framework BRL.Blitz

Import Pub.MySQL

Local conn:ISQLDB=SetISQLDBDriver(GetMySQLDBDriver(True,"localhost","user","pass","test"))

Local result:ISQLResult=conn.execute("SELECT * FROM test1")

DebugLog("colcount: "+result.getNumCols())
DebugLog("col0 name: "+result.getColName(0))
For Local i:Int=0 To result.getNumRows()-1
	DebugLog(result.getVal(i,0))
	DebugLog("err: "+result.getErrorMsg())
Next

result=Null
conn=Null

i get:

DebugLog:colcount: 1
DebugLog:col0 name: Mook
DebugLog:8
DebugLog:err:
DebugLog:0
DebugLog:err:
DebugLog:6
DebugLog:err:
DebugLog:9
DebugLog:err:
DebugLog:6
DebugLog:err:
DebugLog:9
DebugLog:err:
DebugLog:69
DebugLog:err:
DebugLog:69
DebugLog:err:
DebugLog:97
DebugLog:err:


is that correct for the data stored in that column?


Gavin Beard(Posted 2006) [#15]
Building untitled1
Compiling:untitled1.bmx
flat assembler version 1.64
3 passes, 1345 bytes.
Linking:untitled1.exe
Executing:untitled1.exe

Process complete

EDIT: my bad, didnt have debug build option on :D

brill. mod one of the best


gman(Posted 2006) [#16]
make sure you are building debug under the build options or change my debuglogs to Print commands...


gman(Posted 2006) [#17]
good deal. working then? you may want to edit your post and remove the connection info...

also thx :)


Gavin Beard(Posted 2006) [#18]
yeah, it works brilliantly, i removed my info, glad u finished postgre as well as i'll be added that to my web server next month


gman(Posted 2006) [#19]
helped me find a bug too :) error reporting wasnt working for getval if you went beyond the # of rows you have.


Gavin Beard(Posted 2006) [#20]
lol, good, looked in docs and i cant see how insert a new row of info, n e heads up?


gman(Posted 2006) [#21]
currently there are no special methods for insert, update, or delete (theres already ideas being thrown around on gprogs.com forums about that and command objects). you will need to use the executeNonQuery() method using straight SQL. ie:

INSERT INTO test1 (Mook) VALUES ('gg')
UPDATE test1 SET Mook='gg1' WHERE Mook='gg'
DELETE FROM test1 WHERE Mook='gg1'


Gavin Beard(Posted 2006) [#22]
ahh, just std. sql :) lol. well, shouldnt be too bad, thanks again gman :D

Edit* just tried adding and deleting info from db and it works wonders, u rock g


Gavin Beard(Posted 2006) [#23]
*Double post*


gman(Posted 2006) [#24]
just an FYI, i have proposed some additions to the interface in the gprogs.com forum, most in relation to adding command objects similar to dot NET. command objects are essentially the final step in providing a true cross-db interface for BMAX. comments/questions would be much appreciated.

thx.


Gavin Beard(Posted 2006) [#25]
Just another thanks, this module has allowed me to finish the login/registration part of an online multiplayer game i have started work on, it has allowed to create a mysql db of all user info and works very fast, thanks gman


gman(Posted 2006) [#26]
you are very welcome gavin_b :) unfortunately ive had my hands full with a couple of other projects over the last few weeks. i still have some work on those to do and with the Mac version of the Irrlicht mods looming i probably wont get back to improving this set of mods until march sometime. stay tuned :)


Gavin Beard(Posted 2006) [#27]
*sorted


Gavin Beard(Posted 2006) [#28]
Hi all, just thought i'd share this with you, its the login screen for my game, u can click the 'new account' option and fill in username and password (dont worry about other fields) then close the registration screen and type you logins in. It uses PHP for the registration screen and the actual login in done with this module :) i know the php layout needs some work and it doesnt inform you of acount creation, but it does work if the 2 passwords dont match.

n e who, n e comments welcome :D

http://www.3dcg.co.uk/main.rar
*thanks gman


gman(Posted 2006) [#29]
i like the status messages at the bottom of the login screen. the PHP screen could be a little bigger (longer) and for some reason tabbing doesnt work in the PHP screen which is a bit annoying. i was able to connect. good job!


Gavin Beard(Posted 2006) [#30]
yeah cant figure out the PHP tabbing think, i havent set n e flags, but i'll get there :)just wanted to show how well ure mpodule runs


Booticus(Posted 2006) [#31]
Hello all. I'm trying to get my head around the whole database thing, so forgive me for sounding stupid. (OK, mandatory self depracation out of the way!)

I've got the module working and its great (Thanks Gavin and gMan!) It works remotely just fine and I have mySQL 5.0 installed locally on my desktop machine for local development and thats great too...

But are there any options for using it CLIENT SIDE only? To perhaps include a database for game assets, etc.? Just curious. For online stuff (persistent worlds, highscores, etc.) I can see this being pretty neat to store and manipulate data remotely, but I was more curious about client side apps.


xlsior(Posted 2006) [#32]
But are there any options for using it CLIENT SIDE only?


Not without a (stripped down?) copy of the datbase engine (MySQL) installed on the client as well.

Perhaps an MS Access database module could address that?


assari(Posted 2006) [#33]
see this thread Looking for a small, reliable and free database


Booticus(Posted 2006) [#34]
Neat! Firebird looks neat. Have to wait for a wrapper. Ah well, no big. There's always XML to store data. :)


gman(Posted 2006) [#35]
FYI, i built the libmySQL.a for MySQL 5.0.18 and repackaged the MySQL mod to include it. its available on in my ISQLDB forum.


Phobos(Posted 2006) [#36]
Hi all.

Help!

When I try to compile the test I have this compile error:
"Can't find interface for module 'pub.mysql'"

1) I have installed the two mods with this dir structure:
F:\BlitzMax\mod\pub.mod\isqldb.mod
F:\BlitzMax\mod\pub.mod\mysql.mod

2) I have copied the mysql 4.1.16 include dir, with this dir structure:
F:\BlitzMax\mod\pub.mod\mysql.mod\include

3) I have copied the libmysql.a file from msql.mod\lib folder to:
F:\BlitzMax\lib

4) I have copied the libmysql.dll from mysql...\lib\opt in:
c:\windows\system32

5) Restarted blitmax after installation...

I really don't know what to do now!

(Sorry for my bad scholastic english!)

thx!


gman(Posted 2006) [#37]
greetings Phobos :) my apologies for not doing this earlier, but the mods needed rebuilt for BMAX v1.18+ and i just didnt get around to it. i have rebuilt and repackaged the downloads for BMAX v1.20. if you are still on v1.18 lmk and i will provide instructions for rebuilding the mods.

http://www.gprogs.com/forum/viewtopic.php?id=32


Phobos(Posted 2006) [#38]
Ok, thanks gman!!!


Zumwalt(Posted 2006) [#39]
Gman this rocks!
I was looking for Noels, but couldn't find it, this setup fast and easy, thanks!


gman(Posted 2006) [#40]
you are very welcome :)


SculptureOfSoul(Posted 2006) [#41]
Hey GMan, I love the module. I'm a database virgin and already I'm finding it easy to use and figure out.

...edited b/c the problem I had was definitely a user error. ;0

...edited again b/c now I don't think the above is true. The problem I'm having is the need to cast the returned SQLDB object (returned from GetMySQLDBDriver()) to an iSQLDB object to utilize the SelectDB() function. There's no abstract SelectDB() method within SQLDB.

I'm not sure if that was an intentional design decision (I'm not sure how PostGreSQL works so it might not make sense to have SelectDB() in the SQLDB object...). Just thought I'd point it out.


gman(Posted 2006) [#42]
greetings and thank you :) as far as i know the selectdb() functionality is not available in PostgreSQL which is why i chose to not put it on the child type of MySQL. i have seen implementations (like ADODB) where selectdb() is on the parent type but just does nothing for PostgreSQL. i could go both ways really on the design.

as for what you are trying to do, the only way i know of to select a different DB in PostgreSQL is to reconnect with the different DB in there.

hope that helps you out :)


SculptureOfSoul(Posted 2006) [#43]
Sorry, I didn't make it clear. Actually I'm using MySQL.

I guess I'm curious as to why GetMySQLDBDriver returns an SQLDB object instead of an interface to MySQL (iMySQLDB) object.

It's not much of a problem though. I realized that I can just cast the return of GetMySQLDBDriver() once and that'll save me from casting whenever I need to call a method in iMySQLDB.


Vertex(Posted 2006) [#44]
Does it work on Linux?

My own MySQL Module based of the work of Michael 'Jolinah' Zehr
http://vertex.dreamfall.at/mysql/mysql102.zip

cu olli