• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua SQL and LUA

Shinmaru

エロルアー Scripter!
Joined
Aug 20, 2007
Messages
1,988
Reaction score
88
Location
Puerto Rico
I would like a complete explanation on how to use SQL query on LUA:
Code:
	db.query(query)
	db.storeQuery(query)
	db.escapeString(str)
	db.escapeBlob(s, length)
	db.lastInsertId()
	db.stringComparison()
	db.updateLimiter()

How do they work?

How does each part(SELECT, UPDATE, SET, WHERE, etc.) look for something in the the database?

Show an example script, if possible.

Thanks in advance!

PS
If the explanation is good and valid, I will make a Tutorial off of this(With proper credits given to the contributers.)
 
there is no need to explain how tfs executes queries from luascripts on the mysql server, and i'm sure nobody would be interested either

a few examples of db.getResult and db.executeQuery are provided with the core scripts of TFS 0.3.6 and higher

stringComparison, updateLimiter, escapeBlob and storeQuery aren't used often here in lua scripts, nor there's need to use them yet

lastInsertId is useful to get id of account or player if you create them using lua
 
Last edited:
execute query , uses update,insert,delete like
LUA:
db.executeQuery ("UPDATE `players` SET `name` = 'lamino' WHERE `id` = '1' ;")

get Result should return number of rows it mostly uses SELECT
LUA:
local data = db.getResult("SELECT `name` FROM `players` WHERE `id` = '1'";)
--now you need to fetch this result as this is like a arrray returned, so you need to fetch the name value
local name = data:getDataString("name")--this vary according the result type
 
Actually there is no need in OTS to do that as these functions just do the work, unless you would use it in a outside Ot thingy
 
Can be used if you want to make a chat channel in-game which sync with chat channel on website and vise versa.

But you can use more efficient ways for other TFS database stuff. There are functions to fetch pretty much anything.
 
You could have a fast look here it is very helpful and easy ,and doesnt mention unneeded stuff. Go through the basic part that would be good to have background on how it works and will be effective to you SQL Basics
 
You could have a fast look here it is very helpful and easy ,and doesnt mention unneeded stuff. Go through the basic part that would be good to have background on how it works and will be effective to you SQL Basics

Thanks, but now I feel stupid, because I posted a link about all of this and I should have check with that site first! LOL
 
Back
Top