TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

SQLite Script Help

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
new_to_tin_tin



Joined: 05 Jan 2011
Posts: 36

PostPosted: Thu Jan 19, 2017 8:01 pm    Post subject: SQLite Script Help Reply with quote

Someone was nice enough to give me the SQLite script below on this forum. Works decently, but is a tad slow on my older computer. Although outside of tintin I can access SQLite quick enough through the computer using a PHP Script etc, so not exactly sure where the slowness is coming from.

Maybe it's coming from a new error I'm seeing since I upgraded to version of tintin. Anytime I run a select I get a series of errors like this:
Code:
#REPLACE: VARIABLE {__db[Res][a gypsy peddler|A gypsy peddler eyes you carefully, judging your
worth.|204|45534|caravan|gypsy peddler|false|]} NOT FOUND.


When I debug I get this:
Code:
       if {"${__db[Temp]}" != ""}
[02]                 variable {__dbFormat} {${__dbFormat} {${__db[Temp]}}}
[05]             endif
[05]         endif
[05]     endforeach
[18]     ${__dbFormat}
[02]     unvariable __dbFormat
[02]     nop Call sqlite3 and make actual DB call
[02]     variable __db[Call] {sqlite3 -header /var/lib/myuser/database.sqlite
"${__db[Command]}"}
[02]     script {__db[Res]} {${__db[Call]}}
[02]     nop Replace pipe | field serpeators with semicolons for the #list command
[02]     forall {${__db[Res]}} {#replace __db[Res][&0] {|} {;};}
#REPLACE: VARIABLE {__db[Res][name|long_description|level|room_uid|area_keyword|keywords|not_scannab
le|notes]} NOT FOUND.
#REPLACE: VARIABLE {__db[Res][a gypsy peddler|A gypsy peddler eyes you carefully, judging your
worth.|204|45534|caravan|gypsy peddler|false|]} NOT FOUND.
[02]     nop build array off of __dbRes
[02]     variable __db[Out] {}
[02]     nop Build list of fields off the header
[02]     list __db[fields] create {${__db[Res][1]}}
[02]     list __db[Res] delete 1
[02]     nop Process each returned record
[08]     foreach {__db[recordIdx]}
[02]         list __db[record] create {${__db[Res][${__db[recordIdx]}]}}
[02]         forall {${__db[fields][]}} {#var __db[Out][${__db[recordIdx]}][${__db[fields][&0]}]
{${__db[record][&0]}};}
[05]     endforeach
[02]     nop Save results in the desired var and cleanup local vars
[02]     variable {mob_search_results} {${__db[Out]}}
[02]     unvariable __db
[05] endif
[18] @DisplaySearchResults{$mob_search_results}
display_list is {1}{{area_keyword}{caravan}{keywords}{gypsy peddler}{level}{204}{long_description}{A
gypsy peddler eyes you carefully, judging your worth.}{name}{a gypsy peddler}{not_scannable}{false}{
notes}{}{room_uid}{45534}}
|MS|Mob Name                  |Area Key     |Levl|Room UID|Notes               |
| 1|           a gypsy peddler|      caravan| 204|   45534|     K:gypsy peddler|


And here is the full script that worked before with no errors:
SCRIPT:
Code:


#showme {<aef>Loading: <faa>utility/sql.tt}
/*
  Generic SQLite Database Connector
  Brief Help {{{
  db_submit works the same way as #format
  NB: You must enclose each argument in {}

  _db_submit {returnvar} {db file} {sql expression} [{format-style args}]
       {select * from tablename where fieldname = '%s'} {match text}

  Parses the output and puts it into an associative array:
       $returnvar[recordnumber][fieldname]
   E.G. to get the data from HP field of the first record returned:
       #var {varname} {$returnvar[1][HP]}
   }}}
*/

#alias {std_db_submit} {
   #if {"%0" != ""} {
      #nop generate #format command and execute it;
      #var __dbFormat {#format {__db[Command]} {%3}};
      #var __db[argc] 0;
      #foreach {%0} {__db[Temp]} {
         #math __db[argc] {${__db[argc]} + 1};
         #if {${__db[argc]} > 3} {
            #replace {__db[Temp]} {"} {'};
            #replace {__db[Temp]} {'} {''};
            #if {"${__db[Temp]}" != ""} {
               #var {__dbFormat} {${__dbFormat} {${__db[Temp]}}};
            };
         };
      };
      ${__dbFormat};
      #unvar __dbFormat;

      #nop Call sqlite3 and make actual DB call;
      #var __db[Call] {sqlite3 -header %2 "${__db[Command]}"};
      #script {__db[Res]} {${__db[Call]}};
      #nop Replace pipe | field serpeators with semicolons for the #list command;
      #forall {${__db[Res]}} {
         #replace __db[Res][&0] {|} {;};
      };
      #nop build array off of __dbRes;
      #var __db[Out] {};
      #nop Build list of fields off the header;
      #list __db[fields] create {${__db[Res][1]}};
      #list __db[Res] delete 1;
      #nop Process each returned record;
      #foreach {${__db[Res][]}} {__db[recordIdx]} {
         #list __db[record] create {${__db[Res][${__db[recordIdx]}]}};
         #forall {${__db[fields][]}} {
            #var __db[Out][${__db[recordIdx]}][${__db[fields][&0]}] {${__db[record][&0]}};
         };
      };
      #nop Save results in the desired var and cleanup local vars;
      #var {%1} {${__db[Out]}};
      #unvar __db;
   };
};


It still works and everything, but can't seem to fix the error. And I'm having a hard time understand how that bit of code accomplishes what it is trying to do since I'm not familiar with what "&0" is...

Anyone more familiar with tintin have any ideas?

Hoping maybe this is the cause of the slowness, since trying to find a variable that doesn't exist seems like it would be a costly operation!
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Fri Jan 20, 2017 1:43 pm    Post subject: Reply with quote

What version did you used before ?

I get the same errors in the 2.01.1

EDIT:

Try to change this line
Code:

#forall {${__db[Res]}} {


with this

Code:

#forall {${__db[Res][]}} {
Back to top
View user's profile Send private message
new_to_tin_tin



Joined: 05 Jan 2011
Posts: 36

PostPosted: Fri Jan 20, 2017 3:02 pm    Post subject: Reply with quote

PowerGod wrote:
What version did you used before ?

I get the same errors in the 2.01.1

EDIT:

Try to change this line
Code:

#forall {${__db[Res]}} {


with this

Code:

#forall {${__db[Res][]}} {


Thank you! This seems to have fixed the issue!

I believe I was using a very old version: 2.00.8. But I overwrote it so not 100% sure. Also possible that I had some other debugging spam I removed so I just missed the errors....
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group