On a lighter note, I coded for about 17minutes before my Kids dragged me away fighting and balling there eyes out. Those 17 minutes felt like heaven.
This forum is now archived!
- Welcome to the archive!
News:
The 3DRad community can be found at classdev.net.
- 3D Rad - Free 3D game maker - Forum >
- General Category >
- 3D Rad - User-created Sample Projects, Scripts, Tutorials >
- RadSqLite Released.
Author Topic: RadSqLite Released. (Read 9505 times)
jestermon
RadSqLite V2 update
A new function has been added to remove the need of using your own dynamic arrays. extractDB() extracts the string returned from the dll query and places it into a global string array, that in now managed by the functions.
The manual has been updated, and RadSqLite2.3dr now replaces RadSqLite.3dr
Example of use
A new function has been added to remove the need of using your own dynamic arrays. extractDB() extracts the string returned from the dll query and places it into a global string array, that in now managed by the functions.
The manual has been updated, and RadSqLite2.3dr now replaces RadSqLite.3dr
Example of use
Code: [Select]
setDatabase(�mytest.db�); //set name of database file to use
sql = �create table test2 (name text, score number);�; //create a table
doSql(); //do the call
sql = �insert into test2 (name,score) values ('joe',12);�; //insert some data
doSql(); //do the call
sql = �insert into test2 (name,score) values ('peter',31);�; //insert more data
doSql(); //do the call
sql = �select * from test2 where score > 30;�; //get high scores
doSql(); //do the call
int count = getRecordcount(); //get number of records
getRecord(0); //first record is always 0, max is getRecordcount()-1
extractDB() //split the database results into the sqlData array
string playername = sqlData[0]; //get the player info from sqlData
int score = iStringVal(sqlData[1]); //get the score info from sqlData
jestermon
RadSqLite update 1
A extra utility function has been added.
void setRecord(int record, string data) � Non database utility function
This is a special function that has nothing to do with the database itself. Because the dll provides storage space for 1024 strings of 1024 characters long, it makes an ideal storage medium fo passing strings between 3D Rad scripts. You can use this function to store a string in any of the 1024 (0 � 1023) slots, eg. setRecord(123,�Text�); and then by using mystring = getRecord(123); to retrieve this data from any script that uses this dll.
Special note: Sql queries overwrites the slots in this array with data retrieved from the database for the number of records retreived.
If you use for example setRecord(900,"Player1: Jimmy Zoom"); and you do a query afterwards that only retrieves 100 records, all records after 100 will be untouched, including the '900' used above. Use the getRecordcount() to determine the number of records retrieved by a query.
.3dr, dll and manual updated.
A extra utility function has been added.
void setRecord(int record, string data) � Non database utility function
This is a special function that has nothing to do with the database itself. Because the dll provides storage space for 1024 strings of 1024 characters long, it makes an ideal storage medium fo passing strings between 3D Rad scripts. You can use this function to store a string in any of the 1024 (0 � 1023) slots, eg. setRecord(123,�Text�); and then by using mystring = getRecord(123); to retrieve this data from any script that uses this dll.
Special note: Sql queries overwrites the slots in this array with data retrieved from the database for the number of records retreived.
If you use for example setRecord(900,"Player1: Jimmy Zoom"); and you do a query afterwards that only retrieves 100 records, all records after 100 will be untouched, including the '900' used above. Use the getRecordcount() to determine the number of records retrieved by a query.
.3dr, dll and manual updated.
psikotropico
hi jestermon... i'm playing with SQL and for now I can store values on the database sucesfully, but I'm having problems when try to make a query like this:
I've included the setDatabase() function at iInitializing(), but 3dRad crashes every time it runs the doSql() function... here is the debug log when crash:
select * from PlayerProfile;
dbOpen: moonrats.db
dbOpen: moonrats.db
select * from PlayerProfile;
also, I've noticed that all querys are stored in this log twice... not sure if this is ok...
any idea of what I'm doing wrong?
thanks!
Code: [Select]
void ShowSavedProfiles()
{
string table = "PlayerProfile";
sql = "select * from " + table + ";";
doSql();
}
I've included the setDatabase() function at iInitializing(), but 3dRad crashes every time it runs the doSql() function... here is the debug log when crash:
select * from PlayerProfile;
dbOpen: moonrats.db
dbOpen: moonrats.db
select * from PlayerProfile;
also, I've noticed that all querys are stored in this log twice... not sure if this is ok...
any idea of what I'm doing wrong?
thanks!
jestermon
Hi psikoT , can you zip up a text copy of your project script, and a copy of you database file, let me get a complete picture.
Also use the latest update, it runs a little faster, and has more features.. I'ts going out of beta soon.
Also use the latest update, it runs a little faster, and has more features.. I'ts going out of beta soon.
psikotropico
sure, here you go...
Yes, I'm using the latest update... though it crashes eventually...not sure if it is because I'm using two dlls (ImageMagic and RadSqLite) but not at once... ImageMagic has no DLL...
The script contains about 1500 lines of code so, if you need some explanation, just tell me...
thanks for quick reply!
Yes, I'm using the latest update... though it crashes eventually...
The script contains about 1500 lines of code so, if you need some explanation, just tell me...
thanks for quick reply!
psikotropico
ups!... I can't open the database anymore... it says: qAdmin: Cannot perform this operation on a closed dataset... what the heck..
btw, yesterday I had problems trying to create a database... I was trying with sqliteAdmin, SQLiteBrowser, Navicat... but seems that they are not compatible themselves... the only way to create a good database is from 3drad
Finally I can restore the database... here it is
btw, yesterday I had problems trying to create a database... I was trying with sqliteAdmin, SQLiteBrowser, Navicat... but seems that they are not compatible themselves... the only way to create a good database is from 3drad
Finally I can restore the database... here it is
psikotropico
another question... I can store records on the database, but not sure how to read these records... I've followed the documentation as well the tutorials you've posted... but I think this is too much for my little brain... I'm totally lost in loops and arrays... so I need some guru help
How can I do a list of all records in the database?
thanks in advance
EDIT: almost I get it... but some problems... this is the function I'm using to get all records. It doesn't work because only returns one record:
and here is the code - into void Main() - to print the list. It always print the same record:
what I'm doing wrong?
How can I do a list of all records in the database?
thanks in advance
EDIT: almost I get it... but some problems... this is the function I'm using to get all records. It doesn't work because only returns one record:
Code: [Select]
void ShowSavedProfiles()
{
string table = "PlayerProfile";
sql = "select * from " + table + ";";
doSql();
extractDB();
int count = getRecordcount();
int i;
for(i=0;i<count;i++){
getRecord(i);
int PlayerID = iStringVal(sqlData[0]);
string PlayerName = sqlData[1];
int PlayerMoney = iStringVal(sqlData[2]);
}
}
and here is the code - into void Main() - to print the list. It always print the same record:
Code: [Select]
ShowSavedProfiles();
float nameVlocation = 5.13;
int count, i;
for(i=0;i<count;i++){
getRecord(i);
int PlayerID = iStringVal(sqlData[0]);
string PlayerName = sqlData[1];
int PlayerMoney = iStringVal(sqlData[2]);
nameVlocation -= 1.6;
iPrint(PlayerName,-13.5,nameVlocation,TextPrint);
}
what I'm doing wrong?
jestermon
How can I do a list of all records in the database?
Code: [Select]
for(i=0;i<count;i++){
getRecord(i);
extractDB(); //<---------- YOU FORGOT THIS
int PlayerID = iStringVal(sqlData[0]);
string PlayerName = sqlData[1];
int PlayerMoney = iStringVal(sqlData[2]);
nameVlocation -= 1.6;
iPrint(PlayerName,-13.5,nameVlocation,TextPrint);
}
sequence:
1.. sql="blah blah" //sets query
2.. doSql() //passes query to dll
3.. int count = getRecordcount(); //name says it all
4.. for( i=0;i<count;i++) //
4.1{
5.. getRecord(i) // gets data from dll into sqlResult
6.. extractDB() // <---Extract data from sqlResult to sqlData
7.. whateverdata = sqlData;
7.1.. }
There does sometimes seem to be a problem with NULL (empty) fields, this was the cause of your problem. I've fixed this, testing before upload.
To work with many records in the script, I suggest the following
Code: [Select]
//define a class - is a great structure to hold stuff
class PLAYER //Use CAPITALS for the Class name (easy to remember)
{
int Id;
string Name;
float Money;
}
//define an array to make many PLAYERS
//Use lower case for the array name
PLAYER [] player(30); //30 is the number of entries in the array
//make enough entries to hold your info
//You dont have to use capitals, and lowercase, but it is easy to read.
//The names may be different, but this way the names makes sense to anyone.
//PlayerClassThing [] mySupid_ArrAy(100); is also valid, but makes no sense
//Now you can access the player info like this
//To put stuff in
player[0].Id = 123; //the [0] is the index from 0 to 29
player[0].Name = "Joe"; //Use the index and variable inside the class
player[0].Money = 32.10; //Easy to read and maintain
//to get stuff out
String WinningPlayer = player[12].Name;
if(player[i].Money < 20)
{
//Give bonus
}
//To use in a loop
for(i=0;i<count;i++){
getRecord(i);
extractDB(); //<---- don't forget this
player[i].Id = iStringVal(sqlData[0]);
player[i[.Name = sqlData[1];
player[i].Money = iStringVal(sqlData[2]);
}
//all you code must also have the following
//--------------------------------------- haha
int jID = 22; //My record
for(i=0;i<count;i++){
if(player[i].Name != "jestermon"){
player[jID].Money += player[i].Money;
player[i].Money = 0;
}
}
psikotropico
thanks jestermon, that works fine... also thanks for class explanation... as I can see, it's like an array of arrays, true?... I will try to implement it asap
jestermon
thanks jestermon, that works fine... also thanks for class explanation... as I can see, it's like an array of arrays, true?... I will try to implement it asapThink of a class as a collection, more than an array.. A Box to put a lot of varibles into, but all together under one name. Think of a group of variables that fit together, and you have the idea.
Examples of things that go together in a class:
class FRIEND; name, surname, address, phone, email, facebook
class PLAYER: name, life, score, money, position, location, orientation
class CAR: make, color, topSpeed, startPoint, cost
class BALL; size, location, orientation, color, state(active,inactive)
and so on.
So a class will be a way to make your own complex variable type
As you use int number, or string name, or float money;
So you make a variable based on your class type, eg
FRIEND friend, PLAYER player, BALL ball, etc
The nice thing about this, is now you can access the data types inside your own new compound (consisting of many things together) variable by using a dot "."... myvariable.part examples:
friend.name, player.life, ball.color etc.
It's a great way to keep your program data for each thing together.
Edit: For lessons on arrays, see the chart in the main lecture hall.. haha
jestermon
Update to RadSqLite.dll
This version of the dll fixes a small problem that sometimes occurred when a column from a query was empty.
Now, if the column is empty, the returned data for that column is set to a text value of "NULL"
This version of the dll fixes a small problem that sometimes occurred when a column from a query was empty.
Now, if the column is empty, the returned data for that column is set to a text value of "NULL"
psikotropico
thanks for this class of class... that opens a lot of possibilities... also thanks for update... I've noticed that 3dRad goes a bit unstable even if all records are filled... maybe I'm doing something wrong in my script...
psikotropico
hi jestermon... still working with SQLite...
I'm trying to load one of the 5 records from the database... only one of them are Player_active = 1 so, this is the record I want to load.
Then, I've used this script:
a popup window appears telling "The script crashed at line 281. Reason: Out of range"...
what I'm doing wrong? can you post a simple example on how to load only one record?
thanks in advance!
I'm trying to load one of the 5 records from the database... only one of them are Player_active = 1 so, this is the record I want to load.
Then, I've used this script:
Code: [Select]
void LoadData() {
string table = "PlayerProfile";
sql = "SELECT * from " + table + " WHERE Player_active = '1';"; // 1=active 0=inactive
doSql();
extractDB();
getRecord(PlayerID);
extractDB();
PlayerID = iStringVal(sqlData[0]); // this is the line where the script crashes
PlayerActive = iStringVal(sqlData[1]);
PlayerName = sqlData[2];
PlayerMoney = iStringVal(sqlData[3]);
}
a popup window appears telling "The script crashed at line 281. Reason: Out of range"...
what I'm doing wrong? can you post a simple example on how to load only one record?
thanks in advance!