This commit is contained in:
atanasovg
2014-03-13 16:26:21 +02:00
6 changed files with 0 additions and 223 deletions

View File

@ -63,13 +63,6 @@
<TypeScriptCompile Include="Application\application.ios.ts"> <TypeScriptCompile Include="Application\application.ios.ts">
<DependentUpon>application.d.ts</DependentUpon> <DependentUpon>application.d.ts</DependentUpon>
</TypeScriptCompile> </TypeScriptCompile>
<TypeScriptCompile Include="Database\database.android.ts">
<DependentUpon>database.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="Database\database.d.ts" />
<TypeScriptCompile Include="Database\database.ios.ts">
<DependentUpon>database.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="declarations.d.ts" /> <TypeScriptCompile Include="declarations.d.ts" />
<TypeScriptCompile Include="declarations.android.d.ts"> <TypeScriptCompile Include="declarations.android.d.ts">
<DependentUpon>declarations.d.ts</DependentUpon> <DependentUpon>declarations.d.ts</DependentUpon>
@ -81,9 +74,6 @@
<TypeScriptCompile Include="Camera\camera.ios.ts"> <TypeScriptCompile Include="Camera\camera.ios.ts">
<DependentUpon>camera.d.ts</DependentUpon> <DependentUpon>camera.d.ts</DependentUpon>
</TypeScriptCompile> </TypeScriptCompile>
<TypeScriptCompile Include="Database\database_query_result.ts">
<DependentUpon>database.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="declarations.ios.d.ts"> <TypeScriptCompile Include="declarations.ios.d.ts">
<DependentUpon>declarations.d.ts</DependentUpon> <DependentUpon>declarations.d.ts</DependentUpon>
</TypeScriptCompile> </TypeScriptCompile>
@ -132,9 +122,6 @@
</TypeScriptCompile> </TypeScriptCompile>
<TypeScriptCompile Include="WebClient\web_client.d.ts" /> <TypeScriptCompile Include="WebClient\web_client.d.ts" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Database\Readme.md" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Image\Readme.md" /> <Content Include="Image\Readme.md" />
</ItemGroup> </ItemGroup>

View File

@ -1,28 +0,0 @@
Sample code:
```
// TODO: Update with the module architecture (require)
var folder = TK.IO.KnownFolders.Documents();
var path = folder.path + "/MyDB.db";
var db = TK.Data.Database.openDatabase(path);
db.executeSql('DROP TABLE IF EXISTS DEMO;');
db.executeSql('CREATE TABLE DEMO (id unique, data);');
db.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
db.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
db.query("SELECT * FROM DEMO", function(result){
Log("result count:" + result.count);
for(var item in result.items)
{
for(var name in item)
{
Log(name + ":" + item[name]);
}
}
}, function(e){ Log("Error:" + e.message ); }
);
```

View File

@ -1,92 +0,0 @@
import query_module = require("Database/database_query_result");
export module tk {
export module data {
/**
* Android specific Database implementation.
*/
export class Database {
public android: android.database.sqlite.SQLiteDatabase;
public static openDatabase(path: string): Database {
return new Database(path);
}
/**
* Open or creates SQLiteDatabase using the specified path.
*/
constructor(path: string) {
this.android = android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(path, null);
}
/**
* Executes non-select SQL statements using execSQL method of android.database.sqlite.SQLiteDatabase.
*/
public executeSql(sqlStatement: string, successCallback?: Function, errorCallback?: (e: Error) => void) {
try {
if (sqlStatement.toLowerCase().indexOf("select") > -1) {
throw new Error("Please use 'query' method for select SQL statements!");
}
this.android.execSQL(sqlStatement);
if (successCallback) {
successCallback();
}
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
/**
* Executes select SQL statements using rawQuery method of android.database.sqlite.SQLiteDatabase and returns QueryResult.
*/
public query(sqlSelectStatement: string, successCallback: (results: query_module.tk.data.QueryResult) => void, errorCallback?: (e: Error) => void) {
try {
if (sqlSelectStatement.toLowerCase().indexOf("select") == -1) {
throw new Error("Please use 'executeSql' method for non-select SQL statements!");
}
if (successCallback) {
var cursor = this.android.rawQuery(sqlSelectStatement, null);
var qr = new query_module.tk.data.QueryResult();
qr.items = [];
qr.count = cursor.getCount();
if (qr.count > 0) {
cursor.moveToFirst();
var names = cursor.getColumnNames();
do {
var item = {};
for (var name in names) {
item[name] = cursor.getString(cursor.getColumnIndex(name));
}
qr.items.push(item);
} while (cursor.moveToNext());
cursor.close();
}
successCallback(qr);
}
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
}
}
}

View File

@ -1,16 +0,0 @@
import qr = require("Database/database_query_result");
/**
* Data (Database) module.
*/
export declare module tk {
export module data {
/**
* The Database interface.
*/
export class Database {
executeSql(sqlStatement: string, successCallback?: Function, errorCallback?: (e: Error) => void)
query(sqlSelectStatement: string, successCallback: (results: qr.tk.data.QueryResult) => void, errorCallback?: (e: Error) => void)
}
}
}

View File

@ -1,53 +0,0 @@
import query_module = require("Database/database_query_result");
export module tk {
export module data {
export class Database {
public static openDatabase(path: string): Database {
return new Database(path);
}
constructor(path: string) {
}
public executeSql(sqlStatement: string, successCallback?: Function, errorCallback?: (e: Error) => void) {
try {
// native code goes here
if (successCallback) {
successCallback();
}
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
public query(sqlSelectStatement: string, successCallback: (results: query_module.tk.data.QueryResult) => void, errorCallback?: (e: Error) => void) {
try {
// native code goes here
if (successCallback) {
var qr = new query_module.tk.data.QueryResult();
successCallback(qr);
}
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
}
}
}

View File

@ -1,21 +0,0 @@
export module tk {
export module data {
export class QueryResult {
constructor() {
}
/**
* Total number of query result items.
*/
get count(): number {
return 0;
}
/**
* The query result items.
*/
public items: Array<any>;
}
}
}