
Cocoa sqlite tutorial mods#
Set d1 to "insert into mods values('Ray', 'Barber', 'USA') " Now we set up the data to be entered in the table Set newTbl to "drop table " & tableName & " create table " & tableName & "(firstname, lastname, country) " Note the space between the semicolon (which ends every line) and the quote. Next, we set up a table and give the columns labels (there can be several). "tail" ends every query started with "head". "head" is the opening statement of every future command to our db. "head" tells SQLite where to put our db if it doesn't exist, identifies it if it does. (I’ve modified the first slightly to avoid problems running it repeatedly.) Here’s the first script using the do shell script method: set loc to space & "~/desktop/TestDB.db" & space If that’s you, please email me.Īs a taster, here are two scripts borrowed from Adam Bell’s Introduction to SQLite3 tutorial, one to build a database and another to read it. It’s still at the early testing stage, and I’m looking for interested volunteers. It won’t work under versions earlier than 10.10 at this stage.

You need at least a basic understanding of AppleScriptObjC syntax to use it. I may wrap it in a library at some stage. You need to add the framework to your system. Lower overhead than shell, and combined with transactions this means there’s less need to build long statements to perform things like multiple insertions. You can batch updates together for greater efficiency. And because arrays are returned as a simple pointer, large result sets are returned much, much quicker. You can coerce them to AppleScript lists (a simple “ as list”), but in the case of large results it’s often quicker to deal with the raw arrays. Query results are returned initially as Cocoa arrays. Query results are returned in either arrays/lists or dictionaries/records for each row, so there’s no need to massage a string to extract the results. You can handle classes such as dates and images much more easily. It’s main advantages are:Įasy use of SQL ? placeholders, so you can optionally pass parameters as lists containing differing classes. Initial tests show it’s faster – in some cases considerably so. This is the FMDB framework wrapped in a more AppleScript-friendly face (but maintaining access to the more advanced stuff for those who need it). Unfortunately some of it is lower level and more complicated than would be ideal for AppleScript. There is a third-party framework, FMDB, that puts an Objective-C wrapper around SQLite, so it can be called from AppleScriptObjC. And while it’s not slow, it could be faster.

This is especially the case where there are a lot of results.

So you can end up doing a lot of text manipulation just to get stuff in and out.

The biggest issue is that everything is reduced to text. It’s quite usable from AppleScript via the command line tool sqlite3 and do shell script, but it seems to me that this approach has several drawbacks from AppleScript. In c++ already solved the problem Use database (such as sqlite) with cocos2d-xīut I want to use it with below javascript, which is the default script in Cocos creator cc.I’ve been playing with SQLite lately. I can't find any tutorial on official cocos creator site or forums. I want to use a local database file such as question database for my quiz game.
