SQLite Library for AHK v2

Post your working scripts, libraries and tools.
User avatar
RaptorX
Posts: 386
Joined: 06 Dec 2014, 14:27
Contact:

SQLite Library for AHK v2

14 Nov 2023, 11:37

Hi guys,

This is a beta version for my updated SQLite library for v2.0+.

The main advantages of it are the ease of access of data in specialized objects.

Code: Select all

#Requires AutoHotkey v2.0+ ; prefer 64-Bit
#include <SQLite\SQLite>

db := SQLite(':memory:') ; this creates a temporary in-memory database
db.Exec('BEGIN TRANSACTION;')
db.Exec('CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, column TEXT, value REAL)')
loop 20
	db.Exec('INSERT INTO test VALUES(' A_Index ', "name' A_Index '", "value' A_Index '");')
db.Exec('COMMIT TRANSACTION;')
table := db.Exec('SELECT * FROM test')
msgbox table.count

for row in table.rows
	names .= row.name '`n' ; "name" is the column which we setup on the example above

msgbox names

; or

for row in table.rows
{
	for header, value in row
		data .= header ' = ' value ', ' ; rows can be looped over as well

	data .= '`n'
}

msgbox data

; you can access individual cells like this:
msgbox table[5, 'name'] ; returns 'name5'

; also you can get full rows like this:
row := table[5]
msgbox row.name
You can open/create database files or use in-memory and temporary files as described in the documentation.

You can checkout the ReadMe file in the github repository for a quick intro and demonstration.
The code base has some basic unit testing and basic error handling as well.

The Object is split in 2 main parts: the SQLite object which is the public interface you would use in your code and the SQLite3 interface that is the one actually doing the actual work.

the SQLite object depends on the low-level SQLite3 interface (included in the code) that handles direct interaction with the DLL file so make sure you have them both in the file structure provided by the download file.

This library has a copy of the latest DLL releases so all in all it should be a self containing library that if you include in your projects you can use with very little modification.

Right now Im open to suggestions / improvement.
Projects:
AHK-ToolKit
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: SQLite Library for AHK v2

15 Nov 2023, 01:33

[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
RaptorX
Posts: 386
Joined: 06 Dec 2014, 14:27
Contact:

Re: SQLite Library for AHK v2

15 Nov 2023, 09:36

jNizM wrote:
15 Nov 2023, 01:33
viewtopic.php?f=83&t=95389 ?
Hey!

Yes I have seen that version. The main difference with this version is that it is a managed wrapper. Particularly the Table object is what I spent more time on to make it easy to iterate or get arbitrary data from a table by using the row number and the column name like:

Code: Select all

table := db.Exec("SELECT * from test")

; allows using for loops on the data
for row in table.rows
	msgbox row.phone
	
for row in table.rows
{
	for col, value in row
		msgbox col ' = ' value 
}

; access the second row, column header to get its value without looping
msgbox table[2, "phone"]
I was not able to do the above with the library you linked without having to create the code myself.

My end goal for this was not only having full control by using the SQLite3 interface, that will allow you to call all internal functions like your version but also there's the managed interface that doesnt need you to know too much about how the sqlite works to get data quickly :)

Also I wanted it to be the least verbose possible. You have no need to use the prepare statements and stepping as you normally would but you CAN if you want to.
Projects:
AHK-ToolKit
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: SQLite Library for AHK v2

02 Feb 2024, 04:23

Have marked. :+1:
valuex
Posts: 86
Joined: 01 Nov 2014, 08:17

Re: SQLite Library for AHK v2

04 Feb 2024, 08:15

:bravo: :bravo: :bravo:
Does it support the fts5 extension, like https://github.com/wangfenjin/simple?
User avatar
xMaxrayx
Posts: 168
Joined: 06 Dec 2022, 02:56
Contact:

Re: SQLite Library for AHK v2

01 Apr 2024, 15:47

Thanks <3

going learn SQlite instead of using text file then try this :D I dropped mangoDB and mysql becouse the need a servers.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 46 guests