Database

Even if you just want to develop a simple game, often you'll need a database too. Maybe just some table with few rows but your work will be much more simple with a standard database, instead of text files or anything else. After some search, I decided to use SQLite.

Research


My primary goals were find a simple, easy-to-use, standard, file-based SQL solution. That wasn't easy task, I tried some another database but always I had some problem (overhead: too complex and big database for my needs, not so friendly commands or not-SQL logic etc). But finally I've found SQLite and because it has .NET wrapper too and after short time I was able to begin the real work, I didn't search any longer.

Coding

Really I had not too much work. Just installed the package, import dll's and I wrote some kind of wrapper to use very simple commands. I don't like to write 3-4 lines for one SQL command. Now you can use with my SQL class in this way:

SQL db = new SQL("sample.db"); //init a database from sample.db file or create if doesn't exists
db.CreateTable("table007","ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, NAME VARCHAR(20), DATE DATE"); //create table with its name and with fields, just like in any SQL
db.Insert("table007","1,\"B\",\"2011-01-20\""); //insert a sample row with a simple command. You should use escape character before " signs in the field list
db.Update("table007","NAME=\"MODIFIED\"","NAME LIKE \"B%\""); // names which begins with B will be renamed to "MODIFIED"
db.Delete("table007","ID=1"); //delete rows from table007 where ID=1


You see some example here, how can you use SQL with these simplified commands. Now I'll show you, how can you display some data from tables.

DataTable dt = db.Select(); //create datatable from db's last used table -table007 in this case, without arguments this is a SELECT *
Table t = new Table(dt.Columns.Count,dt.Rows.Count,12,2,dt); //create table object with size of dt and from dt's data

t.draw(); //draw the dt's data to the top left corner of the screen


Formatted table example from SQLite db datas


You can make simple databases with SQLite Database Browser. Here you can import your MS Excel / MS Access / LibreOffice Calc datas if they are in common format like .csv (save as in Calc / Excel / Access).

Current database features
  • easy import from .csv or DataTable object to drawable character table
  • good performance and simple solution with SQLite
  • easy commands with SQLite wrapper (commands in SQL object with various argument list: createTable, dropTable, Select, Update, Delete, Insert)
  • easy to display data
  • customizable graphics (line shortening, simple- and double border, flexible size and custom colors supported)
  • without name of table commands will run on the last used table

Tasks
  • tests (performance and bug-finder)
State: under development

Nincsenek megjegyzések:

Megjegyzés küldése