
PDatabase.DatabaseFile = f.Child("EddiesElectronics.sqlite") Var f As FolderItem = xojo.io.SpecialFolder.Documents Source.CopyTo(xojo.io.SpecialFolder.documents) If Not xojo.io.("EddiesElectronics.sqlite").Exists Then if not, we copy the database file from Resources bundle/directory We check if there is our database file already copied on the Documents Sandbox folder
#SQLITE STORED PROCEDURES XOJO CODE#
PDatabase.DatabaseFile = (name).Child("EddiesElectronics.sqlite")įor an iOS app, the code would be: Var source As Xojo.IO.FolderItem = xojo.io.SpecialFolder.GetResource("EddiesElectronics.sqlite") Create a SQLiteDatabase instance and try to open our database file from If Not (name).child(source).exists Then source.CopyTo((name)) If Not ((name).Exists And (name).IsFolder) Then (name).CreateFolder if not, we create it and copy the database file from Resources bundle/directory We check if there is a folder with the App name in special Application Data The Application Support folder is a good place for Desktop apps, while the Documents folder is fine for Xojo Cloud and iOS apps.įor example, if our database file is named “EddiesElectronics.sqlite” and our app name is “Xojotest”, then we can add the following code fragment into the Open Event Handler of a Desktop app: Var source As FolderItem = SpecialFolder.Resource("EddiesElectronics.sqlite") The best thing to do is o detect every time you run the app if the database file has already been copied from the app bundle (or folder) into a target folder that doesn’t have an access problem when it is time to use the database. They are many reasons you shouldn’t do that, specifically because the database would be open in read/write mode and if you write to that database file inside an application bundle, then you’ll be modifying a resource that would invalidate any certificate signature on your app. You may think that the previous step is all you need to do, because if the database file is already copied in a well know path then you only need to provide that path as the DatabaseFile property on a new SQLiteDatabase or iOSSQLiteDatabase instance. Copying the database file to a “Working” folder On iOS, the only change is that you’ll have to choose the icon with an iPhone picture in it in order to access the Build Step contextual menu in addition to the fact that every added resource needs to be signed with a certificate.Ģ. When you’re working with a Web project, you’ll find exactly the same behavior, even if you choose to deploy with Xojo Cloud.

Of course, don’t forget to add the database file itself using the buttons on the Build Editor toolbar. For example, a good Destination option would be “Resources Folder”. In fact, the Destination menu contains a number of typical paths (or most relevant folders). The previous action will give you access to the Inspector Panel for the just-added item where you will be able to type a name for the Build Step, choose if the copy file action will be executed both for debugging or deployment and, most importantly, choose the location where the file should be copied when the app compiles. In order to add a new Build Step in a Desktop project select the target in the Build Settings then, from the contextual menu, choose the “Add to Build Settings > Build Step > Copy Files” option. Bonus: Doing this allows you to decide to use different paths when debugging or deploying your app. This way, the file will be added automatically to the folder of your choice every time you compile your app. You can do that in several ways, but usually it’s best to add a Build Step. You probably created your SQLite database file using an external editor so first add that file to your Xojo project.
#SQLITE STORED PROCEDURES XOJO HOW TO#
This tutorial will show you how to deploy your SQLite based projects so they behave right on Desktop, Web and iOS, copying the database file to the right place on every target.
