SQLite module for Squirrel.

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,807
Re: SQLite module for Squirrel.
« Reply #15, on June 12th, 2016, 01:34 PM »
For those that use the official plugin and wish to migrate to this plugin without replacing every function in their code. Adding the following code to be executed before anything else (I.e. the top of the first executed script) should be enough to have something working:

Code: [Select]
ConnectSQL <- SQLite_Open;
DisconnectSQL <- SQLite_Close;
QuerySQL <- SQLite_Query;
GetSQLNextRow <- SQLite_NextRow;
GetSQLColumnCount <- SQLite_ColumnCount;
GetSQLColumnData <- SQLite_ColumnData;
FreeSQLQuery <- SQLite_Release;
escapeSQLString <- SQLite_Escape;

Same goes the other way around by reversing the function names. Unless you've used functions specific to this plugin.
.

EK.IceFlake

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761
Re: SQLite module for Squirrel.
« Reply #16, on June 12th, 2016, 02:19 PM »
Or... you know...
CTRL+H
ConnectSQL >> SQLite_Open
DisconnectSQL >> SQLite_Close
QuerySQL >> SQLite_Query
...

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,807
Re: SQLite module for Squirrel.
« Reply #17, on June 12th, 2016, 03:02 PM »
Fixed an issue with platform identification since the SDK header now uses INT32_MAX which requires the C++11 header <stdint.h> thus forcing me to enable C++11 making the previous compile-time platform identification that only checked against the WIN32 macro to not work anymore. Now it checks for both 'WIN32' and '_WIN32'.

Binaries will be available within an hour.
Re: SQLite module for Squirrel.
« Reply #18, on November 12th, 2016, 04:56 PM »Last edited on November 12th, 2016, 04:58 PM
Updated the plugin to be fully compatible with the official plugin without any workarounds. Also updated the SQLite version to the latest version available (3.15.1). The official plugin still uses a version from more than 2 years ago (3.8.6). So there could be a chance that some things changed in newer versions of SQLite. But I doubt it's something to break any compatibility.

The source and binaries have been moved to Github now.
Re: SQLite module for Squirrel.
« Reply #19, on November 12th, 2016, 05:13 PM »
As a warning to the people that still use the official plugin. It seems that it statically links with version 3.0.4 stable of Squirrel (link). Which potentially introduces several issues:

Issue #1: Breaks the "one definition" rule of C++. And this is even worse in this case because of issue #2.

Issue #2: The main Squirrel plugin is using version 3.1 stable of Squirrel (link). Which could potentially introduce data corruption if the newer Squirrel version contains changes in its internal data structures.

These two issues combined become an even worse issue since the SQLite plugin creates instances of it's own (due to the static linking) which then have to be managed by the Squirrel plugin. Again, this could lead to some nasty issues.

I would suggest people to take a few moments and think if it's worth making the switch.
.

Sebastian

  • VC:MP Beta Tester
  • Something like this: hga hga hga
  • Posts: 844

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,807
Re: SQLite module for Squirrel.
« Reply #21,  »
  • Updated the plug-in for the new SDK
  • Updated the SQLite library (3.24.0).
  • Included a CMake build system

Binaries are on the repository. Check the first post for more details.
Re: SQLite module for Squirrel.
« Reply #22,  »Last edited
  • Update the sqlite library to version 3.25.1
  • Update the SQLite_ColumnData function to support retrieval of values by either cell name or index.
  • Implement two new helper functions SQLite_RowAsTable and SQLite_RowAsArray to retrieve all the cells of a row as a table or array.
    Their alias compatible with the naming style of the official plugin are GetSQLColumnTable and GetSQLColumnArray.
  • Add support for 64 bit integers when the language was compiled with such support. Mainly 64 bit versions of the plugin.
  • A few other minor internal enhancements.
Binaries are on the repository. Check the first post for more details.

Here's a simple example that showcase the added features:

Code: [Select]
local db = SQLite_Open("test.db");

// Create the table
SQLite_Exec(db, @"
CREATE TABLE IF NOT EXISTS [Test] (
        [id] INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
        [name] TEXT,
        [hp]    REAL
);
");

// Insert stuff
SQLite_Exec(db, @"INSERT INTO [Test] (name, hp) VALUES ('test1', 23.96);");
SQLite_Exec(db, @"INSERT INTO [Test] (name, hp) VALUES ('test2', 52.64);");
SQLite_Exec(db, @"INSERT INTO [Test] (name, hp) VALUES ('test3', 45.75);");

// Read it back

print("\n\nTable Test ================\n");
{
local q = SQLite_Query(db, "SELECT * FROM [Test]");

if (q != null) do {
local r = SQLite_RowAsTable(q);
print("----------------");
print("Index: " + r["id"]); // Also: r.id
print("Name: " + r["name"]); // Also: r.name
print("health: " + r["hp"]); // Also: r.hp
} while (SQLite_NextRow(q));
}
print("\n\nArray Test ================\n");
{
local q = SQLite_Query(db, "SELECT * FROM [Test]");

if (q != null) do {
local r = SQLite_RowAsArray(q);
print("----------------");
print("Index: " + r[0]);
print("Name: " + r[1]);
print("health: " + r[2]);
} while (SQLite_NextRow(q));
}
print("\n\nName Test ================\n");
{
local q = SQLite_Query(db, "SELECT * FROM [Test]");

if (q != null) do {
print("----------------");
print("Index: " + SQLite_ColumnData(q, "id"));
print("Name: " + SQLite_ColumnData(q, "name"));
print("health: " + SQLite_ColumnData(q, "hp"));
} while (SQLite_NextRow(q));
}
print("\n\nIndex Test ================\n");
{
local q = SQLite_Query(db, "SELECT * FROM [Test]");

if (q != null) do {
print("----------------");
print("Index: " + SQLite_ColumnData(q, 0));
print("Name: " + SQLite_ColumnData(q, 1));
print("health: " + SQLite_ColumnData(q, 2));
} while (SQLite_NextRow(q));
}
.

=RK=MarineForce

  • Sr. Member
  • why noise ??? Re 100%
  • Posts: 388
Re: SQLite module for Squirrel.
« Reply #23,  »
Hey, Bro how to use GetSQLColumnCount <- SQLite_ColumnCount;
GetSQLColumnData <- SQLite_ColumnData;

i don't understand :P , Xd

Mahmoud Tornado

  • Full Member
  • Posts: 216
Re: SQLite module for Squirrel.
« Reply #24,  »
Quote from =RK=MarineForce on October 6th, 08:25 PM
Hey, Bro how to use GetSQLColumnCount <- SQLite_ColumnCount;
GetSQLColumnData <- SQLite_ColumnData;

i don't understand :P , Xd
So you understood this?
Code: [Select]
ConnectSQL <- SQLite_Open;
DisconnectSQL <- SQLite_Close;
QuerySQL <- SQLite_Query;
GetSQLNextRow <- SQLite_NextRow;
FreeSQLQuery <- SQLite_Release;
escapeSQLString <- SQLite_Escape;

=RK=MarineForce

  • Sr. Member
  • why noise ??? Re 100%
  • Posts: 388
Re: SQLite module for Squirrel.
« Reply #25,  »
NextRow? Release? Escape i didn't under stand how to get NextRow,Release,Escape