本文整理汇总了C#中SQLiteConnection.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.ExecuteScalar方法的具体用法?C# SQLiteConnection.ExecuteScalar怎么用?C# SQLiteConnection.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.ExecuteScalar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public static DatabaseState Connect(ISQLitePlatform platform, string databasePath)
{
try
{
Connection = new SQLiteConnection(platform, databasePath, storeDateTimeAsTicks:false);
return Connection.ExecuteScalar<int>(@"select count(*) from sqlite_master") == 0 ? DatabaseState.Empty : DatabaseState.NotEmpty;
}
catch (Exception)
{
Connection = null;
return DatabaseState.Invalid;
}
}
示例2: NullableScalarInt
public void NullableScalarInt()
{
var db = new SQLiteConnection(new SQLitePlatformTest(), TestPath.GetTempFileName());
db.CreateTable<NullableIntClass>();
var withNull = new NullableIntClass
{
NullableInt = null
};
var with0 = new NullableIntClass
{
NullableInt = 0
};
var with1 = new NullableIntClass
{
NullableInt = 1
};
var withMinus1 = new NullableIntClass
{
NullableInt = -1
};
db.Insert(withNull);
db.Insert(with0);
db.Insert(with1);
db.Insert(withMinus1);
var actualShouldBeNull = db.ExecuteScalar<int?>("select NullableInt from NullableIntClass order by ID limit 1");
var actualShouldBe0 = db.ExecuteScalar<int?>("select NullableInt from NullableIntClass order by ID limit 1 offset 1");
var actualShouldBe1 = db.ExecuteScalar<int?>("select NullableInt from NullableIntClass order by ID limit 1 offset 2");
var actualShouldBeMinus1 = db.ExecuteScalar<int?>("select NullableInt from NullableIntClass order by ID limit 1 offset 3");
Assert.AreEqual(null, actualShouldBeNull);
Assert.AreEqual(0, actualShouldBe0);
Assert.AreEqual(1, actualShouldBe1);
Assert.AreEqual(-1, actualShouldBeMinus1);
}
示例3: AddTask
/// <summary>
/// Adds a new task to the database using a Task object
/// </summary>
/// <param name="t">Task object to add</param>
public static long AddTask(Task t)
{
using (SQLiteConnection db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath))
{
db.Insert(t);
return db.ExecuteScalar<long>("select last_insert_rowid()");
}
}