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


C# Sqlite.SqliteCommand类代码示例

本文整理汇总了C#中Mono.Data.Sqlite.SqliteCommand的典型用法代码示例。如果您正苦于以下问题:C# SqliteCommand类的具体用法?C# SqliteCommand怎么用?C# SqliteCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Init

        public static void Init(string databaseFullPath)
        {
            try
            {
                if (!File.Exists(databaseFullPath))
                {
                    throw new Exception("Could not find the cards database.");
                }

                _cards = new Dictionary<int, NamedCard>();

                using (SqliteConnection connection = new SqliteConnection("Data Source=" + databaseFullPath))
                {
                    connection.Open();

                    using (IDbCommand command = new SqliteCommand(
                        "SELECT datas.id, ot, alias, setcode, type, level, race, attribute, atk, def, texts.name, texts.desc"
                        + " FROM datas INNER JOIN texts ON datas.id = texts.id",
                        connection))
                    {
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                LoadCard(reader);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not initialize the cards database. Check the inner exception for more details.", ex);
            }
        }
开发者ID:mycard,项目名称:ygosharp,代码行数:35,代码来源:NamedCardsManager.cs

示例2: DoNonQuery

		public static int DoNonQuery (SqliteConnection connection, string command_text, string[] param_names, object[] param_args)
		{
			int ret = 0;

			using (SqliteCommand command = new SqliteCommand ()) {
				command.Connection = connection;
				command.CommandText = command_text;

				if (param_names != null) {
					if (param_args == null || param_names.Length != param_args.Length)
						throw new ArgumentException ("param_names, param_args", "param_names and param_args should have same number of items");
					for (int i = 0; i < param_names.Length; ++i)
						command.Parameters.AddWithValue (param_names [i], param_args [i]);
				}

				while (true) {
					try {
						ret = command.ExecuteNonQuery ();
						break;
					} catch (SqliteException e) {
						if (e.ErrorCode == SQLiteErrorCode.Busy) {
							Thread.Sleep (50);
						} else {
							throw;
						}
					} catch (Exception e) {
						Log.Error (e, "SQL that caused the exception: {0}", command_text);
						throw;
					}
				}
			}

			return ret;
		}
开发者ID:zweib730,项目名称:beagrep,代码行数:34,代码来源:SqliteUtils.cs

示例3: Init

        public static void Init()
        {
            try
            {
                _cards = new Dictionary<int, CardData>();

                string currentPath = Assembly.GetExecutingAssembly().Location;
                currentPath = Path.GetDirectoryName(currentPath) ?? "";
                string absolutePath = Path.Combine(currentPath, "cards.cdb");

                if (!File.Exists(absolutePath))
                {
                    throw new Exception("Could not find the cards database.");
                }

                using (SqliteConnection connection = new SqliteConnection("Data Source=" + absolutePath))
                {
                    connection.Open();

                    const string select =
                        "SELECT datas.id, alias, type, level, race, attribute, atk, def, name, desc " +
                        "FROM datas INNER JOIN texts ON datas.id = texts.id";

                    using (SqliteCommand command = new SqliteCommand(select, connection))
                    using (SqliteDataReader reader = command.ExecuteReader())
                        InitCards(reader);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not initialize the cards database. Check the inner exception for more details.", ex);
            }
        }
开发者ID:Tic-Tac-Toc,项目名称:windbot,代码行数:33,代码来源:CardsManager.cs

示例4: GetAllCategories

        /// <summary>
        /// Returns all categories.
        /// </summary>
        public IEnumerable<Category> GetAllCategories()
        {
            var categories = new List<Category>();

            using (var connection = new SqliteConnection("Data Source=" + dbPath))
            using (var query = new SqliteCommand("SELECT * FROM Categories", connection))
            {
                connection.Open();

                var reader = query.ExecuteReader(CommandBehavior.CloseConnection);

                while (reader.Read())
                {
                    var category = new Category();
                    category.Id = int.Parse(reader["id"].ToString());
                    category.Name = reader ["name"].ToString();

                    categories.Add(category);
                }

                reader.Close();
            }

            return categories;
        }
开发者ID:CayasSoftware,项目名称:RSSReader,代码行数:28,代码来源:CategoryRepository.cs

示例5: NonQuery

 public void NonQuery( string cmdstr )
 {
     using (var cmd = new SqliteCommand( con )) {
         cmd.CommandText = cmdstr;
         cmd.ExecuteNonQuery();
     }
 }
开发者ID:Money520,项目名称:XR.Baboon,代码行数:7,代码来源:CodeRecordData.cs

示例6: DateTimeConvert

		public void DateTimeConvert ()
		{
			var dateTime = new DateTime (2016, 9, 15, 12, 1, 53);
			var guid = Guid.NewGuid ();

			using (var connection = new SqliteConnection ("Data Source=" + _databasePath)) {
				connection.Open ();

				var sqlCreate = "CREATE TABLE TestTable (ID uniqueidentifier PRIMARY KEY, Modified datetime)";
				using (var cmd = new SqliteCommand (sqlCreate, connection)) {
					cmd.ExecuteNonQuery ();
				}

				var sqlInsert = "INSERT INTO TestTable (ID, Modified) VALUES (@id, @mod)";
				using (var cmd = new SqliteCommand (sqlInsert, connection)) {
					cmd.Parameters.Add (new SqliteParameter ("@id", guid));
					cmd.Parameters.Add (new SqliteParameter ("@mod", dateTime));
					cmd.ExecuteNonQuery ();
				}
			}

			using (var connection = new SqliteConnection ("Data Source=" + _databasePath)) {
				connection.Open ();

				var sqlSelect = "SELECT * from TestTable";
				using (var cmd = new SqliteCommand (sqlSelect, connection))
				using (var reader = cmd.ExecuteReader ()) {
					while (reader.Read ()) {
						Assert.AreEqual (guid, reader.GetGuid (0), "#1");
						Assert.AreEqual (dateTime, reader.GetDateTime (1), "#2");
					}
				}
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:34,代码来源:SqliteTests.cs

示例7: ExecuteStringCommand

        public static List<string[]> ExecuteStringCommand(SqliteCommand command, int columncount)
        {
            try
            {
            var values = new List<string[]>();
            SqliteDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                var row = new List<string>();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    row.Add(reader[i].ToString());
                }
                values.Add(row.ToArray());
            }
            reader.Close();
            return values;

            }
            catch (Exception ex)
            {
            MessageBox.Show(ex.Message);
            return new List<string[]>();
            }
        }
开发者ID:salvadorc17,项目名称:YGOPRO-Tools,代码行数:25,代码来源:DatabaseHelper.cs

示例8: UpdateOrders

    public void UpdateOrders()
    {
        MainClass.StatusMessage("Получаем таблицу заказов...");

        string sql = "SELECT orders.id, orders.customer, orders.contract, orders.address, orders.phone1, orders.phone2, orders.arrval, orders.deadline_s, orders.deadline_e FROM orders ";
        SqliteCommand cmd = new SqliteCommand(sql, (SqliteConnection) QSMain.ConnectionDB);

        using(SqliteDataReader rdr = cmd.ExecuteReader())
        {
            OrdersListStore.Clear();
            while (rdr.Read())
            {
                OrdersListStore.AppendValues(rdr.GetInt32(rdr.GetOrdinal("id")),
                    rdr["customer"].ToString(),
                    rdr["contract"].ToString(),
                    rdr["phone1"].ToString() + rdr["phone2"].ToString(),
                    rdr["address"].ToString(),
                    String.Format("{0:d}", rdr["arrval"]),
                    DateWorks.GetDateRangeText(DBWorks.GetDateTime(rdr, "deadline_s", new DateTime()), DBWorks.GetDateTime(rdr, "deadline_e", new DateTime()))
                );
            }

        }
        MainClass.StatusMessage("Ok");
    }
开发者ID:QualitySolution,项目名称:CupboardDesigner,代码行数:25,代码来源:MainWinOrders.cs

示例9: GetAllFeeds

        /// <summary>
        /// Returns all subscribed feeds.
        /// </summary>
        public IEnumerable<Feed> GetAllFeeds()
        {
            var feeds = new List<Feed>();

            using (var connection = new SqliteConnection("Data Source=" + dbPath))
            using (var query = new SqliteCommand("SELECT * FROM Feeds", connection))
            {
                connection.Open();

                var reader = query.ExecuteReader(CommandBehavior.CloseConnection);

                while (reader.Read())
                {
                    var feed = new Feed();
                    feed.Id = int.Parse(reader["id"].ToString());
                    feed.Name = reader ["name"].ToString();
                    feed.Url = reader ["url"].ToString();
                    feed.LastUpdated = DateTime.Parse (reader ["LastUpdated"].ToString ());
                    feed.CategoryId = int.Parse(reader["categoryId"].ToString());

                    feeds.Add(feed);
                }

                reader.Close();
            }

            return feeds;
        }
开发者ID:CayasSoftware,项目名称:RSSReader,代码行数:31,代码来源:FeedRepository.cs

示例10: Fill

        public void Fill(int id)
        {
            ItemId = id;
            NewItem = false;

            MainClass.StatusMessage(String.Format ("Запрос выставки №{0}...", id));
            string sql = "SELECT exhibition.* FROM exhibition WHERE exhibition.id = @id";
            try
            {
                SqliteCommand cmd = new SqliteCommand(sql, (SqliteConnection) QSMain.ConnectionDB);

                cmd.Parameters.AddWithValue("@id", id);

                using(SqliteDataReader rdr = cmd.ExecuteReader())
                {
                    rdr.Read();

                    labelID.Text = rdr["id"].ToString();
                    entryName.Text = rdr["name"].ToString();
                    entryPhone1.Text = DBWorks.GetString(rdr, "phone", "");
                    entryPhone2.Text = DBWorks.GetString(rdr, "phone2", "");
                    textAddress.Buffer.Text = DBWorks.GetString(rdr, "address", "");
                }

                MainClass.StatusMessage("Ok");
                this.Title = entryName.Text;
            }
            catch (Exception ex)
            {
                QSMain.ErrorMessageWithLog(this, "Ошибка получения информации о номенклатуре!", logger, ex);
            }
            TestCanSave();
        }
开发者ID:QualitySolution,项目名称:CupboardDesigner,代码行数:33,代码来源:Exhibition.cs

示例11: GetAll

 public IList<SyncItem> GetAll()
 {
     List<SyncItem> returnData = new List<SyncItem>();
     using (var conn = _provider.GetConnection())
     {
         conn.Open();
         using (SqliteCommand command =
             new SqliteCommand(
                 string.Format(
                     @"SELECT Id, FileKey, CloudAssetId,
         CloudLastUpdatedDate, CloudCreatedDate, IsDeleted,
         Size FROM {0}", SyncItem.TableName), conn))
         {
             var reader = command.ExecuteReader();
             while (reader.Read())
             {
                 SyncItem item = new SyncItem();
                 item.Id = reader.GetInt32(0);
                 item.FileKey = reader.GetString(1);
                 item.CloudAssetId = reader.GetString(2);
                 item.CloudLastUpdated = new DateTime(reader.GetInt64(3));
                 item.CloudCreated = new DateTime(reader.GetInt64(4));
                 item.IsDeleted = reader.GetBoolean(5);
                 returnData.Add(item);
             }
         }
         conn.Close();
     }
     return returnData;
 }
开发者ID:KalliopeMedia,项目名称:KalliopeSync,代码行数:30,代码来源:SyncItemServices.cs

示例12: GUIhosts

        public GUIhosts(GUImain gui, SqliteConnection connection, SqliteCommand command)
        {
            InitializeComponent();
            InitializeList();

            this.gui = gui;
            _connection = connection;
            _command = command;

            using (_command = new SqliteCommand("SELECT host, port, password FROM hosts ORDER BY id DESC", _connection))
            {

                using (SqliteDataReader reader = _command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        String host = gui.GetSafeString(reader, 0);
                        String port = gui.GetSafeString(reader, 1);
                        String password = gui.GetSafeString(reader, 2);

                        String[] items = { host, port, password };
                        ListViewItem item = new ListViewItem(items);
                        list.Items.Add(item);
                    }
                }
            }
        }
开发者ID:DomiStyle,项目名称:DaRT,代码行数:27,代码来源:GUIhosts.cs

示例13: addRow

    void addRow(string sName, string sNote)
    {
        SqliteCommand cmd=new SqliteCommand(con);
        cmd.CommandText=
            string.Format("Insert into Cars (id,name,note) VALUES(NULL,'{0}','{1}');",
                          sName,sNote);
        da.InsertCommand=cmd;
        da.InsertCommand.ExecuteNonQuery();

        DataTable dt = ds.Tables[0];
        DataRow dr = dt.NewRow();
        dr["name"]=sName;
        dr["note"]=sNote;
        dr["id"]=getNewID();
        dt.Rows.Add(dr);

        System.Console.WriteLine(da.InsertCommand.CommandText);

        dt.AcceptChanges();
        ds.AcceptChanges();

        da.Update(dt);

        doRefresh();
    }
开发者ID:hjgode,项目名称:mail_grabber,代码行数:25,代码来源:MForm.cs

示例14: Create

		public void Create()
		{
			try {
				if(File.Exists(dbPath)) {
					cnn.Dispose();
					// We want to start with a fresh db for each full run
					// The database is created on the first open()
					File.Delete(dbPath);
				}
			}
			catch(Exception e) {
				throw e;
			}

			try {
				using (var createCommand = new SqliteCommand ("CREATE TABLE Company (RecordId int, Name text);", cnn))
				using (var insertCommand = new SqliteCommand ("INSERT INTO Company VALUES (1, 'Test CO')", cnn)) {
					cnn.Open();
					createCommand.ExecuteNonQuery();
					insertCommand.ExecuteNonQuery();
				}
			}
			catch(Exception e) {
				Console.WriteLine (e);
				throw new AssertionException ("Create table failed", e);
			}
			finally {
				cnn.Close();  
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:30,代码来源:Bug27864.cs

示例15: MakeSureTableExists

		private void MakeSureTableExists()
		{
			using (SqliteCommand sqc = new SqliteCommand(connection)) {
				sqc.CommandText = "CREATE TABLE IF NOT EXISTS `Files` (`id` INTEGER NOT NULL PRIMARY KEY, `path` TEXT NOT NULL, `changedate` INTEGER NOT NULL, `size` INTEGER NOT NULL, `hash` TEXT NOT NULL)";
				sqc.ExecuteNonQuery();
			}
		}
开发者ID:SmartFire,项目名称:IntelliSync,代码行数:7,代码来源:Snapshot.cs


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