mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Merge branch 'master' of https://github.com/telerik/xPlatCore
This commit is contained in:
13
BCL.csproj
13
BCL.csproj
@ -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>
|
||||||
|
@ -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 ); }
|
|
||||||
);
|
|
||||||
|
|
||||||
```
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
16
Database/database.d.ts
vendored
16
Database/database.d.ts
vendored
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user