Main

Forums

Wiki

Downloads

Tutorials

Walkthrough

Unreal-netiquette

Links

Submit-News

Oldunreal's hosted:
UnrealReference

Usermaps

Real-CTF

Donate for Oldunreal:

Oldunreal Donation
Oldunreallogo
  Welcome, Guest. Please Login or Register
 
  HomeHelpSearchLoginRegister  
 
 
USQLite [Not yet released, pending testing] (Read 420 times)
[]KAOS[]Casey
Oldunreal MasterPoster
******
Offline


nedm

Posts: 2892
Gender: male
USQLite [Not yet released, pending testing]
07/01/12 at 05:42:00
 
So I finally got off my ass and made an SQLite database interface for Unreal.

Currently it uses name lookups instead of ID lookups, but I could add ID lookups in case extra speed is needed because the test function as shown below is pretty.. well.. slow. It freezes my unreal for about 1/4th a second or so.

Any suggestions? I still need to test the hell out of it since I just now got it working without any sort of consistent crashing, but I haven't tested literally every single function in depth; only what you see in the test code.


Interface code is as follows(including test poop)

Code:
//============================================================================
// Holy shitballs! it's a SQLite3 Class for unreal!!!!!!!!
// Do you love local databases? I crappity smackING DO, NO SQL INSTALLATION REQUIRED
// v1.0 by []KAOS[]Casey using a wrapper I had to fix called easySQLite
// crappity smack google code
//==============================================================================
class USQLiteDB extends Object
native;

var native const editconst int InternalTableList;//If you touch these I hope you like crashes.
var native const editconst int InternalRecordList;
var native const editconst int InternalDB;
var native const editconst int InternalDBName; //yeah thats right,4 different ways to cause crashes. Don't be a dumbass.


native final function SetupDatabase(string Filename);//filename eg test.db
native final function CloseDatabase();//cleanup!


//sqlite3 syntax   : CREATE TABLE person (_ID INTEGER PRIMARY KEY, fname TEXT NOT NULL, lname TEXT NOT NULL, birthdate INTEGER)
//USQLiteDB syntax : AddTable("person","_ID INTEGER PRIMARY KEY, fname TEXT NOT NULL, lname TEXT NOT NULL, birthdate INTEGER");
native final function AddTable(String TableName, String TableDefinition);
native final function RemoveTable(String TableName);


native final function bool PushRecord(String Table);//Adds one new record.

native final function PullRecord(String Table,optional string WhereCondition);
//PullRecord("person"); would grab the all entries from the person table
//PullRecord("person","_ID >= 10 and _ID <= 15"); would grab entries 10-15.

native final function UpdateRecord(String Table, optional string WhereCondition);
//UpdateRecord("person","_ID = 1") would update only primary key ID of 1
//UpdateRecord("person") would update all records

//SetStringToRecord("person","fname","John");
//SetStringToRecord("person","lname","Smith"); //would set Record to first name of John, last name of Smith

native final function bool SetNullToRecord(string Table, string FieldName); //don't ask. I just put it here. crappity smack you.
native final function bool SetStringToRecord(string Table, string FieldName,  string Value);
native final function bool SetIntegerToRecord(string Table, string FieldName, int Value);
native final function bool SetFloatToRecord(string Table, string FieldName,   float Value);
native final function bool SetBoolToRecord(string Table, string FieldName,    bool Value);
native final function bool SetTimeToRecord(string Table, string FieldName,    int Value);//time since 1970


native final function int GetNumRecords(String Table); //returns num records from query used by PullRecord/UpdateRecord
native final function int GetSQLTime(); //returns time since 1970.. unix time is weird. really weird.


native final function string 	GetStringFromRecord(string Table, int RecordNum, string FieldName);
native final function int 		GetIntegerFromRecord(string Table, int RecordNum, string FieldName);
native final function float 	GetFloatFromRecord(string Table, int RecordNum, string FieldName);
native final function bool 		GetBoolFromRecord(string Table, int RecordNum, string FieldName);
native final function int 		GetTimeFromRecord(string Table, int RecordNum, string FieldName);


//code I used for testing
/*
function PostBeginPlay()
{
	local USQLiteDB DB;
	local int i, max;
	local string S;
	DB = new (Outer) class'USQLiteDB';
	DB.SetupDatabase("test.db");

	SetupTestTable(DB,"person");
	SetupTestTable(DB,"person2");
	DB.PullRecord("person");
	DB.PullRecord("person2");
	log("printing person table");
	PrintTestDB(DB,"person");//should print
	log("printing person2 table");
	PrintTestDB(DB,"person2");//should print


	DB.RemoveTable("person");//crappity smack it over!!!!!!!!!
	log("printing person table after deleting");
	PrintTestDB(DB,"person");//should NOT print
	log("printing person2 table after deleting one");
	PrintTestDB(DB,"person2");//should print

	DB.RemoveTable("person2");//keep it as a controlled test!
	DB.CloseDatabase();//clean this poop up yo, seriously crappity smacking do this
}

function SetupTestTable(USQLiteDB DB, string TableName)
{
	DB.AddTable(TableName,"_ID INTEGER PRIMARY KEY, fname TEXT NOT NULL, lname TEXT NOT NULL, birthdate INTEGER");
	DB.SetStringToRecord(TableName,"fname","jvb");
	DB.SetStringToRecord(TableName,"lname","&ht");
	DB.SetTimeToRecord(TableName,"birthdate",5);
	log("Setting up table "$TableName);
	DB.PushRecord(TableName);
	DB.PushRecord(TableName);
	DB.PushRecord(TableName);
	DB.PushRecord(TableName);
	DB.PushRecord(TableName);
	DB.PullRecord(TableName);

	DB.SetStringToRecord(TableName,"fname","crappity smack");
	DB.SetStringToRecord(TableName,"lname","226f");
	DB.SetTimeToRecord(TableName,"birthdate",DB.GetSQLTime());
	DB.UpdateRecord(TableName,"_ID > 3");

}

function PrintTestDB(USQLiteDB DB,string TableName)
{
	local int i, max;
	max = DB.GetNumRecords(TableName);
	for(i=0; i<max; i++)
	{
		log("Entry # "$i);
		log("FirstName = "$ DB.GetStringFromRecord(TableName,i,"fname"));
		log("Last Name = " $DB.GetStringFromRecord(TableName,i,"lname"));
		log("Birthday = "  $DB.GetTimeFromRecord(TableName,i,"birthdate"));
	}
}

*/ 



And the log output:

Code:
ScriptLog: Setting up table person
ScriptLog: Setting up table person2
ScriptLog: printing person table
ScriptLog: Entry # 0
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 1
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 2
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 3
ScriptLog: FirstName = crappity smack
ScriptLog: Last Name = 226f
ScriptLog: Birthday = 1341117682
ScriptLog: Entry # 4
ScriptLog: FirstName = crappity smack
ScriptLog: Last Name = 226f
ScriptLog: Birthday = 1341117682
ScriptLog: printing person2 table
ScriptLog: Entry # 0
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 1
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 2
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 3
ScriptLog: FirstName = crappity smack
ScriptLog: Last Name = 226f
ScriptLog: Birthday = 1341117683
ScriptLog: Entry # 4
ScriptLog: FirstName = crappity smack
ScriptLog: Last Name = 226f
ScriptLog: Birthday = 1341117683
ScriptLog: printing person table after deleting
ScriptLog: printing person2 table after deleting one
ScriptLog: Entry # 0
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 1
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 2
ScriptLog: FirstName = jvb
ScriptLog: Last Name = &ht
ScriptLog: Birthday = 5
ScriptLog: Entry # 3
ScriptLog: FirstName = crappity smack
ScriptLog: Last Name = 226f
ScriptLog: Birthday = 1341117683
ScriptLog: Entry # 4
ScriptLog: FirstName = crappity smack
ScriptLog: Last Name = 226f
ScriptLog: Birthday = 1341117683 


Back to top
 
 
IP Logged
 
Smirftsch
YaBB Administrator
******
Offline



Posts: 5482
at home
Gender: male
Re: USQLite [Not yet released, pending testing]
Reply #1 - 07/01/12 at 11:32:26
 
the possibilities a database offers are almost endless. Could make real RPG's maybe with it Smiley
Back to top
 

Sometimes you have to lose a fight to win the war.
WWW WWW Smirftsch 52832995  
IP Logged
 
Bleeder91[NL]
God Member
*****
Offline


Personal Text:

Posts: 780
Location, Location, Location.
Gender: male
Re: USQLite [Not yet released, pending testing]
Reply #2 - 07/01/12 at 13:39:47
 
I would give it a try. Tongue
Back to top
 
WWW WWW Bleeder91[NL]  
IP Logged
 
DocHoliday
YaBB Newbies
*
Offline


Oldunreal member

Posts: 10
Gender: male
Re: USQLite [Not yet released, pending testing]
Reply #3 - 07/01/12 at 20:43:14
 
What is it used for??? Saving data like player health and stuff?
Back to top
 
 
IP Logged
 
(Moderators: Smirftsch, TCP_Wolf, pÍtßûll, DieHard SCWS)