当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteConnection.ExecuteScalar方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:Sylix,项目名称:DataAccess,代码行数:14,代码来源:SQLiteConnector.cs

示例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);
        }
开发者ID:kevingy,项目名称:SQLite.Net-PCL,代码行数:37,代码来源:NullableTest.cs

示例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()");
     }
 }
开发者ID:jkralicky,项目名称:TaskPlanner,代码行数:12,代码来源:DataHandler.cs


注:本文中的SQLiteConnection.ExecuteScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。