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


C# SQLiteConnection.ExecuteScalar方法代码示例

本文整理汇总了C#中SQLite.SQLiteConnection.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.ExecuteScalar方法的具体用法?C# SQLiteConnection.ExecuteScalar怎么用?C# SQLiteConnection.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQLite.SQLiteConnection的用法示例。


在下文中一共展示了SQLiteConnection.ExecuteScalar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: App

        public App()
        {
            // The root page of your application
            MainPage = new ContentPage {
                Content = new StackLayout {
                    VerticalOptions = LayoutOptions.Center,
                    Children = {
                        new Label {
                            XAlign = TextAlignment.Center,
                            Text = "Welcome to Xamarin Forms!"
                        }
                    }
                }
            };

            // path to db
            var path = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "mydb");

            // open connection and attempt to apply encryption using PRAGMA statement
            var conn = new SQLiteConnection (path);
            conn.Execute ("PRAGMA key = 'passme'");
            int v = conn.ExecuteScalar<int> ("SELECT count(*) FROM sqlite_master");
            conn.Close ();

            // open another connection, this time use wrong password. It will still open, but should fail the
            // query (see docs on key PRAGMA https://www.zetetic.net/sqlcipher/sqlcipher-api/)
            var conn2 = new SQLiteConnection (path);
            conn2.Execute ("PRAGMA key = 'wrongpassword'");
            int v2 = conn2.ExecuteScalar<int> ("SELECT count(*) FROM sqlite_master");
            conn2.Close ();
        }
开发者ID:chriswjones,项目名称:sqlite-net-cipher-poc,代码行数:31,代码来源:SnowReport.cs

示例2: FootballPlayer

 public FootballPlayer()
 {
     database = DependencyService.Get<MySqlConn> ().getConnection ();
     var count = database.ExecuteScalar<int> ("SELECT Count(*) FROM FootballPlayer");
     if (count == 0) {
         database.CreateTable<FootballPlayer> ();
     }
 }
开发者ID:CTS458641,项目名称:cts458701,代码行数:8,代码来源:FootballPlayer.cs

示例3: isTableExisting

		private static bool isTableExisting(string strTblName){
			try{
				var connection = new SQLiteConnection(path);
				var count = connection.ExecuteScalar<int>("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='" + strTblName + "'");
				if(count > 0){
					return true;
				}else{
					return false;
				}
			}catch(SQLiteException){
				return false;
			}
		}
开发者ID:jejeboom,项目名称:Cebuanizer,代码行数:13,代码来源:Database.cs

示例4: MapServiceSQLite

        public MapServiceSQLite()
        {
            using (SQLiteConnection connection = new SQLiteConnection(SQLiteConfiguration.ConnectionString))
            {
                connection.CreateTable<MapModel>();
                if (connection.ExecuteScalar<int>("SELECT COUNT(*) FROM Maps") == 0)
                    connection.RunInTransaction(() =>
                    {
                        connection.Insert(new MapModel(Guid.NewGuid(), "Default Map", @"ms-appx:///MetroExplorer.Components.Maps/DesignAssets/MapBackground.bmp"));
                    });

                connection.CreateTable<MapLocationModel>();
                connection.CreateTable<MapLocationFolderModel>();
            }
        }
开发者ID:CasaTeam,项目名称:MetroExplorer,代码行数:15,代码来源:MapServiceSQLite.cs

示例5: clickFoodDialogList

        private void clickFoodDialogList(object sender, DialogClickEventArgs args)
        {
            listChoice = choices [args.Which];

            Console.WriteLine ("Selected: {0}", args.Which);

            // Open a confirmation alert
            AlertDialog.Builder confirmFoodDialogBuilder = new AlertDialog.Builder(this);
            confirmFoodDialogBuilder.SetTitle ("Confirm selection");

            confirmFoodDialogBuilder.SetMessage ("You are adding the following choice: " +
            listChoice + ".  Do you wish to proceed?");

            // Insert the selection into the database on confirmation
            confirmFoodDialogBuilder.SetPositiveButton ("Confirm", delegate {
                dismissAddFoodDialog ();

                LogEntry newLog = new LogEntry {
                    LoggedAt = DateTime.Now,
                    Level = LogEntry.MapToLevel(args.Which)
                };

                using (var db = new SQLiteConnection(dbPath)) {
                    db.Insert (newLog);
                    var count = db.ExecuteScalar<int> ("Select COUNT(*) from LogEntry");
                    Console.WriteLine("There are now {0} Log Entries", count);
                }
            });

            // Close all alerts if the user cancels at this point
            confirmFoodDialogBuilder.SetNegativeButton ("Cancel", delegate {
                dismissAddFoodDialog ();
            });

            confirmFoodDialog = confirmFoodDialogBuilder.Create ();
            confirmFoodDialog.Show ();
        }
开发者ID:jbuckle,项目名称:shamely,代码行数:37,代码来源:MainActivity.cs

示例6: OnCreate


//.........这里部分代码省略.........
                                    {
                                        try
                                        {
                                            var sql = "delete from PERSON";
                                            int oldDataCount = conn.Execute(sql);
                                            new AlertDialog.Builder(this).SetMessage(string.Format("旧数据有{0}条", oldDataCount)).Show();

                                            sql = "DROP TABLE [PERSON];";
                                            conn.Execute(sql);
                                            sql = @"CREATE TABLE [PERSON] (
                                          [ID] nvarchar(2147483647) NOT NULL
                                        , [NAME] nvarchar(2147483647) NULL
                                        , [DEPARTMENT] nvarchar(2147483647) NULL
                                        , [MOBILE_PHONE] nvarchar(2147483647) NULL
                                        , [VIRTUAL_PHONE] nvarchar(2147483647) NULL
                                        , [POSITION] nvarchar(2147483647) NULL
                                        , [REGION] nvarchar(2147483647) NULL
                                        , [OFFICE_PHONE] nvarchar(2147483647) NULL
                                        , [INNER_PHONE] nvarchar(2147483647) NULL
                                        , [PY] nvarchar(2147483647) NULL
                                        , [CAR] nvarchar(2147483647) NULL
                                        , CONSTRAINT [sqlite_autoindex_PERSON_1] PRIMARY KEY ([ID])
                                        );";
                                            conn.Execute(sql);

                                            conn.BeginTransaction();
                                            conn.InsertAll(personList);

                                            textViewCurrentVersion.Text = textViewLatestVersion.Text;
                                            editor.PutString("version", textViewCurrentVersion.Text);
                                            editor.Commit();

                                            sql = "select count(ID) from PERSON";
                                            int newDataCount = conn.ExecuteScalar<int>(sql);
                                            new AlertDialog.Builder(this).SetMessage(string.Format("新数据有{0}条", newDataCount)).Show();

                                            conn.Commit();

                                            new AlertDialog.Builder(this).SetMessage("更新完毕").SetPositiveButton("确定", delegate
                                                {
                                                }).Show();

                                        }
                                        catch (Exception ex)
                                        {
                                            conn.Rollback();
                                            new AlertDialog.Builder(this).SetMessage(ex.Message).Show();
                                        }
                                    }
                                }
                            }
                        }

                    }
                    else
                    {
                        new AlertDialog.Builder(this).SetMessage("无需更新").Show();
                    }

                }
                catch (System.Exception ex)
                {
                    new AlertDialog.Builder(this).SetMessage(ex.Message).Show();
                }
                finally
                {
开发者ID:kidfruit,项目名称:WisdriContacts,代码行数:67,代码来源:Update.cs

示例7: ScalarQuery

		public static string ScalarQuery () 
		{
			var output = "";
			output += "\nScalar query example: ";
			string dbPath = Path.Combine (
				Environment.GetFolderPath (Environment.SpecialFolder.Personal), "ormdemo.db3");
			
			var db = new SQLiteConnection (dbPath);
			
			var rowcount = db.ExecuteScalar<int> ("SELECT COUNT(*) FROM [Items] WHERE Symbol <> ?", "MSFT");

			output += "\nNumber of rows : " + rowcount;

			return output;
		}
开发者ID:ARMoir,项目名称:mobile-samples,代码行数:15,代码来源:OrmExample.cs

示例8: getCurrentSig

 private static string getCurrentSig(SQLiteConnection db)
 {
     string json = db.ExecuteScalar<string>("SELECT v FROM t$v WHERE k=10");
         return DependencyService.Get<ISHA1Service>().HashString(json);
 }
开发者ID:KennyDeblaere,项目名称:Burocenter,代码行数:5,代码来源:ZagDebugSchemaVersionCheck.cs

示例9: open_and_load_zumero

        private static SQLiteConnection open_and_load_zumero(string s)
        {
            // open the local SQLite db
            SQLiteConnection db = new SQLiteConnection(s);

            // tell SQLite to allow load_extension()
            db.EnableLoadExtension(1);

            // load the Zumero extension
            // this is the equivalent of ".load zumero.dylib" in the sqlite3 shell
            db.ExecuteScalar<string>("SELECT load_extension('zumero.dylib');");

            return db;
        }
开发者ID:paulroub,项目名称:z_rss,代码行数:14,代码来源:z_rss_sync.cs

示例10: do_feeds

        private static void do_feeds(SQLiteConnection db, List<feed_row> rows)
        {
            foreach (feed_row q in rows)
            {
                string dbfile_name_for_this_feed = string.Format("feed_{0}", q.feedid);
                Console.WriteLine("Updating {0}: {1}", dbfile_name_for_this_feed, q.url);
                SyndicationFeed f = null;

                try
                {
                    XmlReader xr = new XmlTextReader(q.url);
                    f = SyndicationFeed.Load(xr);
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0}", e);
                    // TODO failed trying to retrieve or parse this feed.
                    // TODO log the failure?
                    // TODO delete the feed row?
                    // TODO launch nethack?
                }

                if (f != null)
                {
                    db.Execute("ATTACH ? AS cur;", dbfile_name_for_this_feed);

                    bool found = false;

                    var query = "pragma cur.table_info(\"items\")";
                    List<SQLiteConnection.ColumnInfo> cols = db.Query<SQLiteConnection.ColumnInfo> (query);

                    foreach (var c in cols) {
                        found = (string.Compare ("permalink", c.Name, StringComparison.OrdinalIgnoreCase) == 0);
                        if (found)
                            break;
                    }

                    if (! found)
                    {
                        db.Execute("BEGIN TRANSACTION;");
                        db.ExecuteScalar<string>(@"select zumero_alter_table_add_column('cur', 'items', 'permalink TEXT');");
                        db.Execute("COMMIT TRANSACTION;");

                        // after altering a zumero table, the dbfile connection must be reopened

                        db.Execute("DETACH cur;", dbfile_name_for_this_feed);
                        db.Execute("ATTACH ? AS cur;", dbfile_name_for_this_feed);
                    }

                    db.Execute("BEGIN TRANSACTION;");

                    // set last_update to the time we retrieved the feed XML

                    db.Execute(
                            @"INSERT OR REPLACE
                            INTO main.last_update
                            (feedid, when_unix_time)
                            VALUES
                            (?, strftime('%s','now')
                            );",
                            q.feedid);

                    foreach (SyndicationItem it in f.Items)
                    {
                        Console.WriteLine("    {0}", it.Title.Text);

                        TextSyndicationContent t = (TextSyndicationContent) it.Summary;

                        if (null == t)
                            t = (TextSyndicationContent)it.Content;

                        string id = it.Id;
                        string url = null;

                        foreach(SyndicationLink link in it.Links)
                        {
                            url = link.Uri.ToString();
                            break;
                        }

                        if (null == id)
                            id = url;

                        if (null == url)
                            url = id;

                        if (null == id)
                        {
                            Console.WriteLine("        no id");
                        }
                        else
                        {
                            db.Execute("INSERT OR IGNORE INTO cur.items (id, title, summary, pubdate_unix_time, permalink) VALUES (?,?,?,?,?)",
                                    id,
                                    it.Title.Text,
                                    t.Text,
                                    (it.PublishDate.UtcDateTime - new DateTime(1970,1,1)).TotalSeconds,
                                    url
                                    );
                        }
//.........这里部分代码省略.........
开发者ID:paulroub,项目名称:z_rss,代码行数:101,代码来源:z_rss_update.cs

示例11: do_feeds

        private static void do_feeds(SQLiteConnection db, List<feed_row> rows)
        {
            foreach (feed_row q in rows)
            {
                string dbfile_name_for_this_feed = string.Format("feed_{0}", q.feedid);
                Console.WriteLine("Creating {0}: {1}", dbfile_name_for_this_feed, q.url);

                SyndicationFeed f = null;

                try
                {
                    XmlReader xr = new XmlTextReader(q.url);
                    f = SyndicationFeed.Load(xr);
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0}", e);
                    // TODO failed trying to retrieve or parse this feed.
                    // TODO log the failure?
                    // TODO delete the feed row?
                    // TODO launch nethack?
                }

                if (f != null)
                {
                    db.Execute("ATTACH ? AS cur;", dbfile_name_for_this_feed);

                    db.Execute("BEGIN TRANSACTION;");

                    db.Execute(
                            @"CREATE VIRTUAL TABLE
                            cur.items
                            USING zumero
                            (
                              id TEXT PRIMARY KEY NOT NULL,
                              title TEXT NOT NULL,
                              summary TEXT NOT NULL,
                              pubdate_unix_time INTEGER NOT NULL,
                              permalink TEXT
                            );"
                            );

                    // each feed is allowed to be pulled by anyone, but only the admin user
                    // can make changes

                    db.ExecuteScalar<string>(
                            @"SELECT zumero_define_acl_table('cur');"
                            );

                    db.Execute(
                            @"INSERT INTO cur.z_acl
                            (scheme,who,tbl,op,result)
                            VALUES (
                                '',
                                zumero_named_constant('acl_who_anyone'),
                                '',
                                '*',
                                zumero_named_constant('acl_result_deny')
                            );"
                            );

                    db.Execute(
                            @"INSERT INTO cur.z_acl
                            (scheme,who,tbl,op,result)
                            VALUES (
                                zumero_internal_auth_scheme('zumero_users_admin'),
                                zumero_named_constant('acl_who_any_authenticated_user'),
                                '',
                                '*',
                                zumero_named_constant('acl_result_allow')
                            );"
                            );

                    db.Execute(
                            @"INSERT INTO cur.z_acl
                            (scheme,who,tbl,op,result)
                            VALUES (
                                '',
                                zumero_named_constant('acl_who_anyone'),
                                '',
                                zumero_named_constant('acl_op_pull'),
                                zumero_named_constant('acl_result_allow')
                            );"
                            );

                    // set the feed title

                    db.Execute("INSERT INTO main.about (feedid, title) VALUES (?,?)",
                            q.feedid,
                            f.Title.Text
                            );

                    db.Execute("COMMIT TRANSACTION;");

                    db.Execute("DETACH cur;");
                }
            }
        }
开发者ID:paulroub,项目名称:z_rss,代码行数:98,代码来源:z_rss_create.cs

示例12: getCoins

		public static int getCoins(){
			try
			{
				var db = new SQLiteConnection(path);

				return db.ExecuteScalar<int>("SELECT CoinsCount FROM Coins WHERE ID = 1");
			}
			catch (SQLiteException)
			{
				return 0;
			}
		}
开发者ID:jejeboom,项目名称:Cebuanizer,代码行数:12,代码来源:Database.cs

示例13: getRandomTip

		public static string getRandomTip(){
			try
			{
				var db = new SQLiteConnection(path);

				string tip = db.ExecuteScalar<string>("SELECT TipPhrase FROM Tip WHERE ID = " + Convert.ToString(new System.Random().Next(12) + 1));

				if(string.IsNullOrEmpty(tip)){
					tip = "0 returned";
				}
				return tip;
			}
			catch (SQLiteException ex)
			{
				return ex.Message ;
			}
		}
开发者ID:jejeboom,项目名称:Cebuanizer,代码行数:17,代码来源:Database.cs

示例14: get_total_records

 //------------------------------------------------------------------------//
 //used for debugging purposes
 public int get_total_records()
 {
     try
     {
         var db = new SQLiteConnection(m_db_path);
         // this counts all records in the database, it can be slow depending on the size of the database
         var count = db.ExecuteScalar<int>("SELECT Count(*) FROM ShopItem");
         return count;
     }
     catch (SQLiteException ex)
     {
         Console.WriteLine("get total records has failed, ex.msg :{0}",ex.Message);
         return -1;
     }
 }
开发者ID:winifredrayen,项目名称:commondepot,代码行数:17,代码来源:DBHelper.cs

示例15: FetchStatsFromDate

		double FetchStatsFromDate (SQLiteConnection connection, DateTime dt)
		{
			return connection.ExecuteScalar<double> (SumQuery, dt.ToUniversalTime ());
		}
开发者ID:nagyist,项目名称:bikr,代码行数:4,代码来源:DataApi.cs


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