ELENESSKI GAMES
  • Home
  • Games
    • Worzzler
    • The Lost Tribes
  • Unity
    • Facade Generator for Archimatix
    • Elenesski Object Database
    • Generic Move Camera
    • Unity C# Library
  • SQLINQ
    • Change Log
    • Concepts >
      • Overview
      • The Patterns
      • Database & Factories
      • Working with Tables
      • Custom Queries
      • Lazy Loading
      • Units of Work
    • Video Tutorials
    • Getting Started
    • Code Examples >
      • Implementing Behavior
      • Finding Objects
      • Custom Searches
      • Converters and Transformers
      • Object Association Management
      • New Objects
      • Creating Database
      • Associating Objects
      • Deleting Objects
      • Validating Objects
      • Saving
    • Sample Model >
      • Tutorial Model
      • Table Classes Code
      • Domain Classes Code
      • Factories Code
    • OSX Developers
    • Bridge Building
    • External Websites
    • Class Documentation
  • Presentations
    • 3D Ship Design
  • Music
    • Jamendo (Main)
    • Blend
    • Sound Cloud
    • Mixcloud (DJ)
    • DJ Demos
  • YouTube

SQLINQ - Getting started

This section assumes you have gone through the majority of the tutorial videos and want to see how difficult it is to create code.   The entire idea behind SQLINQ is the ability to quickly go from a model to code with few steps in the middle.  Assuming your model has all the right features, or the Bridge you are using is well written, you should be able to straight to coding once the code is generated.

All the pre-written and generated classes are designed to hide away the complexities of dealing with SQLite.  There are a few things you have to do to read data and/or write data.

Setting the 32-bit vs. 64-bit SQLITE DLL

Both Windows and OSX use the same Dynamic Link Library (DLL).  The versions are acquired here:
  1. 32-Bit: http://sqlite.org/download.html     (Look for the "32-bit DLL (x86) for SQLite verison 3.8.8.3" link)
  2. 64-Bit: http://blog.synopse.info/post/2013/03/23/Latest-version-of-sqlite3.dll-for-Windows-64-bit

Both versions are included in the plugins folder, but in case you need to upgrade, this the original sourced locations. 


Important Note: If you are using a 32-bit or 64-bit SQLite version, you must set a  compiler flag in player settings. 
These Compiler Flags tells SQLINQ which version of SQLite to bind to and correspondingly which library it will use:
  1. Use SQLINQ32 to use the 32-bit version of SQLite
  2. Use SQLINQ64 to use the 64-bit version of SQLite (the image below shows the setting of the 64-bit compiler flag)
Picture

Factory Initialize

Factory.Initialize();

This class and static method is generated by SQLINQ and it's purpose is to initialize the repository with information about how to transform rows coming out of a database into the objects represented by your class model. 

This method is only required if you are reading from SQLite, and must be called before your first object is read.  It often appears in an "Awake()" method, and it's smart, in that if you accidentally call the method more than once, it exits on the subsequent tries.

Note: It's not required if you are only writing objects to the database.

initialize repository

Repository.InitializeRepository("filename");

This method is required to identify the physical file on the end-users hard-drive.  SQLite has no association to a specific file extension (Windows), it simply uses the file as a place to put it's database. 

SQLite's database is fully self-contained within this file.  That means it makes it possible to create temporary copies of the database so that a game could read/write out of the copy and then the game could write it back to it's main location with a game save.  SQLINQ doesn't normally keep a file open when writing to the database, so it's possible to copy the file using .Net's File.Copy() method to "save" the database.

The only difference between OSX and Windows users is the filename; otherwise the system is functionally identical.

factory make database

Factory.MakeDatabase();

You call this method whenever you are creating a database for the first time.  It constructs the tables and indexes in an ordered fashion.  If you modify the underlying classes SQLINQ will retrofit the database to fit the new data structure, but won't remove columns you removed from your definitions.  You can create individual tables by calling Table.CreateTable() directly.

You will have to write your own code to retrofit existing tables with new tables yourself, which includes the manual removal of data. 

Suggested tools

Once you have your data, you may want to look at the database or edit the data.  See the External Websites page for suggested (free) tools.