View Single Post
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-30-2022 , 18:18   [Windows] SQLite 3.38.3 - 01.05.2022
Reply With Quote #1

SourceMod Extension SQLite 3.38.3
https://www.sqlite.org/changes.html

Install:
- Rename file ...sample\msvc12\Debug\sample.ext.dll to dbi.sqlite.ext.dll
- Shutdown your server.
- Add file into ...addons\sourcemod\extensions\

- Launch server, type sm exts list
Code:
[08] SQLite (1.11.0-manual): SQLite Driver
- If not loaded, to manually load extension sm exts load dbi.sqlite.ext.dll
- sm exts info index
Code:
sm exts info 08
 File: dbi.sqlite.ext.dll
 Loaded: Yes (version 1.11.0-manual)
 Name: SQLite (SQLite Driver)
 Author: Bacardi, AlliedModders LLC (http://www.sourcemod.net/)
 Binary info: API version 8 (compiled Apr 30 2022 23:46:11)
 Method: Loaded by SourceMod

- Important notes!

I am not coder, how this extension got compiled was pure luck.
I tried follow this https://wiki.alliedmods.net/Writing_..._Visual_Studio

- Using SQLite source code https://www.sqlite.org/download.html
I compiled libary and then compiled extension, using copy of SourceMod SQLite extension, with updated files.

- Use your own risk. This is just for experimental use.

Here test plugin, using SQLite new feature RETURNING https://www.sqlite.org/lang_returning.html
PHP Code:


public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}

Database MyDB;

public 
Action test(int clientint args)
{
    
Database.Connect(connectcallback"my_database"0);

    return 
Plugin_Handled;
}

public 
void connectcallback(Database db, const char[] errorany data)
{
    if(
MyDB != db)
        
delete MyDB;

    
MyDB db;

    
MyDB.Query(querytablecallback,
                        
"CREATE TABLE IF NOT EXISTS my_table(    \
                        a INTEGER PRIMARY KEY,                    \
                        b DATE DEFAULT CURRENT_TIMESTAMP,        \
                        c INTEGER                                \
                        );"
,
                        
0DBPrio_Low);
}

public 
void querytablecallback(Database dbDBResultSet results, const char[] errorany data)
{
    if(
results == null)
        return;

// SQLite random() return 64bit values!
// In this code, return value is limited between -2147483647 ~ 2147483647

    
MyDB.Query(queryvaluecallback,
                        
"INSERT INTO my_table(c) VALUES(    \
                        abs(random()) % (2147483647 - -2147483647) + -2147483647    \
                        ) RETURNING *;"
,
                        
0DBPrio_Low);
}

public 
void queryvaluecallback(Database dbDBResultSet results, const char[] errorany data)
{
    if(
results == null)
        return;


    
// table exist, look results and print those

    
if(results.AffectedRows 0)
    {
        
char buffer[256];

        while(
results.FetchRow())
        {
            for(
int x 0results.FieldCountx++)
            {
                
results.FetchString(xbuffersizeof(buffer));
                
PrintToServer("%s"buffer);
            }
        }
    }


output
Code:
sm_test
24
2022-04-30 22:07:50
-384232008
- I don't know how JSON feature works, I have not tested.
Attached Files
File Type: zip sample.zip (7.53 MB, 86 views)
__________________
Do not Private Message @me
Bacardi is offline