• gm_sqlite3
    4 replies, posted
[release][highlight]gm_sqlite3[/highlight] An object oriented SQLite module for Garry's Mod that supports parametrized queries. [B]NOTE[/B] This is the first release of this module, so constructive comments, testers and contributors are welcome. [/release] [release][highlight]Functions[/highlight] [lua] -- Creates and returns a new database object sqlite3.New() -- Returns the current version of the running SQLite library sqlite3.LibVersion() sqlite3.LibVersionNumber() sqlite3.SourceId() -- Evaluates an SQL statement and returns true if it appears to be complete sqlite3.IsStatementComplete(sql) -- Most, if not all, of the constants are also defined, to name a few: sqlite3.SQLITE_OK sqlite3.SQLITE_ERROR -- Open a database sqlite3db:Open(dbname, flags) -- Close currently open database sqlite3db:Close() -- Returns whether or not a database is currently open sqlite3db:IsOpen() -- Toggle extended errors codes on or off sqlite3db:SetExtendedErrors(onoff) -- Returns the last error code sqlite3db:LastError() -- Returns last human readable error sqlite3db:LastErrorMessage() -- Returns the last inserted id number of the primary key sqlite3db:LastInsertId() -- Returns the changes by the last query sqlite3db:Changes() -- Returns the total changes since the database has been open sqlite3db:TotalChanges() -- Executes a simple SQL string, but can also call a callback function on each result row sqlite3db:Execute(sql, callback) -- Prepares an SQL statement for execution and returns a sqlite3stmt object sqlite3db:Prepare(sql) -- Finalizes the statement object and frees memory (Do this every time you are finished with a statement) sqlite3stmt:Finalize() -- Returns the SQL string this statement was prepared with sqlite3stmt:SQLString() -- Fetches a row from the current query and returns either a table with keys (e.g. row["x"]) or nil if no more rows are available -- (Note this is more of a convience function) sqlite3stmt:Fetch() -- Steps the query and moves to next row (will return sqlite3.SQLITE_ROW if a row is available for reading, otherwise sqlite3.SQLITE_DONE) sqlite3stmt:Step() -- Resets the query to its initial state as though it had never been executed, but does not clear bindings sqlite3stmt:Reset() -- Clears bindings associated with this statement, but does not reset the statement itself sqlite3stmt:ClearBindings() -- Returns the number of parameters in this statement sqlite3stmt:ParameterCount() -- Returns the name of a parameter at position n (Leftmost parameter is 1, not 0) sqlite3stmt:GetParameterIndex(n) -- Returns the index of a parameter with given name sqlite3stmt:GetParameterName(name) -- Bind functions will bind a parameter with the given name (string) or index (number) sqlite3stmt:BindNull(index|name) sqlite3stmt:BindInteger(index|name, value) sqlite3stmt:BindFloat(index|name, value) sqlite3stmt:BindString(index|name, value) -- Returns the number of columns in this query sqlite3stmt:ColumnCount() -- Returns the name of a column at position n (Leftmost column is 0, not 1) sqlite3stmt:GetColumnName(n) -- Returns the index of a column with given name sqlite3stmt:GetColumnIndex(name) -- Get functions will return a value in the current row with the given name (string) or index (number) sqlite3stmt:GetInteger(name|index) sqlite3stmt:GetFloat(name|index) sqlite3stmt:GetString(name|index) [/lua] [/release] [release][highlight]Example Code[/highlight] [URL]http://gmsqlite3.googlecode.com/svn/trunk/sv_init.lua[/URL] [/release] [release][highlight]Download[/highlight] [IMG]http://www.sourcemm.net/media/images/code.gif[/IMG] Source SVN: [URL]http://gmsqlite3.googlecode.com/svn/trunk/[/URL] [IMG]http://www.sourcemm.net/media/images/win32.gif[/IMG] Windows Binary: [URL]http://gmsqlite3.googlecode.com/svn/trunk/build/release/gm_sqlite3.dll[/URL] [/release]
Looks pretty good, might get use of this but i prefer MySQL :350:
Hmm why should we use this instead of the [b][url=wiki.garrysmod.com/?title=sql]sql [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] library?
For the people that can't or wont set up a MySQL database.
[QUOTE=Crazy Quebec;22544881]Hmm why should we use this instead of the [B][URL="http://wiki.garrysmod.com/?title=sql"]sql [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B] library?[/QUOTE] This module is object oriented, you can have more then one database, it exposes more of SQLite3's functionality and most of all it supports prepared/parametrized queries thus practically eliminating the risk SQL injection. I started this as a practice project, and because I though the existing sql library was lacking in features, so I released it in hopes that maybe someone would find it useful over the older library. [QUOTE=twisted-scot;22545765]For the people that can't or wont set up a MySQL database.[/QUOTE] SQLite and MySQL both have their uses. One may not be as practical for a job as the other. SQLite is compact, embedded and will work with practically any game host (Not all game hosts are willing to host MySQL servers, dedicated boxes are expensive and MySQL servers hosted from outside can be really laggy). It really depends on what your needs and resources are.
Sorry, you need to Log In to post a reply to this thread.