Garry's Mod Wiki
The SQL library allows you to access powerful database software included with Garry's Mod. It is the preferred and fastest method of storing large amounts of data. The database is located in sv.db serverside and cl.db clientside, both in the Garry's Mod base folder. SQL is a whole scripting language in itself although relatively simple, it's something you'll need to read up on before using this library.
Example of using sql.
Known GMod SQLite settings:
- Temp files are stored in memory (
SQLITE_TEMP_STORE = 3
) - No
ATTACH
andDETACH
operations (SQLITE_OMIT_ATTACH = 1
) - No Virtual Tables (
SQLITE_OMIT_VIRTUALTABLE = 1
) - No
VACUUM
operation (SQLITE_OMIT_VACUUM = 1
) - No
LIMIT
andORDER BY
clauses inDELETE
andUPDATE
statements (SQLITE_ENABLE_UPDATE_DELETE_LIMIT
)
Methods
sql.Begin()
Tells the engine a set of queries is coming. Will wait until sql. Commit is called to run them.
This is most useful when you run more than 100+ queries.
This is equivalent to :
sql. Query( "BEGIN;" )
sql.Commit()
Tells the engine to execute a series of queries queued for execution, must be preceded by sql. Begin.
This is equivalent to sql. Query( "COMMIT;" ).
Returns true if the index with the specified name exists.
Performs a query on the local SQLite database, returns a table as result set, nil if result is empty and false on error.
To run SQL queries with this function safely, it is crucial to ensure that the concatenated variables in the query string are safe to avoid vulnerabilities like SQL injections. For this, it is recommended to use the sql. SQLStr, which allows arguments to be escaped correctly.
Performs the sql. Query and returns the n'th row.
This function is equivalent to safely returning
sql. Query(query)[row]
Performs the query like sql. QueryRow, but returns the first value found.
Escapes dangerous characters and symbols from user input used in an SQLite SQL Query.
This function is not meant to be used with external database engines such as MySQL. Escaping strings with inadequate functions is dangerous!
Returns true if the table with the specified name exists.
This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.
Page content is automatically updated twice a day. Edits and history are not available.
Last Parsed: Loading...