Thread: SQLite
View Single Post
  #30  
Old 04-12-2009, 08:20 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 Stefan View Post
The database is databases/main.db
Use "as" for renaming columns of the result. You can also access the result as array, like rows[][]
Ah good, thanks.

Could you perhaps make a function for converting arrays into a format suitable for SQL statements? Basically making it into a large string, using single quotes around strings, and escaping the single quotes in the string. I figure that would be better if not done by script.

And, I'd also like a server option for reporting SQLite errors and such on RC.

This is the equivalent script:
PHP Code:
public function sqlarray(array) {
  
temp.out "";
  
temp.sz = array.size();
  
  if (
temp.sz 1)
    return 
"";
  if (
temp.array[0].type() == 0)
    
temp.out @= temp.array[0];
  else
    
temp.out @= this.sqlescape(temp.array[0]);
  for (
temp.1temp.temp.array.size(); temp.++) {
    if (
temp.array[i].type() == 0)
      
temp.out @= "," temp.array[i];
    else
      
temp.out @= "," this.sqlescape(temp.array[i]);
  }
  return 
temp.out;
}
public function 
sqlescape(rstr) {
  
temp.temp.rstr.positions("'");
  if (
temp.p.size() > 0)
    for (
temp.temp.p.size() - 1temp.> -1temp.--)
      
temp.rstr replacesubstring(temp.rstrtemp.p[temp.e], 1"''");
  return 
"'" temp.rstr "'";
}
// replacesubstring from util_string
public function replacesubstring(stringpositionlengthnewstring) {
  if (
temp.position 0) {
    return;
  }
  return 
temp.string.substring(0temp.position) @
         
temp.newstring @
         
temp.string.substring(temp.position temp.length, -1);

__________________

Last edited by Inverness; 04-12-2009 at 09:33 AM..
Reply With Quote