本文整理汇总了C#中SQLitePCL.SQLiteConnection.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Prepare方法的具体用法?C# SQLiteConnection.Prepare怎么用?C# SQLiteConnection.Prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLitePCL.SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.Prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadDatabase
public static void LoadDatabase(SQLiteConnection db)
{
string sql = @"CREATE TABLE IF NOT EXISTS
Customer (Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
Name VARCHAR( 140 ),
City VARCHAR( 140 ),
Contact VARCHAR( 140 )
);";
using (var statement = db.Prepare(sql))
{
statement.Step();
}
sql = @"CREATE TABLE IF NOT EXISTS
Project (Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
CustomerId INTEGER,
Name VARCHAR( 140 ),
Description VARCHAR( 140 ),
DueDate DATETIME,
FOREIGN KEY(CustomerId) REFERENCES Customer(Id) ON DELETE CASCADE
)";
using (var statement = db.Prepare(sql))
{
statement.Step();
}
// Turn on Foreign Key constraints
sql = @"PRAGMA foreign_keys = ON";
using (var statement = db.Prepare(sql))
{
statement.Step();
}
}
示例2: EnableForeignKeys
private void EnableForeignKeys(SQLiteConnection connection)
{
using (var statement = connection.Prepare(@"PRAGMA foreign_keys = ON;"))
{
statement.Step();
}
}
示例3: getDownloads
public static ObservableCollection<Downloads> getDownloads()
{
string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "User.db");
ObservableCollection<Downloads> list = new ObservableCollection<Downloads>();
using (var connection = new SQLiteConnection(path))
{
using (var statement = connection.Prepare(@"SELECT * FROM DownloadList;"))
{
while (statement.Step() == SQLiteResult.ROW)
{
list.Add(new Downloads()
{
FileName = (string)statement[0],
Path = (string)statement[1],
Date = (string)statement[2],
Size = (string)statement[3]
});
Debug.WriteLine(statement[0] + " ---" + statement[1] + " ---" + statement[2]);
}
}
}
return list;
}
示例4: AddDownload
public static void AddDownload(string filename,string path, string date, string size)
{
string path1 = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "User.db");
try
{
using (var connection = new SQLiteConnection(path1))
{
using (var statement = connection.Prepare(@"INSERT INTO DownloadList (FILENAME,PATH,DATE,SIZE)
VALUES(?,?,?,?);"))
{
statement.Bind(1, filename);
statement.Bind(2, path);
statement.Bind(3, date);
statement.Bind(4, size);
// Inserts data.
statement.Step();
statement.Reset();
statement.ClearBindings();
Debug.WriteLine("Download Added");
}
}
}
catch (Exception ex)
{
Debug.WriteLine("Exception\n" + ex.ToString());
}
}
示例5: SqliteInitializationTest
public void SqliteInitializationTest()
{
string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME);
using (SQLiteLocalStorage storage = new SQLiteLocalStorage())
{ }
using (SQLiteConnection connection = new SQLiteConnection(dbPath))
{
var query = "SELECT name FROM sqlite_master WHERE type='table'";
var tableName = new List<string>();
using (var sqliteStatement = connection.Prepare(query))
{
while(sqliteStatement.Step() == SQLiteResult.ROW)
{
tableName.Add(sqliteStatement.GetText(0));
}
}
Assert.IsTrue(tableName.Count == 2);
Assert.IsTrue(tableName.Contains("datasets"));
Assert.IsTrue(tableName.Contains("records"));
}
}
示例6: insertData
public static void insertData(string param1, string param2, string param3)
{
try
{
using (var connection = new SQLiteConnection("Storage.db"))
{
using (var statement = connection.Prepare(@"INSERT INTO Student (ID,NAME,CGPA)
VALUES(?, ?,?);"))
{
statement.Bind(1, param1);
statement.Bind(2, param2);
statement.Bind(3, param3);
// Inserts data.
statement.Step();
statement.Reset();
statement.ClearBindings();
}
}
}
catch(Exception ex)
{
Debug.WriteLine("Exception\n"+ex.ToString());
}
}
示例7: getValues
public static ObservableCollection<Student> getValues()
{
ObservableCollection<Student> list = new ObservableCollection<Student>();
using (var connection = new SQLiteConnection("Storage.db"))
{
using (var statement = connection.Prepare(@"SELECT * FROM Student;"))
{
while (statement.Step() == SQLiteResult.ROW)
{
list.Add(new Student()
{
Id = (string)statement[0],
Name = (string)statement[1],
Cgpa = statement[2].ToString()
});
Debug.WriteLine(statement[0]+" ---"+statement[1]+" ---"+statement[2]);
}
}
}
return list;
}
示例8: WordListDB
public WordListDB()
{
connection_ = new SQLiteConnection(DB_NAME);
using (var statement = connection_.Prepare(SQL_CREATE_TABLE))
{
statement.Step();
}
}
示例9: PlanetaDao
public PlanetaDao(SQLiteConnection con)
{
this.con = con;
string sql = "CREATE TABLE IF NOT EXISTS planeta (id INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT, gravedad FLOAT)";
using (var statement =con.Prepare(sql)) {
statement.Step();
}
}
示例10: FacturaDao
public FacturaDao(SQLiteConnection con)
{
this.con = con;
string sql = "CREATE TABLE IF NOT EXISTS factura (id INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT, vence DATETIME, alarma DATETIME, valor INTEGER, estado TEXT)";
using (var statement = con.Prepare(sql))
{
statement.Step();
}
}
示例11: Cleaup
public void Cleaup()
{
string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME);
//drop all the tables from the db
using (SQLiteConnection connection = new SQLiteConnection(dbPath))
{
using (var sqliteStatement = connection.Prepare("DROP TABLE IF EXISTS records"))
{
var result = sqliteStatement.Step();
}
using (var sqliteStatement = connection.Prepare("DROP TABLE IF EXISTS datasets"))
{
var result = sqliteStatement.Step();
}
}
}
示例12: ResetDataAsync
/// <summary>
/// Metoda czyszcząca bazę danych ze wszystkich informacji.
/// </summary>
/// <param name="db"></param>
/// <returns></returns>
public async static Task ResetDataAsync(SQLiteConnection db)
{
// Empty the Device and Comment tables
string sql = @"DELETE FROM Device";
using (var statement = db.Prepare(sql))
{
statement.Step();
}
sql = @"DELETE FROM Comment";
using (var statement = db.Prepare(sql))
{
statement.Step();
}
}
示例13: WordBookDB
public WordBookDB()
{
mutex_ = new object();
connection_ = new SQLiteConnection(SQL_CREATE_TABLE);
using (var statement = connection_.Prepare(SQL_CREATE_TABLE))
{
statement.Step();
}
}
示例14: OnNavigatedTo
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
try
{
conn = App.conn;
string req = @"Create Table if not exists
User (Id integer primary key autoincrement not null,
Login varchar(50),
Passeword varchar(50)
)";
using (var Statement = conn.Prepare(req))
{
Statement.Step();
}
req = @"select Login from User where Login='Admin'";
using (var Statement = conn.Prepare(req))
{
//if (SQLiteResult.DONE == Statement.Step())
//{
Statement.Step();
if (Statement.DataCount == 0)
{
req = @"insert into User(Login,Passeword) values('Admin','Admin')";
using (var Statement1 = conn.Prepare(req))
{
Statement1.Step();
}
}
//}
}
}
catch (Exception ex)
{
MessageDialog Msg = new MessageDialog(ex.ToString());
await Msg.ShowAsync();
}
}
示例15: LoadDatabase
public static void LoadDatabase()
{
// Get a reference to the SQLite database
conn = new SQLiteConnection("SQLiteTODO.db");
// NOTE - The Id character is actually a GUID which is 36 characters long.
// Here we speacify it as VARCHAR(36) - but actually SQLite does not impose a length
// limit on columns, nor rigidly enforce data types.
// Could have specified CHARACTER(10), VARCHAR(255), TEXT - all would work for a GUID.
// SQLite just stores these as 'TEXT' - see http://www.sqlite.org/datatype3.html#expraff
string sql = @"CREATE TABLE IF NOT EXISTS
ToDoList (Id VARCHAR( 36 ) PRIMARY KEY NOT NULL,
Title VARCHAR( 140 )
);";
using (var statement = conn.Prepare(sql))
{
statement.Step();
}
sql = @"CREATE TABLE IF NOT EXISTS
ToDoItem (Id VARCHAR( 36 ) PRIMARY KEY NOT NULL,
Title VARCHAR( 140 ),
DueDate DATETIME,
Details VARCHAR( 140 ),
IsFavorite BOOLEAN,
IsComplete BOOLEAN,
ListId CHAR( 36 ),
FOREIGN KEY(ListId) REFERENCES ToDoList(Id) ON DELETE CASCADE
)";
using (var statement = conn.Prepare(sql))
{
statement.Step();
}
// Turn on Foreign Key constraints
sql = @"PRAGMA foreign_keys = ON";
using (var statement = conn.Prepare(sql))
{
statement.Step();
}
}