本文整理汇总了C#中SQLiteConnection.Query方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Query方法的具体用法?C# SQLiteConnection.Query怎么用?C# SQLiteConnection.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.Query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteItem
public string DeleteItem(int itemId)
{
string result = string.Empty;
using (var dbConn = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
{
var existingItem = dbConn.Query<Media>("select * from Media where Id =" + itemId).FirstOrDefault();
if (existingItem != null)
{
dbConn.RunInTransaction(() =>
{
dbConn.Delete(existingItem);
if (dbConn.Delete(existingItem) > 0)
{
result = "Success";
}
else
{
result = "This item was not removed";
}
});
}
return result;
}
}
示例2: Select
private static List<Trk> Select(String sql, params object[] args)
{
String path = SQLiteService.DBLocation;
using (SQLiteConnection conn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
{
var res = conn.Query<Trk>(sql, args);
return res;
}
}
示例3: Delete
public void Delete(int Number)
{
var sqlPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "StudentDB.sqlite");
using (SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), sqlPath))
{
var existingconact = conn.Query<Student>("select * from Students where Number =" + Number).FirstOrDefault();
if (existingconact != null)
{
conn.RunInTransaction(() =>
{
conn.Delete(existingconact);
});
}
}
}
示例4: Update
public void Update(Student student)
{
var sqlPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "StudentDB.sqlite");
using (SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), sqlPath))
{
var existingStudent = conn.Query<Student>("select * from Students where Number =" + student.Number).FirstOrDefault();
if (existingStudent != null)
{
existingStudent.Name = student.Name;
existingStudent.Number = student.Number;
existingStudent.Department = student.Department;
conn.RunInTransaction(() =>
{
conn.Update(existingStudent);
});
}
}
}
示例5: SampleData
/// <summary>
/// Generating sample data.
/// </summary>
public async Task<bool> SampleData()
{
await DropAndCreateDatabase();
using (var dbConn = new SQLiteConnection(new SQLitePlatformWinRT(), App.DbPath))
{
//create user
var user = GetUser("[email protected]", "Jey");
dbConn.Insert(user);
//create myOwnWord
var mow = GetMyOwnWord(user.UserID, "Man", "Muž, Chlap");
dbConn.Insert(mow);
//create second myOwnWord
var mow2 = GetMyOwnWord(user.UserID, "Hello", "Ahoj");
dbConn.Insert(mow2);
//create 10 photos belongs to mow
for (int i = 0; i < 10; i++)
{
dbConn.Insert(GetPhoto(mow.MyOwnWordID));
}
//create 5 recordings belongs to mow
for (int i = 0; i < 5; i++)
{
dbConn.Insert(GetRecording(mow.MyOwnWordID));
}
//create sentence belongs to mow
dbConn.Insert(GetSentence(mow.MyOwnWordID, "This man is amazing!"));
dbConn.Insert(GetSentence(mow2.MyOwnWordID, "Hello my love :-*"));
MowListItem item = new MowListItem();
var listItems = dbConn.Query<MowListItem>("select * from vw_mowlist");
}
return true;
}
示例6: fillDataGrid
private int fillDataGrid(int country_id, int city_id, SQLiteConnection conn)
{
dgResult.ItemsSource = conn.Query<UserResult>("SELECT 'User'.'firstName', 'User'.'lastName', 'Sex'.'title' as 'sex', 'User'.'bDate', 'Country'.'title' as 'country', 'City'.'title' as 'city', 'User'.'mobilePhone', printf('http://vk.com/id%d','User'.'id') AS 'pageAddress' FROM ((('User' JOIN 'Country' ON 'User'.'countryId' = 'Country'.'id') JOIN 'City' ON 'User'.'cityId' = 'City'.'id') JOIN 'Sex' ON 'User'.'sexId' = 'Sex'.'id') WHERE 'User'.'countryId' = ? AND 'User'.'cityId' = ?", country_id, city_id)
.Where(v => (tbAge.Text == "" ? true : Math.Floor(((DateTime.Now - v.bDate).TotalDays / 365.25)) == Int32.Parse(tbAge.Text)));
return dgResult.Items.Count;
}
示例7: CreateTestData
static void CreateTestData (SQLiteConnection db)
{
var js = new MeasurementSubjectModel () { Name = "JS"};
if (db.Table<MeasurementSubjectModel> ().Count (c => c.Name == "JS") == 0) {
db.Insert (js);
} else {
js = db.Table<MeasurementSubjectModel> ().Where (w => w.Name == "JS").FirstOrDefault ();
}
var jsProfile = new ProfileModel () { MeasurementSubjectId = js.Id};
var jp = db.Query<ProfileModel> ("SELECT P.* FROM ProfileModel as P JOIN MeasurementSubjectModel AS s ON p.MeasurementSubjectId == s.Id WHERE s.Name == ?", "JS");
if(jp.Count == 0) {
db.Insert (jsProfile);
var v = new ProfileMeasurementDefinitionModel () {
MeasurementFrequencyId = 3,
MeasurementDefinitionId = 1,
ProfileId = jsProfile.Id,
MeasureTypeId = 2
};
db.Insert (v);
db.Insert(new ProfileMeasurementDefinitionModel () {
MeasurementFrequencyId = 4 ,
MeasurementDefinitionId = 2 ,
ProfileId = jsProfile.Id,
MeasureTypeId = 7
});
db.Insert (new ProfileMeasurementDefinitionModel () {
MeasurementFrequencyId = 3 ,
MeasurementDefinitionId = 3 ,
ProfileId = jsProfile.Id,
MeasureTypeId = 2
});
} else {
jsProfile = jp.FirstOrDefault ();
db.GetChildren (jsProfile, true);
}
var stella = new MeasurementSubjectModel () { Name = "Stella" };
if (db.Table<MeasurementSubjectModel> ().Count (c => c.Name == "Stella") == 0) {
db.Insert (stella);
}else {
stella = db.Table<MeasurementSubjectModel> ().Where (w => w.Name == "Stella").FirstOrDefault ();
}
var stellaProfile = new ProfileModel () { MeasurementSubjectId = stella.Id };
var sp = db.Query<ProfileModel> ("SELECT P.* FROM ProfileModel as P JOIN MeasurementSubjectModel AS s ON p.MeasurementSubjectId == s.Id WHERE s.Name == ?", "Stella");
if(sp.Count == 0) {
db.Insert (stellaProfile);
var v = new ProfileMeasurementDefinitionModel () {
MeasurementFrequencyId = 3,
MeasurementDefinitionId = 1,
ProfileId = stellaProfile.Id,
MeasureTypeId = 2
};
var c = db.Insert (v);
db.Insert(new ProfileMeasurementDefinitionModel () {
MeasurementFrequencyId = 4 ,
MeasurementDefinitionId = 2 ,
ProfileId = stellaProfile.Id,
MeasureTypeId = 7
});
db.Insert (new ProfileMeasurementDefinitionModel () {
MeasurementFrequencyId = 3 ,
MeasurementDefinitionId = 3 ,
ProfileId = stellaProfile.Id,
MeasureTypeId = 2
});
} else {
stellaProfile = sp.FirstOrDefault ();
db.GetChildren (stellaProfile, true);
}
var isabelle = new MeasurementSubjectModel () { Name = "Isabelle" };
if (db.Table<MeasurementSubjectModel> ().Count (c => c.Name == "Isabelle") == 0) {
db.Insert (isabelle);
}else {
isabelle = db.Table<MeasurementSubjectModel> ().Where (w => w.Name == "Isabelle").FirstOrDefault ();
}
var jsBloodPressure = new MeasurementInstanceModel () {DateRecorded = DateTime.Now, MeasurementSubjectId = js.Id, MeasurementDefinitionId = 1 };
var jsBloodPressure2 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-1), MeasurementSubjectId = js.Id, MeasurementDefinitionId = 1 };
var jsBloodPressure3 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-2), MeasurementSubjectId = js.Id, MeasurementDefinitionId = 1 };
if (db.Table<MeasurementInstanceModel> ().Count (w => w.MeasurementSubjectId == js.Id && w.MeasurementDefinitionId == 1) == 0) {
db.Insert (jsBloodPressure);
db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBloodPressure.Id, MeasurementGroupDefinitionId = 1, UnitId = 1, Value = 120 });
//.........这里部分代码省略.........
示例8: SetShowCompleteTasks
/// <summary>
/// Sets the visibility mode for complete tasks
/// </summary>
/// <param name="newValue">Show complete tasks</param>
public static void SetShowCompleteTasks(bool newValue)
{
using (SQLiteConnection db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath))
{
db.Query<Settings>($"update Settings set Value = '{newValue}' where Key = 'ShowCompleteTasks'");
}
}
示例9: SetTaskSortMode
/// <summary>
/// Sets the task sort mode
/// </summary>
/// <param name="sortMode">Sort mode</param>
public static void SetTaskSortMode(string sortMode)
{
using (SQLiteConnection db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath))
{
db.Query<Settings>($"update Settings set Value = '{sortMode}' where Key = 'TaskSortMode';");
}
}
示例10: RemoveClass
/// <summary>
/// Removes a class
/// </summary>
/// <param name="classId">ID of class to remove</param>
public static void RemoveClass(int classId)
{
using (SQLiteConnection db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath))
{
db.Query<Task>($"delete from Task where ClassId = {classId};");
db.Query<Class>($"delete from Class where Id = {classId};");
}
}
示例11: RemoveTask
/// <summary>
/// Removes a task
/// </summary>
/// <param name="taskId">ID of task to remove</param>
public static void RemoveTask(int taskId)
{
using (SQLiteConnection db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath))
{
db.Query<Task>($"delete from Task where Id = {taskId};");
}
}
示例12: GetTaskSortMode
/// <summary>
/// Gets the task sort mode
/// </summary>
/// <returns>String sort mode</returns>
public static string GetTaskSortMode()
{
using (SQLiteConnection db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath))
{
return db.Query<Settings>("select * from Settings where Key = 'TaskSortMode' limit 1")[0].Value;
}
}
示例13: EditClass
/// <summary>
/// Edits a class
/// </summary>
/// <param name="classId">Class ID to edit</param>
/// <param name="properyName">Property to edit</param>
/// <param name="newValue">New value to replace</param>
public static void EditClass(int classId, string properyName, object newValue)
{
using (SQLiteConnection db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath))
{
db.Query<Class>($"update Class set {properyName} = '{newValue}' where Id = {classId};");
}
}
示例14: GetTasks
/// <summary>
/// Returns a list of tasks given a class ID
/// </summary>
/// <param name="classId">Class ID</param>
/// <returns>List of tasks in that class</returns>
public static List<Task> GetTasks(int classId)
{
using (SQLiteConnection db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath))
{
return db.Query<Task>($"select * from Task where ClassId = {classId};");
}
}
示例15: DapperTransaction
public void DapperTransaction()
{
using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
conn.Execute(@"create table Test (Id integer primary key, String text); insert into Test(Id, String) values(1, 'one'), (2, 'two'), (3, 'three');", transaction: trans);
trans.Commit();
}
var results = conn.Query<long>("select Id from Test where length(String) = @len", new { len = 3 }).ToList();
CollectionAssert.AreEqual(new long[] { 1, 2 }, results);
}
}