Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #31  
Old 04-12-2009, 03:07 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Well for errors I gave the suggestion to write a wrapper function:

PHP Code:
function getsql(query) {
  
temp.req requestsql(query,true);
  if (!
temp.req.completed && !waitfor(temp.req,"onReceiveData",60))
    return 
NULL;
  if (
temp.req.error!="")
    echo(
temp.req.error);
  return 
temp.req;

For escaping use the string.escape() function.
Reply With Quote
  #32  
Old 04-12-2009, 04:11 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Stefan View Post
For escaping use the string.escape() function.
I don't believe that is the same thing as what I'm talking about. For example, if a have a graal string "It's alive!" and I want to stick it in as a string value in an SQL statement string then it needs to be changed to "'It''s alive!'". the SQL strings have the single quotes around them plus any single quotes inside the string need to have a second single quote after it to be escaped.

Also, I don't think you specified what the boolean value was for in requestsql() and requestsql2().
__________________
Reply With Quote
  #33  
Old 04-12-2009, 06:16 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Inverness View Post
Also, I don't think you specified what the boolean value was for in requestsql() and requestsql2().
It's in /scripthelp now:
Quote:
requestsql(str, bool) - returns object - executes a sql query for the default database, parameters are the query string and if you expect a result (e.g. from a select-query); the result is an event object, call waitfor(requestobj,"onReceiveData",60) and then use requestobj.rows, error and lastinsertid

requestsql2(str, str, bool) - returns object - like requestSQL(), but allows you to select the database, parameters are database identifier, query, expect result (true/false)
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #34  
Old 04-12-2009, 06:31 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Is there a way to create 'sub-tables'? It's been a while since I've using any SQL, and the one I did use was MySQL.

What I'm trying to do is create a sub-table of 'shops' to store item data.
PHP Code:
  sql.execute(
    
"CREATE TABLE IF NOT EXISTS shops ("
    
"title TEXT NOT NULL DEFAULT 'Shop', "
    
"stype TEXT NOT NULL DEFAULT 'Server', "
    
"owner TEXT NOT NULL DEFAULT 'Unknown', "
    
"kerou INT NOT NULL DEFAULT 5000, "
    
"desc TEXT NOT NULL DEFAULT 'Description text.', "
    
"createtime INT NOT NULL DEFAULT CURRENT_TIMESTAMP)"false);
  
sql.execute (
    
"CREATE TABLE IF NOT EXISTS shops.items ("
    
"arch TEXT NOT NULL DEFAULT 'Unknown', "
    
"price INT DEFAULT 0, "
    
"stock INT DEFAULT 0)"false); 
However, I get the following error:
Quote:
SQL Error: unknown database shops
Query: CREATE TABLE IF NOT EXISTS shops.items (arch TEXT NOT NULL DEFAULT 'Unknown', price INT DEFAULT 0, stock INT DEFAULT 0)
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #35  
Old 04-12-2009, 08:30 PM
Damix2 Damix2 is offline
RED SQUARE CLUB
Join Date: Nov 2003
Location: NY-what's better?
Posts: 3,577
Damix2 will become famous soon enough
Just in general a 'sub-table' in a ERD is just 2 tables in a parent-child relationship. The child will always hold the foreign key to point towards the parent, not entirely sure why you are getting an error.

Sorry, my help was fairly useless.
__________________
Reply With Quote
  #36  
Old 04-12-2009, 09:44 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Inverness, string.escape() is made for that. It escapes ' and \ according to the SQL standard / pascal.
Reply With Quote
  #37  
Old 04-13-2009, 02:10 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Damix2 View Post
Just in general a 'sub-table' in a ERD is just 2 tables in a parent-child relationship. The child will always hold the foreign key to point towards the parent, not entirely sure why you are getting an error.

Sorry, my help was fairly useless.
Does the following link give any valuable information?

http://sqlite.org/omitted.html

More specifically, this bit on foreign-key constraints:
Quote:
FOREIGN KEY constraints are parsed but are not enforced. However, the equivalent constraint enforcement can be achieved using triggers. The SQLite source tree contains source code and documentation for a C program that will read an SQLite database, analyze the foreign key constraints, and generate appropriate triggers automatically.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #38  
Old 04-13-2009, 02:51 AM
Damix2 Damix2 is offline
RED SQUARE CLUB
Join Date: Nov 2003
Location: NY-what's better?
Posts: 3,577
Damix2 will become famous soon enough
Quote:
Originally Posted by LoneAngelIbesu View Post
Does the following link give any valuable information?

http://sqlite.org/omitted.html

More specifically, this bit on foreign-key constraints:
As for your error? No, not really, at least not that I can see. The fact that SQLite doesn't support referential integrity is surprising I'd say. Also no outer joins (granted, that can be accomplished in other ways.)
__________________
Reply With Quote
  #39  
Old 04-13-2009, 03:10 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Damix2 View Post
As for your error? No, not really, at least not that I can see. The fact that SQLite doesn't support referential integrity is surprising I'd say. Also no outer joins (granted, that can be accomplished in other ways.)
Using requestsql2() pointing to the "sqlite_master" database results in no error. However, when trying to access the data, nothing is outputted.
PHP Code:
  sql.execute(
    
"CREATE TABLE IF NOT EXISTS shops ("
    
"title TEXT NOT NULL DEFAULT 'Shop', "
    
"stype TEXT NOT NULL DEFAULT 'Server', "
    
"owner TEXT NOT NULL DEFAULT 'Unknown', "
    
"kerou INT NOT NULL DEFAULT 5000, "
    
"desc TEXT NOT NULL DEFAULT 'Description text.', "
    
"createtime INT NOT NULL DEFAULT CURRENT_TIMESTAMP)"false);
  
requestsql2("sqlite_master",
    
"CREATE TABLE IF NOT EXISTS shops.items ("
    
"arch TEXT NOT NULL DEFAULT 'Unknown', "
    
"price INT DEFAULT 0, "
    
"stock INT DEFAULT 0)"false);
  
sql.execute(format(
    
"INSERT INTO shops VALUES('%s','%s','%s',%s,'%s',%s)",
    
"Test Shop""Server""NPCServer"5000"Description text.""CURRENT_TIMESTAMP"), false);
  
requestsql2("sqlite_master",
    
"INSERT INTO shops.items VALUES('arch1',1000,10)"false);
  
temp.sqltest sql.execute("SELECT * FROM shops WHERE title='Test Shop'"true);
  for(
temp.rowtemp.sqltest.rows) {
    echo(
"Title: " temp.row.title);
    for(
temp.irowtemp.row.items) { //I've also tried temp.row.items.rows
      
echo(temp.irow.arch ": " temp.irow.stock);
    }
  } 
The execute() command is a simple error checker:
PHP Code:
public function execute(queryisreq) {
  
temp.req requestsql(temp.querytemp.isreq);
  if (
temp.req.error != "") {
    echo(
"SQL Error: " temp.req.error);
    echo(
"      Query: " temp.query);
  }
  if (
temp.isreq && !temp.req.completed &&
      !
waitfor(temp.req"onReceiveData"5))
    return 
null;
  return 
temp.req;

__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #40  
Old 04-13-2009, 07:22 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by LoneAngelIbesu View Post
Using requestsql2() pointing to the "sqlite_master" database results in no error.
sqlite_master is a table not a database. Stefan said in an earlier post that requestsql2() is for choosing between mysql and sqlite databases, so at the moment it is useless to you and you shouldn't use it.

select tbl_name from sqlite_master where type='table' order by tbl_name

That would list all tables in the SQLite database.
__________________
Reply With Quote
  #41  
Old 04-13-2009, 12:43 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Using requestsql2 with an unconfigured database will result in silence, may be can set the error variable. For the future it could be possible to configure additional databases in the server options but right now it's not possible.
Reply With Quote
  #42  
Old 04-13-2009, 05:45 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Inverness View Post
Stefan said in an earlier post that requestsql2() is for choosing between mysql and sqlite databases, so at the moment it is useless to you and you shouldn't use it.
The /scripthelp entry should be updated as such, then.

As good as all of this information is, none of it helps with my original question of how to create 'sub-tables'. Just a light reminder...
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #43  
Old 04-14-2009, 12:56 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
The requestsql2 information is correct, it lets you select the (configured) database. Right now you cannot configure databases, so there is only "default".
Reply With Quote
  #44  
Old 04-14-2009, 01:38 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by LoneAngelIbesu View Post
As good as all of this information is, none of it helps with my original question of how to create 'sub-tables'. Just a light reminder...
No such thing as sub-tables in this case. The syntax you're thinking of is for creating a table in a database other than the default, which is useless in this case since there is only one database. Just create a normal table.
__________________

Last edited by Inverness; 04-14-2009 at 03:10 PM..
Reply With Quote
  #45  
Old 04-14-2009, 03:10 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
I tried using string.escape() as you suggested, but like I thought, it escaped single quotes using a backslash which is incorrect, you're supposed to escape single quotes using another single quote.

I also suggest adding "parameterized queries." Which is basically when question marks in the query are replaced by function parameters to protect against SQL injection and stuff. Example:

executesql("INSERT INTO options VALUES (?,?)", {"profit", 9001});
__________________

Last edited by Inverness; 04-14-2009 at 05:54 PM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.