[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  sqlite variables
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

sqlite variables

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Miloh   (4 posts)  [Biography] bio
Date Sun 20 Nov 2011 04:56 AM (UTC)  quote  ]

Amended on Sun 20 Nov 2011 05:02 AM (UTC) by Miloh

Message
Greetings all,

I am attempting to create a mob database with sqlite. The db is very simple - I just have two fields: mobname and roomname. Both fields go into the sqlite db. The problem is that one of the variables (MyRoom) is going into the db as the variable name itself. I am guessing this is a syntax thing? Any insight would be most appreciated. Here is what I am using:


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="mobdb"
   match="^You get (.*) gold coin? from the dead body of (.*)\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>local MyRoom
  
--RoomName set by another trigger elsewhere that captures roomname.
MyRoom = GetVariable("RoomName")

--ensure vars are correct
Note ("%2 is in ",MyRoom)

--begin db stuff

DatabaseOpen ("mobs", GetInfo (66) .. "mobs.db", 6)

-- insert a record
DatabasePrepare ("mobs", "INSERT INTO mobtable (mobname, roomname) VALUES ('%2','MyRoom')")  --&gt; returns 0 (SQLITE_OK)
DatabaseStep ("mobs")   -- returns 101 (SQLITE_DONE)
DatabaseFinalize ("mobs")  -- returns 0 (SQLITE_OK)
      
DatabaseClose ("mobs")  -- close it </send>
  </trigger>
</triggers>


And when I check the db, the "%2" or mobname goes in as correctly. But, for roomname, I get "MyRoom".

Thanks much in advance!
[Go to top] top

Posted by Fiendish   USA  (1,035 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sun 20 Nov 2011 05:12 AM (UTC)  quote  ]

Amended on Sun 20 Nov 2011 05:14 AM (UTC) by Fiendish

Message
Quote:
VALUES ('%2','MyRoom')

I'm not sure what you expect that to do other than what is happening.

Perhaps you want instead
"INSERT INTO mobtable (mobname, roomname) VALUES ('%2','"..MyRoom.."')"

http://aardwolfclientpackage.googlecode.com/
https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Miloh   (4 posts)  [Biography] bio
Date Reply #2 on Sun 20 Nov 2011 05:26 AM (UTC)  quote  ]
Message
Hi Fiendish, you are the man!! That worked like a charm. Thank you very much. I had a feeling it was something like that. I did fail to mention that I tried everything I could think of with that pesky variable... Double quotes, no quotes at all, a ".." before the variable, a dollar sign...

Anywho, again, thank you :)



[Go to top] top

Posted by Fiendish   USA  (1,035 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Sun 20 Nov 2011 05:36 AM (UTC)  quote  ]

Amended on Sun 20 Nov 2011 05:41 AM (UTC) by Fiendish

Message
Values for %1,%2,etc get mapped into place by MUSHclient before the Lua code gets sent to the script parser. That's the only reason you can use %2 in the way you did without breaking the query string apart into chunks (and which is why people need to wrap them in quotation marks to compare the values with strings). But MyRoom is just a Lua variable containing a string. In order to get the value from MyRoom you have to treat it as a variable and not just like some letters, which means pulling it outside of the string and using concatenation to merge the parts together.

You had
DatabasePrepare("mobs", "a_string")
when you needed
DatabasePrepare("mobs", "first_part_of_the_string"..your_variable.."the_rest_of_the_string")

http://aardwolfclientpackage.googlecode.com/
https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


1,426 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]