sql/LastError

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Also menu state)
(Added Example)
 
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=LastError
 
|Parent=sql
 
 
|Description=Returns the last error from a SQLite query.
 
|Description=Returns the last error from a SQLite query.
 
|Realm=Shared and Menu
 
|Realm=Shared and Menu
Line 8: Line 6:
 
{{Ret
 
{{Ret
 
|type=string
 
|type=string
|desc= error
+
|desc=error
 +
}}
 +
{{Example
 +
|Description=Reports all SQL errors into console automatically. Can help on debugging or testing
 +
|Code=sql.m_strError = nil -- This is required to invoke __newindex
 +
setmetatable(sql,{__newindex = function(t,k,v) if k == "m_strError" and v then print("[SQL Error] "..v) end end})
 +
|Output=After running <pre class="inline">sql.Query("SELECT")</pre> will print <pre class="inline">[SQL Error] incomplete input</pre> in the console.
 
}}
 
}}

Latest revision as of 20:46, 6 January 2020

 sql.LastError( )

Contents

Description

Returns the last error from a SQLite query.

Returns

string

error

Examples

Example

Reports all SQL errors into console automatically. Can help on debugging or testing

sql.m_strError = nil -- This is required to invoke __newindex
setmetatable(sql,{__newindex = function(t,k,v) if k == "m_strError" and v then print("[SQL Error] "..v) end end})

Output:

After running
sql.Query("SELECT")
will print
[SQL Error] incomplete input
in the console.
Personal tools
Navigation