Difference between revisions of "Sqlite3"

From GiderosMobile
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:sqlite3 -->
 
<!-- GIDEROSOBJ:sqlite3 -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2012.2.1<br/>
+
'''Available since:''' Gideros 2012.2.1<br/>
=== <translate>Description</translate> ===
 
<translate><br />
 
Gideros runtime supports public domain SQLite3 database engine for iOS, Android and Desktop platforms. <br />
 
For more information and detailed documentation, please visit [http://lua.sqlite.org](http://lua.sqlite.org).<br />
 
<br />
 
&lt;h3&gt;SQLite3 on Android platforms&lt;/h3&gt;<br />
 
Currently, LuaSQLite3 plugin cannot open databases stored in APK files. Therefore, database file should be<br />
 
copied from resource directory to documents directory.<br />
 
<br />
 
To copy a file, this function can be used:<br />
 
<br />
 
&lt;pre&gt;&lt;code&gt;<br />
 
local function copy(src, dst)<br />
 
local srcf = io.open(src, &quot;rb&quot;)<br />
 
local dstf = io.open(dst, &quot;wb&quot;)<br />
 
<br />
 
local size = 2^13      -- good buffer size (8K)<br />
 
while true do<br />
 
local block = srcf:read(size)<br />
 
if not block then break end<br />
 
dstf:write(block)<br />
 
end<br />
 
<br />
 
srcf:close()<br />
 
dstf:close()<br />
 
end<br />
 
<br />
 
&lt;/code&gt;&lt;/pre&gt;<br />
 
Also it&#039;s better to check if the database file is previously copied or not. To check if a file can be found <br />
 
on the underlying file system, this function can be used:<br />
 
<br />
 
&lt;pre&gt;&lt;code&gt;<br />
 
local function exists(file)<br />
 
local f = io.open(file, &quot;rb&quot;)<br />
 
if f == nil then<br />
 
return false<br />
 
end<br />
 
f:close()<br />
 
return true<br />
 
end<br />
 
<br />
 
&lt;/code&gt;&lt;/pre&gt;<br />
 
By using these two function, you can copy the database file from resource to documents directory before using it:<br />
 
<br />
 
&lt;pre&gt;&lt;code&gt;<br />
 
if not exists(&quot;|D|database.db&quot;) then<br />
 
copy(&quot;database.db&quot;, &quot;|D|database.db&quot;)<br />
 
end<br />
 
<br />
 
&lt;/code&gt;&lt;/pre&gt;<br />
 
  
&lt;h3&gt;SQLite3 on on WinRT need to add an extension to Visual Studio&lt;/h3&gt;
+
=== Description ===
 +
Gideros runtime supports public domain SQLite3 database engine for iOS, Android and Desktop platforms.
 +
<source lang="lua">
 +
require "lsqlite3" -- ?
 +
</source>
 +
 
 +
'''For more information and detailed documentation, please visit [http://lua.sqlite.org](http://lua.sqlite.org)'''
 +
 
 +
=== SQLite3 on Android platforms ===
 +
Currently, LuaSQLite3 plugin cannot open databases stored in APK files. Therefore, database file should be copied from resource directory to documents directory.
 +
 
 +
To copy a file, this function can be used:
 +
<source lang="lua">
 +
local function copy(src, dst)
 +
local srcf = io.open(src, "r")
 +
local dstf = io.open(dst, "wb")
 +
local size = 2^13 -- good buffer size (8K)
 +
while true do
 +
local block = srcf:read(size)
 +
if not block then break end
 +
dstf:write(block)
 +
end
 +
srcf:close()
 +
dstf:close()
 +
end
 +
</source>
 +
 
 +
Also it is better to check if the database file is previously copied or not. To check if a file can be found on the underlying file system, this function can be used:
 +
<source lang="lua">
 +
local function exists(file)
 +
local f = io.open(file, "rb")
 +
if f == nil then return false end
 +
f:close()
 +
return true
 +
end
 +
</source>
 +
 
 +
By using these two function, you can copy the database file from resource to documents directory before using it:
 +
<source lang="lua">
 +
if not exists("|D|database.db") then
 +
copy("database.db", "|D|database.db")
 +
end
 +
</source>
 +
 
 +
=== SQLite3 on on WinRT need to add an extension to Visual Studio ===
 +
Gideros now supports sqlite and to make this work on Windows Phone, it is necessary to add an extension to Visual Studio. Even if you don't use sqlite, you will need to add this extension or Windows Phone projects exported by Gideros will not compile. It's easy to do as explained next. Of course, you only need to add the extension once.
 +
 
 +
Open Visual Studio and go to ''TOOLS > Extensions and Updates''. Select the ''Online'' tab on the left and type sqlite in the search bar at the top right. Select ''SQLite'' for Windows 8.1 or/and Windows Phone 8.1 and select install. You will need to restart VS for the extension to take effect.
  
Gideros now supports sqlite and to make this work on Windows Phone, it is necessary to add an extension to Visual Studio. Even if you don't use sqlite, you will need to add this extension or Windows Phone projects exported by Gideros will not compile. It's easy to do as explained next. Of course, you only need to add the extension once.
 
&lt;br/&gt;
 
Open Visual Studio and go to ''TOOLS > Extensions and Updates''. Select the ''Online'' tab on the left and type sqlite in the search bar at the top right. Select ''SQLite'' for Windows 8.1 or/and Windows Phone 8.1 and select install. You will need to restart VS for the extension to take effect.</translate>
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Revision as of 22:06, 10 October 2022

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2012.2.1

Description

Gideros runtime supports public domain SQLite3 database engine for iOS, Android and Desktop platforms.

require "lsqlite3" -- ?
For more information and detailed documentation, please visit [1](http://lua.sqlite.org)

SQLite3 on Android platforms

Currently, LuaSQLite3 plugin cannot open databases stored in APK files. Therefore, database file should be copied from resource directory to documents directory.

To copy a file, this function can be used:

local function copy(src, dst)
	local srcf = io.open(src, "r")
	local dstf = io.open(dst, "wb")
	local size = 2^13 -- good buffer size (8K)
	while true do
		local block = srcf:read(size)
		if not block then break end
		dstf:write(block)
	end
	srcf:close()
	dstf:close()
end

Also it is better to check if the database file is previously copied or not. To check if a file can be found on the underlying file system, this function can be used:

local function exists(file)
	local f = io.open(file, "rb")
	if f == nil then return false end
	f:close()
	return true
end

By using these two function, you can copy the database file from resource to documents directory before using it:

if not exists("|D|database.db") then
	copy("database.db", "|D|database.db")
end

SQLite3 on on WinRT need to add an extension to Visual Studio

Gideros now supports sqlite and to make this work on Windows Phone, it is necessary to add an extension to Visual Studio. Even if you don't use sqlite, you will need to add this extension or Windows Phone projects exported by Gideros will not compile. It's easy to do as explained next. Of course, you only need to add the extension once.

Open Visual Studio and go to TOOLS > Extensions and Updates. Select the Online tab on the left and type sqlite in the search bar at the top right. Select SQLite for Windows 8.1 or/and Windows Phone 8.1 and select install. You will need to restart VS for the extension to take effect.

Methods

Events

Constants