Raised This Month: $ Target: $400
 0% 

[Windows] SQLite 3.38.3 - 01.05.2022


Post New Thread Reply   
 
Thread Tools Display Modes
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, 13 views)
__________________
Do not Private Message @me
Bacardi is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-01-2022 , 08:07   Re: [Windows] SQLite 3.38.3 - 01.05.2022
Reply With Quote #2

Here is JSON example: https://tirkarthi.github.io/programm...rovements.html

PHP Code:
/*
./sqlite3
SQLite version 3.38.0 2022-02-22 18:58:40
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> create table user(id integer primary key, name text, interests json);
sqlite> insert into user values(null, "John", '{"likes": ["skating", "reading", "swimming"], "dislikes": ["cooking"]}');
sqlite> insert into user values(null, "Kate", '{"likes": ["reading", "swimming"], "dislikes": ["skating"]}');
sqlite> insert into user values(null, "Jim", '{"likes": ["reading", "swimming"], "dislikes": ["cooking"]}');
sqlite> .mode column
sqlite> select * from user;
id  name  interests                                                   
--  ----  ------------------------------------------------------------
1   John  {"likes": ["skating", "reading", "swimming"], "dislikes": ["cooking"]}                                               
2   Kate  {"likes": ["reading", "swimming"], "dislikes": ["skating"]}
3   Jim   {"likes": ["reading", "swimming"], "dislikes": ["cooking"]}

*/


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 user(    \
                        id INTEGER PRIMARY KEY,                \
                        name TEXT,                            \
                        interests JSON                        \
                        );"
,
                        
0DBPrio_Low);
}

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

    
MyDB.Query(queryinsertcallback,
                        
"INSERT INTO user VALUES(    \
                        null, \"John\", '{\"likes\": [\"skating\",\"reading\",\"swimming\"], \"dislikes\": [\"cooking\"]}\'    \
                        ),                            \
                        (                            \
                        null, \"Kate\", '{\"likes\": [\"reading\",\"swimming\"], \"dislikes\": [\"skating\"]}\'                \
                        ),                            \
                        (                            \
                        null, \"Jim\", '{\"likes\": [\"reading\",\"swimming\"], \"dislikes\": [\"cooking\"]}\'                \
                        );"
,
                        
0DBPrio_Low);
}



/*
select id, name, interests from user 
where interests->'$.likes'->>'$[0]' = 'reading';
*/
public void queryinsertcallback(Database dbDBResultSet results, const char[] errorany data)
{
    if(
results == null)
        return;

    
MyDB.Query(queryvaluecallback,
                        
"SELECT id, name, interests FROM user            \
                        WHERE interests->'$.likes'->>'$[0]' = 'reading';"
,
                        
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
2
Kate
{"likes": ["reading","swimming"], "dislikes": ["skating"]}
3
Jim
{"likes": ["reading","swimming"], "dislikes": ["cooking"]}
5
Kate
{"likes": ["reading","swimming"], "dislikes": ["skating"]}
6
Jim
{"likes": ["reading","swimming"], "dislikes": ["cooking"]}
8
Kate
{"likes": ["reading","swimming"], "dislikes": ["skating"]}
9
Jim
{"likes": ["reading","swimming"], "dislikes": ["cooking"]}
11
Kate
{"likes": ["reading","swimming"], "dislikes": ["skating"]}
12
Jim
{"likes": ["reading","swimming"], "dislikes": ["cooking"]}
14
Kate
{"likes": ["reading","swimming"], "dislikes": ["skating"]}
15
Jim
{"likes": ["reading","swimming"], "dislikes": ["cooking"]}
17
Kate
{"likes": ["reading","swimming"], "dislikes": ["skating"]}
18
Jim
{"likes": ["reading","swimming"], "dislikes": ["cooking"]}
20
Kate
{"likes": ["reading","swimming"], "dislikes": ["skating"]}
21
Jim
{"likes": ["reading","swimming"], "dislikes": ["cooking"]}
__________________
Do not Private Message @me

Last edited by Bacardi; 05-01-2022 at 08:08.
Bacardi is offline
psychonic

BAFFLED
Join Date: May 2008
Old 05-21-2022 , 22:35   Re: [Windows] SQLite 3.38.3 - 01.05.2022
Reply With Quote #3

It would be very preferable if you would use a different extension/db/include name to not conflict with named used by first-party SM extensions.
psychonic is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-22-2022 , 10:25   Re: [Windows] SQLite 3.38.3 - 01.05.2022
Reply With Quote #4

I know... but I'm too dummy to make it.
I wanted to upgrade SM own extension, because it was easy way and this is for testing purpose. :S
Bacardi is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:25.


Powered by vBulletin®
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Theme made by Freecode