Converting mysql to SQLite

Trevor DeVore lists at mangomultimedia.com
Tue Apr 19 11:48:58 EDT 2005


On Apr 18, 2005, at 7:27 AM, Stephen Barncard wrote:

> Trevor, thanks again for your DB library. It is very useful and 
> motivational.. and example of great coding...

You are welcome and thanks for the complement.

> Will the new library be backwards compatible? Should all I have to do 
> would be to change the lib name in the code?

Right now most of the calls are backwards compatible except for 
libdb_updateTable.  The order of the array that has the update values 
and the array that has the search values has been swapped so that it 
matches libdb_addToTable and the order of the statements in a SQL 
statement.

The major change will be how error handling is done.  Now most of the 
functions and commands throw errors rather than returning false, etc.  
I grew tired of constantly writing:

put libdb_getTableRow("mydb", tSQL) into tDataA
if tDataA = false then
	--> ALERT AND LOG ERROR
else
	--> display to user
end if

put libdb_getTableRows("mydb", tSQL) into tDataA
if tDataA = false then
	--> ALERT AND LOG ERROR
else
	repeat with i = 1 to tDataA["Length"]
		--> CREATE LIST FOR USER
	end repeat
end if

especially when making multiple db calls in a single handler.

Now you do something like this:

try
	put libdb_getTableRow("mydb", tSQL) into tDataA
	--> display to user
	
	put libdb_getTableRows("mydb", tSQL) into tDataA
	repeat with i = 1 to tDataA["Length"]
		--> CREATE LIST FOR USER
	end repeat
	
catch e
	if item 1 of e = "libdberr" then
		--> ALERT AND LOG ERROR
	end if
end try

Most of the other changes will be transparent to you.  I now use 
binding so that libdb supports binary data with the "*b" prefix before 
a field name in an array.  I've added a setting that will run macToISO 
and isoToMac transparently for you on Mac (so all values are stored in 
iso format in the db) so that you don't have high ascii characters 
displaying funny on different platforms when fetched from the database.

I'm in the middle of adding the code to do sql dumps.  This will allow 
you to create sql backups of your database without any additional 
utilities or to create SQLite or Valentina databases from a MySQL, 
Postgresql, etc. database.


-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com



More information about the use-livecode mailing list