SQLite

Monkey Programming Forums/User Modules/SQLite

Samah(Posted 2015) [#1]
So I decided to make an incredibly simple wrapper on SQLite.
At the moment it only supports Windows C++ targets, and I've only tested it with cpptool using MinGW.

Here's what I want to know:
1) Which targets you would like to see it on? Suggest some and I'll give you an estimate on how much work is required, if it's possible or feasible to do.
2) What features would you like to see wrapped? At the moment it lets you open a database, execute statements, and loop through result sets.

Enjoy.

https://github.com/swoolcock/monkeysqlite


ziggy(Posted 2015) [#2]
Awesome!


rIKmAN(Posted 2015) [#3]
Awesome! - I'd love to see this on iOS!

I'm not sure what you mean by 'features', but would being able to order the results count?


Samah(Posted 2015) [#4]
@rIKmAN: I'm not sure what you mean by 'features', but would being able to order the results count?

format_code('SELECT Foo FROM Test ORDER BY Foo')

Note that the design is currently very volatile. I essentially wrapped the official structs and functions and made them a bit cleaner to use. Other targets may have a slightly different implementation, and I'll have to hack them to work the current way.
I may end up designing it from a usability perspective, then implement each target whichever way it needs to. I was considering having a common "sql" interface so that there's the possibility of plugging in other drivers later, but I don't see any reason why you would need to support Oracle or MSSQL... maybe someone can enlighten me on why a game would need something that complicated.


rIKmAN(Posted 2015) [#5]
Yeah that's exactly the syntax I meant Samah, and I know it wasn't really a feature but I wasn't sure what you meant by that.
What other features were you thinking of?

Oracle / MSSQL would be overkill for games imo, SQLite is perfect - quick, light and simple.

If you need any to help test when you get round to working on it for iOS let me know, I'd be happy to help :)


bitJericho(Posted 2015) [#6]
This is totally killer. Can't wait to see it hit other platforms if it gets to that point. In another language I wrote the beginnings of a GUI library that made extensive use of in-memory sqlite to hold the data rather than lists and classes. It would be cool to continue that work in monkey.


Amon(Posted 2015) [#7]
This is cool. Do you ever stop and not code? Your worse than Brucey you are Mr Samah. :)

If Android is supported then I'm good to go.

Thank you for this.


Samah(Posted 2015) [#8]
Sorry for being inactive with this, I've got a million projects on my plate and a new job coming up soon (Objective-C and Swift). iOS and Android will probably be my next target.
Question: Would you guys prefer that this just be a SQLite wrapper with 99% mapped functions, or do you think it would be good to make it less DB specific? I can't see the point for having drivers for other databases since this is client-side and not server-side. The catch with the current implementation is that the developer needs to actually know all the raw calls to SQLite.
I might see how hard it is to actually include the source directly into the generated file, like Mark's GLFW configuration.

Continued from: http://www.monkey-x.com/Community/posts.php?topic=10165&post=111879
@Raz: ...does that include GLFW?

Yes.
@Raz: I'm currently getting...

Looks like you haven't added sqlite to the libraries, so the linker can't find it. Did you do steps 2 and 5 in the configuration?
https://github.com/swoolcock/monkeysqlite/blob/master/src/sqlite/sqlite.monkey
format_code('2) Copy "libsqlite3.a" to MinGW/lib
5) Add to CONFIG.MONKEY in the build directory: #CC_LIBS="-lsqlite3"')


Raz(Posted 2015) [#9]
Hi Samah, yup I believe I've completed all of those steps.

With regards to copying the dll, I put this in the same directory as CONFIG.MONKEY, is that correct?

Ta!
-Chris


Samah(Posted 2015) [#10]
Right, I've managed to static link sqlite3 directly into MonkeyGame.exe. It just requires some hacking to the GLFW3 target. (static linking means you don't need the DLL any more)
No need to mess around with your MinGW installation either. :D

You'll want the first zip file, "sqlite-amalgamation-3090000.zip"
http://sqlite.org/download.html

1) Create a new directory in MonkeyXPro/targets/glfw3/template called "sqlite3"
2) Copy "sqlite3.c" and "sqlite3.h" into that directory
3) In the gcc_winnt directory, open Makefile in a decent text editor (not notepad)
4) In the CPPFLAGS section, change the last line to (note the ending backslash):
format_code('-I../lpng1610 \
-I../sqlite3')
5) Before the line "vpath %.cpp ..", add the following:
format_code('vpath %.c ../sqlite3')
6) In the OBJS0 section, before context.o, add (note the ending backslash):
format_code('sqlite3.o \')

It would be nice if there was a way to set all this stuff in the Monkey source, but we're limited as to what we can configure without modifying the template.

If you want to cheat:
format_codebox('
CC=gcc
CFLAGS=

CXX=g++
CXXFLAGS=

CPPFLAGS=$(CCOPTS) \
-Wno-free-nonheap-object \
-I../glfw3/include \
-I../glfw3/src \
-I../openal/include \
-I../stb \
-I../zlib-1.2.8 \
-I../lpng1610 \
-I../sqlite3

LD=g++
LDFLAGS=-Wl,--subsystem,windows -L../openal/libs/Win32 -L../openal/libs/Win64
LDLIBS=-lcomdlg32 -lgdi32 -lopengl32 -lOpenAL32 -lws2_32

vpath %.c ../glfw3/src
vpath %.c ../stb
vpath %.c ../sqlite3
vpath %.cpp ..

OBJS0=\
sqlite3.o \
context.o \
init.o \
input.o \
monitor.o \
wgl_context.o \
win32_init.o \
win32_monitor.o \
win32_time.o \
win32_tls.o \
win32_window.o \
window.o \
winmm_joystick.o \
stb_vorbis.o \
stb_image.o \
main.o

TMP=build/$(dir $(OUT))

OBJS=$(patsubst %.o,$(TMP)%.o,$(OBJS0))

all : $(OUT)

$(OUT) : $(OBJS)
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)

$(TMP)%.o : %.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

$(TMP)%.o : %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<')


Raz(Posted 2015) [#11]
Woop, just managed to give it a proper try and it works a treat :D