本文整理汇总了C#中SQLitePCL.SQLiteConnection类的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection类的具体用法?C# SQLiteConnection怎么用?C# SQLiteConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SQLiteConnection类属于SQLitePCL命名空间,在下文中一共展示了SQLiteConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}
示例2: 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;
}
示例3: EnableForeignKeys
private void EnableForeignKeys(SQLiteConnection connection)
{
using (var statement = connection.Prepare(@"PRAGMA foreign_keys = ON;"))
{
statement.Step();
}
}
示例4: 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"));
}
}
示例5: 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();
}
}
示例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: DBHelper
private DBHelper(string sqliteDb)
{
SoupNameToTableNamesMap = new Dictionary<string, string>();
SoupNameToIndexSpecsMap = new Dictionary<string, IndexSpec[]>();
DatabasePath = sqliteDb;
_sqlConnection = (SQLiteConnection) Activator.CreateInstance(_sqliteConnectionType, sqliteDb);
}
示例11: AddFacturaPage
public AddFacturaPage()
{
this.InitializeComponent();
con = new SQLiteConnection(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "FacturasBD.sqlite"));
factDao = new FacturaDao(con);
rootFrame = Window.Current.Content as Frame;
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
SystemNavigationManager.GetForCurrentView().BackRequested += AddFacturaPage_BackRequested;
}
示例12: WordBookDB
public WordBookDB()
{
mutex_ = new object();
connection_ = new SQLiteConnection(SQL_CREATE_TABLE);
using (var statement = connection_.Prepare(SQL_CREATE_TABLE))
{
statement.Step();
}
}
示例13: MainPage
public MainPage()
{
this.InitializeComponent();
con = new SQLiteConnection(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "FacturasBD.sqlite"));
factDao = new FacturaDao(con);
facturas = App.Current.Resources["facturas"] as Facturas;
rootFrame = Window.Current.Content as Frame;
}
示例14: MobileServiceSQLiteStore
/// <summary>
/// Initializes a new instance of <see cref="MobileServiceSQLiteStore"/>
/// </summary>
/// <param name="fileName">Name of the local SQLite database file.</param>
public MobileServiceSQLiteStore(string fileName)
{
if (fileName == null)
{
throw new ArgumentNullException("fileName");
}
this.connection = new SQLiteConnection(fileName);
}
示例15: 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();
}
}