bah.database

BlitzMax Modules Forums/Brucey's Modules/bah.database

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I tried the bah.database prepared queries but they don't make any difference to the retrieval speed.


The idea with prepared queries, is that you prepared them "somewhere", and when you need it, you just execute it... as many times as you like, without having the expense of "recompiling" the SQL each time you want to execute.
In theory, it's much more efficient to use the "prepare once, execute many" method.

The actual retrieval (nextRow) itself will be the same speed for prepared or non-prepared queries.

Here's an example from a project of mine, which shows caching of a query :
	Function sqlAddRoute(id:Int)
		Global addRouteQuery:TDatabaseQuery
		
		If conn And conn.isOpen() Then
		
			If Not addRouteQuery Then
				addRouteQuery = TDatabaseQuery.Create(conn)
				sqlPrepareQuery(addRouteQuery, "INSERT INTO route (id) VALUES (?)")
			Else
				addRouteQuery.clearBindValues()
			End If
					
			sqlAddBindInt(addRouteQuery, id)
		
			addRouteQuery.execute()
							
		End If
		
	End Function


The query is prepared once, and reused after that. (this example is actually running on MySQL, but it doesn't matter, it would be the same for SQLite too)


Anyways, I'll be updating BaH.Database soon with some more helper methods, that let you do :

Local name:String = record.getStringByName("surname")

Which is a bit less coding.