SQLlite?

Is there any plan to add sqlite access?

Viewing 1 to 18 (18 Total)
SQLlite?

widged

widged
Total Posts: 4
Joined: November 16, 2011

Is there any plan to add sqlite access?

Tags:
Posted on November 16, 2011 at 5:41 AM

singmajesty

singmajesty
Total Posts: 2189
Joined: August 25, 2011

Re: SQLlite?

I used to maintain my own copy of NME, before webOS support was merged in. I had added SQLite support. Bringing it up-to-date as an NME extension is something I have intended to do soon. If you need it now, I can point you to the original sources, otherwise I hope to have it in a nice format when I'm able

Posted on November 17, 2011 at 2:48 AM

widged

widged
Total Posts: 4
Joined: November 16, 2011

Re: SQLlite?

I am trying to figure out what can be done with NME outside of simple 2D games. I would like to experiment with using NME to write an app for android tablets. I need to be able to read and write data, preferably on a sqlite db. Android is the primary target but the reason to try NME for that project really is the prospect of being able to compile the same code (with minimal changes if any) to mac/windows desktop and html5 browser apps.

Sources are ok if they come with clear instructions on how to compile on OSX 10.6. I downloaded haxe last week. My familiarity with that environment is rather limited. I am likely to contribute a tutorial with working examples to the community if the feature gets added.

In the interim, I can probably cope with the ability to read data from an external text file. Is it possible to easily load a text file at runtime? At the very least via a byteArray, with an approach similar to the one described there:http://board.flashkit.com/board/showthread.php?t=731822,... reading UTFBytes from the ByteArray?

Posted on November 17, 2011 at 9:00 AM

singmajesty

singmajesty
Total Posts: 2189
Joined: August 25, 2011

Re: SQLlite?

You can use the SharedObject API to read and write settings. You can also use classes like cpp.FileSystem and cpp.io.File to read and write on Android, but you'll have to know the right paths you can use.

I had the SQLite extension working with Android, and I understand how unimportant SQL is to games, but how crucial it can be to applications. I got caught in the rain in Toronto a couple days ago and it seems to have killed the touchscreen on my Android dev phone. That'll make it a little harder for me to test on my end, for the moment, but in the mean time using the File API may help you.

NME should also support OS X 10.6 ... I just need to use Snow Leopard to rebuild the binaries, instead of Lion, so they're the right version. I should be updating the installer soon

Posted on November 17, 2011 at 11:23 AM

hpatino

hpatino
Total Posts: 1
Joined: January 15, 2012

Re: SQLlite?

I echo the need for SQLite access (done with Flash builder and openplug with flash.data.* package) I am certainly interested in business applications for tables that do require storage of considerable amounts of data for offline use.

I certainly see a future with NME as flash do not run in many devices.

Posted on January 15, 2012 at 1:16 AM

singmajesty

singmajesty
Total Posts: 2189
Joined: August 25, 2011

Re: SQLlite?

Hi hpatino, welcome to the forums!

I actually did update the SQLite code and package it as an NME extension.

Check out this blog post for more information:

http://www.joshuagranick.com/blog/2011/11/29/sql-database-access-fr...

Have a great day!

Posted on January 15, 2012 at 1:30 AM

Horsetopus

Horsetopus
Total Posts: 15
Joined: January 20, 2012

Re: SQLlite?

Hi,

I'm working on an application I would like to see run at least in Android and iOS and if possible on Windows.
Flash would be wonderful since it builds the fastest.

The problem is, I need a local database.
SQLite would be the best, and I tried your extention.
But I just can't get it to work.

Here is what I did:
Download the files (dhu...)
Ran compile.bat
Took the Windows target dll and put it into:
C:\Motion-Twin\haxe\lib\nme\3,1,1\ndll\Windows
Copied the cpp folder into my src folder.
Built a simple project who just does:
_Connection = Sqlite.open ("assets/conjugaison.db");
Ran it.

The runtime error I get is:
Error : Could not load module sqlite3@sqlite_connect__1

What have I done wrong?


Also:
My primary target is to run for Windows so that I can start working.
Can you confirm me that after that it is possible to target Android an iOS also?

Is Flash not an option?
The Flash player can access local files since Flash player... 10, I believe?
Javascript has some APIs to do so also.
It would be nice if it became a basic haXe library.
Or are their other limitations?


Thanks for your time.

Posted on January 22, 2012 at 4:15 AM

singmajesty

singmajesty
Total Posts: 2189
Joined: August 25, 2011

Re: SQLlite?

Oh! It's much simpler than all you've gone through so far smiling

First, use "haxelib install sqlite" to install the library from haxelib.

In NME 3.2, you'll be able to use it with a standard <haxelib name="sqlite" /> tag. In NME 3.1.1, you would use <extension haxelib="sqlite" />

That's it.

As for using SQLite on Flash, there is SQLite support in AIR, but not Flash Player. You can't extend Flash Player with your own C/C++ libraries... its really up to what Adobe already offers in the runtime. There's a way for users to manually save files to their system, but that would not work well for a database, I don't think. The closest thing that Flash Player has is SharedObject, but that isn't suitable for lots of storage.

Generally, Flash works with a server, which stores heavy data. One option would be to use SQLite on your server, with Neko (or PHP, etc). Depending on the application, SQLite may be as (or more) effective than MySQL, and then you could use the same code in the client and the server. Flash Player would just need the additional code to make network requests. You could use Haxe's serialization library to pack and unpack objects for transfer over HTTP.

If you haven't seen it already, here's a little blog post about it:

http://www.joshuagranick.com/blog/2011/11/29/sql-database-access-fr...

Posted on January 22, 2012 at 11:04 AM

Horsetopus

Horsetopus
Total Posts: 15
Joined: January 20, 2012

Re: SQLlite?

It works like a charm.
Thanks!

As for Flash, I agree the client / server workflow is the usual one.
But Flash is the quickest target to compile to.
That would be nice to have a default target where every features works for the best, even if it is not good to deploy on any platform.

Thanks for your work, and for answering all those questions.

Posted on January 22, 2012 at 12:55 PM

singmajesty

singmajesty
Total Posts: 2189
Joined: August 25, 2011

Re: SQLlite?

If you would like a target to use that compiles faster than C++, try Neko.

On Windows, for example, you can target C++ using "nme test project.nmml windows", or you can target Neko using "nme test project.nmml windows -neko"

Neko still uses the same base code as C++, but compiles a lot faster, since it is dynamic like Flash.

The only problem I have had is that sometimes Neko will return null values if you don't type your variables. For example, if you create an event handler, but use "function (event)" instead of "function (event:Event)", it won't find "event.currentTarget". Other than that, its a fast target that I use all the time for testing smiling

Posted on January 22, 2012 at 2:35 PM

Horsetopus

Horsetopus
Total Posts: 15
Joined: January 20, 2012

Re: SQLlite?

I always type my variables, so this is just perfect.
Thanks a lot.

Posted on January 22, 2012 at 4:16 PM

NZCoderGuy

NZCoderGuy
Total Posts: 74
Joined: December 08, 2011

Re: SQLlite?

I would love to know how to use this when targetting iOS?

I have tried the Neko package, whilst building for iOS, and it failed saying it couldn't.

Anyway of porting sql-lite properly to NME for iOS support?

Posted on February 07, 2012 at 8:44 PM

singmajesty

singmajesty
Total Posts: 2189
Joined: August 25, 2011

Re: SQLlite?

Neko includes SQLite support out of the box, but for C++ targets like iOS, you should have the "sqlite" haxelib installed, and use either the cpp.* classes for SQLite or the haxe.* classes (which maps to either cpp.* or neko.* automatically)

Is this what you are using? It should have binaries already compiled for iOS

Posted on February 07, 2012 at 9:17 PM

zsbee

zsbee
Total Posts: 5
Joined: July 27, 2012

Re: SQLlite?

Hi!
I downloaded your example from your blogpost and everything works like a charm if i compile it to Windows, but if i try android all i get is a white screen! (no errors)

What could be the problem?

Posted on July 29, 2012 at 5:20 PM

grahamma

grahamma
Total Posts: 3
Joined: October 02, 2012

Re: SQLlite?

Hi there, I'm having a really hard time getting SQLite working in iOS and I'm hoping you can help me. I've included the SQLite haxelib in my .nmml file and have structured things very similarly to your blog post. I'm including cpp.db.Connection and cpp.db.Sqlite in my database access file.

The issue is that my app hangs on the Sqlite.open(filename) command, but there's no error message and everything stops on a blank white screen (though I'm assuming that's cause my background is white). I've tried using a filename string that points to a file that doesn't exist, (since I read that Sqlite.open is supposed to create one if it can't find it) as well as including an empty .db file in my assets folder and pointing to that. I've even tried creating an empty .sqlite3 db file using rails and pointing to that in my assets folder, all to no avail.

What am I missing here? Do we know that this works in iOS? Is this some kind of iOS file structure / permissions issue?

I tried with your example project but ran into the same issue. Strangely though, your example project did throw an error saying that the file couldn't be found.

I'm at my wits end. Any help is greatly appreciated.

Thanks!
Graham

Posted on October 02, 2012 at 3:17 PM

DrMorph

DrMorph
Total Posts: 8
Joined: October 05, 2012

Re: SQLlite?

grahamma thats work well for me on IOS .

my connection sqlite for IOS :

public ......

var natpath = nme.filesystem.File.applicationDirectory.nativePath; // for native directory
var ConnexionBase : Connection;
ConnexionBase = Sqlite.open(natpath+"/assets/assets_sqlitebdd_db");
var resultSet = ConnexionBase.request("SELECT * FROM Produit ORDER BY LibelleProduit");
END;


name of my sqlite file is "sqlitebdd.db" in my assets directory .
but xcode compile that into a filename "assets_sqlitebdd_db" in "assets"


no permission required .

DrMorph

Posted on October 05, 2012 at 3:12 AM

grahamma

grahamma
Total Posts: 3
Joined: October 02, 2012

Re: Re: SQLlite?

So I figured out my iOS/SQLite issue above and I thought I'd post the solution for anyone who stumbles upon this thread with the same problem.

The SQLite.open("filename.db") command will try and open the file from the program's application directory in the iOS filesystem, and if the file isn't found it will try and create a new one. The problem is that the application directory is read only, so you need to point the open() function to your program's documents directory. To do that with haxe nme, you use the documentsDirectory property of the nme.filesystem.File class:

import nme.filesystem.File;

connection = Sqlite.open(File.documentsDirectory.nativePath+"/filename.db)

The .nativePath property formats the address properly for the native filesystem.

Hope that helps someone!

Posted on October 05, 2012 at 10:15 PM

grahamma

grahamma
Total Posts: 3
Joined: October 02, 2012

Re: SQLlite?

Hey thanks DrMorph,

I didn't see your reply until just now - after I posted my own solution.

Looks like both of our ways get the job done. One of the good things about the method I'm using is that I don't have to include a file in my assets folder.

Regardless, thanks a lot for taking the time to help me out!

Posted on October 05, 2012 at 10:20 PM