SQLite module for Squirrel.

Started by ., Mar 28, 2015, 04:26 AM

Previous topic - Next topic

.

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:

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

Or... you know...
CTRL+H
ConnectSQL >> SQLite_Open
DisconnectSQL >> SQLite_Close
QuerySQL >> SQLite_Query
...

.

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.
.

.

#18
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.
.

.

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

Thanks for that !
It was included in my Blank Server files.

.

  • 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.
.

.

#22
  • 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:

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

Hey, Bro how to use GetSQLColumnCount <- SQLite_ColumnCount;
GetSQLColumnData <- SQLite_ColumnData;

i don't understand :P , Xd

Mahmoud Tornado

Quote from: =RK=MarineForce on Oct 06, 2018, 07:25 PMHey, Bro how to use GetSQLColumnCount <- SQLite_ColumnCount;
GetSQLColumnData <- SQLite_ColumnData;

i don't understand :P , Xd

So you understood this?
ConnectSQL <- SQLite_Open;
DisconnectSQL <- SQLite_Close;
QuerySQL <- SQLite_Query;
GetSQLNextRow <- SQLite_NextRow;
FreeSQLQuery <- SQLite_Release;
escapeSQLString <- SQLite_Escape;

=RK=MarineForce

NextRow? Release? Escape i didn't under stand how to get NextRow,Release,Escape