• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SQLiteClient.SqliteCommand类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createTable

        public static void createTable(Type ja)
        {
            try
            {
                SqliteCommand sql = new SqliteCommand("DROP TABLE " + ja.Name, SqliteManager.connection);
                sql.ExecuteNonQuery();
            }
            catch (Exception e)
            {
            }
            string tmp = "CREATE TABLE " + ja.Name + "(";
            System.Reflection.FieldInfo[] fieldInfo = ja.GetFields();

            bool was = false;
            string primary = "";
            foreach (System.Reflection.FieldInfo info in fieldInfo)
            {
                Type temp = info.FieldType;
                if (was) tmp += ", ";
                tmp += info.Name + " ";
                was = true;
                if (temp == typeof(long))
                {
                    tmp += " INT";
                }
                else
                    if (temp == typeof(string))
                    {
                        tmp += " TEXT";
                    }
                    else
                        if (temp == typeof(double))
                        {
                            tmp += " REAL";
                        }
                        else
                            if (temp == typeof(bool))
                            {
                                tmp += " INT";
                            }
                            else
                            {
                                tmp += " TEXT";
                            }
                if (info.IsDefined(typeof(PrimaryKey), true))
                {
                    if (primary.Length != 0) primary += ", ";
                    primary += info.Name;
                }
            }
            if (primary.Length > 0)
            {
                tmp += ", PRIMARY KEY(" + primary + ") ";
            }
            tmp += ");";
            SqliteCommand sql2 = new SqliteCommand(tmp, SqliteManager.connection);
            sql2.ExecuteNonQuery();
        }
开发者ID:Xplo1T,项目名称:l2tower-database-repository,代码行数:58,代码来源:AbstractTable.cs


示例2: SqliteDataReader

		internal SqliteDataReader (SqliteCommand cmd, Sqlite3.Vdbe pVm, int version)
		{
			command = cmd;
            rows = new List<object[]>();
            column_names_sens = new Dictionary<String, Object>();
            column_names_insens = new Dictionary<String, Object>( StringComparer.InvariantCultureIgnoreCase );
			closed = false;
			current_row = -1;
			reading = true;
			ReadpVm (pVm, version, cmd);
			ReadingDone ();
		}
开发者ID:Foxbow74,项目名称:my-busycator,代码行数:12,代码来源:SqliteDataReader.cs


示例3: SqliteDataReader

 internal SqliteDataReader(SqliteCommand cmd, Sqlite3.Vdbe pVm, int version)
 {
     command = cmd;
     rows = new ArrayList ();
     column_names_sens = new Hashtable ();
     column_names_insens = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
     closed = false;
     current_row = -1;
     reading = true;
     ReadpVm (pVm, version, cmd);
     ReadingDone ();
 }
开发者ID:taxilian,项目名称:some_library,代码行数:12,代码来源:SqliteDataReader.cs


示例4: CreateHistoryTable

 private void CreateHistoryTable()
 {
     string sql = @"
     CREATE TABLE history (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
     client_id varchar(32) NOT NULL,
     from_jid varchar(3071),
     to_jid varchar(3071),
     timestamp INTEGER NOT NULL,
     message TEXT
     )";
     var command = new SqliteCommand(sql, _connection);
     command.ExecuteNonQuery();
 }
开发者ID:Irdis,项目名称:VSTalk,代码行数:14,代码来源:InitialMS.cs


示例5: get

 internal static Patron get(int patron_id, Community.CsharpSqlite.SQLiteClient.SqliteConnection conn)
 {
     SqliteCommand cmd = new SqliteCommand(
         string.Format("select id, name, type from patron where id = {0}", patron_id), conn);
     SqliteDataReader rdr = cmd.ExecuteReader();
     while (rdr.NextResult())
     {
         OurPatron p = new OurPatron(conn, rdr.GetInt32(0));
         p.name = rdr.GetString(1);
         p.type = (PatronType)rdr.GetInt32(2);
         return p;
     }
     return null;
 }
开发者ID:taxilian,项目名称:some_library,代码行数:14,代码来源:OurPatron.cs


示例6: getAll

        internal static List<Patron> getAll(SqliteConnection conn)
        {
            List<Patron> plist = new List<Patron>();

            SqliteCommand cmd = new SqliteCommand("select id, name, type from patron order by name", conn);
            SqliteDataReader rdr = cmd.ExecuteReader();
            while (rdr.NextResult())
            {
                OurPatron p = new OurPatron(conn, rdr.GetInt32(0));
                p.name = rdr.GetString(1);
                p.type = (PatronType)rdr.GetInt32(2);
                plist.Add(p);
            }

            return plist;
        }
开发者ID:taxilian,项目名称:some_library,代码行数:16,代码来源:OurPatron.cs


示例7: SqliteDataReader

		internal SqliteDataReader (SqliteCommand cmd, Sqlite3.Vdbe pVm, int version)
		{
			command = cmd;
			rows = new ArrayList ();
			column_names_sens = new Hashtable ();
#if NET_2_0
			column_names_insens = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
#else
			column_names_insens = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
							     CaseInsensitiveComparer.DefaultInvariant);
#endif
			closed = false;
			current_row = -1;
			reading = true;
			ReadpVm (pVm, version, cmd);
			ReadingDone ();
		}
开发者ID:Orvid,项目名称:SQLInterfaceCollection,代码行数:17,代码来源:SqliteDataReader.cs


示例8: CreateVcard

 private void CreateVcard()
 {
     string sql = @"
     CREATE TABLE contact_details (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
     jid varchar(2048) NOT NULL,
     hash varchar(2048) NOT NULL,
     fullname varchar(2048) NULL,
     url varchar(2048) NULL,
     birthday INTEGER NULL,
     details TEXT NULL,
     photoType varchar(2048) NULL,
     photoBin BLOB NULL
     );
     CREATE INDEX IX_contact_details ON contact_details(jid, hash)
     ";
     var command = new SqliteCommand(sql, _connection);
     command.ExecuteNonQuery();
 }
开发者ID:Irdis,项目名称:VSTalk,代码行数:19,代码来源:Migration2.cs


示例9: CreateDiscoCache

 private void CreateDiscoCache()
 {
     string sql = @"
     CREATE TABLE caps_info (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
     node varchar(2048) NULL,
     version varchar(2048) NULL,
     hash varchar(2048) NULL
     );
     CREATE TABLE feature (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
     uri varchar(2048) UNIQUE NOT NULL
     );
     CREATE TABLE caps_to_feature (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
     caps_info_id int NOT NULL,
     feature_id int NOT NULL,
     FOREIGN KEY (caps_info_id) REFERENCES caps_info(id),
     FOREIGN KEY (feature_id) REFERENCES feature(id)
     )";
     var command = new SqliteCommand(sql, _connection);
     command.ExecuteNonQuery();
 }
开发者ID:Irdis,项目名称:VSTalk,代码行数:23,代码来源:Migration1.cs


示例10: Select

 /// <summary>
 /// Select a single result using the passed in value to formulate a query.
 /// </summary>
 /// <param name="statement"></param>
 /// <returns></returns>
 public Model.Item Select(String statement)
 {
     Open();
     Model.Item result = null;
     try
     {
         SqliteCommand cmd = new SqliteCommand(statement, db);
         SqliteDataReader reader = cmd.ExecuteReader();  //all rows exist in this object only right now
         
         while (reader.Read())
         {
             //value 0 = id
             //value 1 = name
             //value 2 = html
             result = new Model.Item((int)reader.GetValue(0), (string)reader.GetValue(1), (string)reader.GetValue(2));
         }
     }
     catch (SqliteExecutionException ee)
     {
         System.Windows.MessageBox.Show("Error while querying Database: \n" + ee.Message + "\n" + ee.StackTrace);
     }
     catch (SqliteSyntaxException se)
     {
         System.Windows.MessageBox.Show("Error while querying Database: \n" + se.Message + "\n" + se.StackTrace);
     }
     catch (ArgumentException ae)
     {
         System.Windows.MessageBox.Show("Error while adding value to list: \n" + ae.Message + "\n" + ae.StackTrace);
     }
     finally
     {
         Close();
     }
     
     return result;
 }
开发者ID:Frannsoft,项目名称:dnd35encyclopedia,代码行数:41,代码来源:DBHelper.cs


示例11: CreateTable

        public override void CreateTable(string table, ColumnDefinition[] columns, IndexDefinition[] indexDefinitions)
        {
            if (TableExists(table))
            {
                MainConsole.Instance.WarnFormat("[SQLite]: Trying to create a table '{0}' that already exists.", table);
                return;
            }

            IndexDefinition primary = null;
            foreach (IndexDefinition index in indexDefinitions)
            {
                if (index.Type == IndexType.Primary)
                {
                    primary = index;
                    break;
                }
            }

            List<string> columnDefinition = new List<string>();

            bool has_auto_increment = false;
            foreach (ColumnDefinition column in columns)
            {
                has_auto_increment |= column.Type.auto_increment;
                columnDefinition.Add(column.Name + " " + GetColumnTypeStringSymbol(column.Type));
            }
            if (!has_auto_increment && primary != null && primary.Fields.Length > 0)
            {
                columnDefinition.Add("PRIMARY KEY (" + string.Join(", ", primary.Fields) + ")");
            }

            var cmd = new SqliteCommand 
                            {
                                CommandText = 
                                    string.Format ("create table " + table + " ({0})",
                                    string.Join (", ", columnDefinition.ToArray ()))
                            };
            try {
                ExecuteNonQuery (cmd);
            } catch (SqliteException e) {
                MainConsole.Instance.Error ("[Sqlite]: Create table (" + table + "), " + e);
            }
            CloseReaderCommand(cmd);

            if (indexDefinitions.Length >= 1 && (primary == null || indexDefinitions.Length >= 2))
            {
                columnDefinition = new List<string>(primary != null ? indexDefinitions.Length : indexDefinitions.Length - 1);
                    // reusing existing variable for laziness
                uint i = 0;
                foreach (IndexDefinition index in indexDefinitions)
                {
                    if (index.Type == IndexType.Primary || index.Fields.Length < 1)
                    {
                        continue;
                    }

                    i++;
                    columnDefinition.Add("CREATE " + (index.Type == IndexType.Unique ? "UNIQUE " : string.Empty) +
                                         "INDEX idx_" + table + "_" + i + " ON " + table + "(" +
                                         string.Join(", ", index.Fields) + ")");
                }
                foreach (string query in columnDefinition)
                {
                    cmd = new SqliteCommand
                              {
                                  CommandText = query
                              };
                    try {
                    ExecuteNonQuery(cmd);
                    } catch (SqliteException e) {
                        MainConsole.Instance.Error ("[Sqlite]: Create index (" + query + "), " + e);
                    }

                    CloseReaderCommand(cmd);
                }
            }
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:77,代码来源:SQLiteDataManager.cs


示例12: Delete

        public override bool Delete(string table, QueryFilter queryFilter)
        {
            Dictionary<string, object> ps = new Dictionary<string, object>();
            string query = "DELETE FROM " + table +
                           (queryFilter != null ? (" WHERE " + queryFilter.ToSQL(':', out ps)) : "");

            SqliteCommand cmd = new SqliteCommand(query);
            AddParams(ref cmd, ps);
            try
            {
                ExecuteNonQuery(cmd);
            }
            catch (Exception e)
            {
                MainConsole.Instance.Error("[Sqlite]: Delete(" + query + "), " + e);
                return false;
            }
            CloseReaderCommand(cmd);
            return true;
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:20,代码来源:SQLiteDataManager.cs


示例13: Insert

        public override bool Insert(string table, object[] values, string updateKey, object updateValue)
        {
            var cmd = new SqliteCommand();
            Dictionary<string, object> ps = new Dictionary<string, object>();

            string query;
            query = string.Format("insert into {0} values (", table);
            int i = 0;
            foreach (object value in values)
            {
                ps[":" + Util.ConvertDecString(i)] = value;
                query = string.Format(query + ":{0},", Util.ConvertDecString(i++));
            }
            query = query.Remove(query.Length - 1);
            query += ")";
            cmd.CommandText = query;
            AddParams(ref cmd, ps);
            try
            {
                ExecuteNonQuery(cmd);
                CloseReaderCommand(cmd);
            }
                //Execute the update then...
            catch (Exception)
            {
                cmd = new SqliteCommand();
                query = string.Format("UPDATE {0} SET {1} = '{2}'", table, updateKey, updateValue);
                cmd.CommandText = query;
                ExecuteNonQuery(cmd);
                CloseReaderCommand(cmd);
            }
            return true;
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:33,代码来源:SQLiteDataManager.cs


示例14: InsertOrReplace

        bool InsertOrReplace(string table, Dictionary<string, object> row, bool insert)
        {
            SqliteCommand cmd = new SqliteCommand();
            string query = (insert ? "INSERT" : "REPLACE") + " INTO " + table + " (" +
                           string.Join(", ", row.Keys.ToArray ()) + ")";
            List<string> ps = new List<string>();
            foreach (KeyValuePair<string, object> field in row)
            {
                string key = ":" + field.Key.Replace("`", "");
                ps.Add(key);
                AddParam(ref cmd, key, field.Value);
            }
            query += " VALUES( " + string.Join(", ", ps.ToArray<string>()) + " )";

            cmd.CommandText = query;
            try
            {
                ExecuteNonQuery(cmd);
            }
            catch (Exception e)
            {
                MainConsole.Instance.Error("[Sqlite]: " + (insert ? "Insert" : "Replace") + "(" + query + "), " + e);
            }
            CloseReaderCommand(cmd);
            return true;
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:26,代码来源:SQLiteDataManager.cs


示例15: CreateNewCommand

		private void CreateNewCommand (ref SqliteCommand command)
                {
                        SqliteCommand sourceCommand = SourceCommand;
                        if (command == null) {
                                command = sourceCommand.Connection.CreateCommand () as SqliteCommand;
                                command.CommandTimeout = sourceCommand.CommandTimeout;
                                command.Transaction = sourceCommand.Transaction;
                        }
                        command.CommandType = CommandType.Text;
                        command.UpdatedRowSource = UpdateRowSource.None;
                        command.Parameters.Clear ();
                }
开发者ID:Orvid,项目名称:SQLInterfaceCollection,代码行数:12,代码来源:SqliteCommandBuilder.cs


示例16: PrepReader

        protected void PrepReader(ref SqliteCommand cmd)
        {
            int retries = 0;
            restart:
            try
            {
                SqliteConnection connection = new SqliteConnection(m_connectionString);
                connection.Open();
                cmd.Connection = connection;
            }

            catch (SqliteBusyException ex)
            {
                if (retries++ > 5)
                    MainConsole.Instance.WarnFormat("[Sqlite]: Exception processing command: {0}, Exception: {1}",
                                            cmd.CommandText, ex);
                else
                    goto restart;
            }
            catch (SqliteException ex)
            {
                MainConsole.Instance.WarnFormat("[Sqlite]: Exception processing command: {0}, Exception: {1}",
                                        cmd.CommandText, ex);
            }
            catch (Exception ex)
            {
                MainConsole.Instance.WarnFormat("[Sqlite]: Exception processing command: {0}, Exception: {1}",
                                        cmd.CommandText, ex);
            }
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:30,代码来源:SQLiteDataManager.cs


示例17: CloseReaderCommand

 protected void CloseReaderCommand(SqliteCommand cmd)
 {
     cmd.Connection.Close();
     cmd.Parameters.Clear();
     cmd.Dispose ();                 // previously commented but this is a resource leak if not cleared out - greythane - 20160427
 }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:6,代码来源:SQLiteDataManager.cs


示例18: UpdateTable

        public override void UpdateTable(string table, ColumnDefinition[] columns, IndexDefinition[] indexDefinitions,
                                         Dictionary<string, string> renameColumns)
        {
            if (!TableExists(table))
            {
                MainConsole.Instance.WarnFormat ("[SQLite]: Trying to update a table {0} that does not exist.", table);
                return;
            }

            List<ColumnDefinition> oldColumns = ExtractColumnsFromTable(table);

            Dictionary<string, ColumnDefinition> sameColumns = new Dictionary<string, ColumnDefinition>();
            foreach (ColumnDefinition column in oldColumns)
            {
                if (columns.Any(innercolumn => innercolumn.Name.ToLower() == column.Name.ToLower() ||
                                               renameColumns.ContainsKey(column.Name) &&
                                               renameColumns[column.Name].ToLower() == innercolumn.Name.ToLower()))
                {
                    sameColumns.Add(column.Name, column);
                }
            }

            string renamedTempTableColumnDefinition = string.Empty;
            string renamedTempTableColumn = string.Empty;

            foreach (ColumnDefinition column in oldColumns)
            {
                if (renamedTempTableColumnDefinition != string.Empty)
                {
                    renamedTempTableColumnDefinition += ", ";
                    renamedTempTableColumn += ", ";
                }
                renamedTempTableColumn += column.Name;
                renamedTempTableColumnDefinition += column.Name + " " + GetColumnTypeStringSymbol(column.Type);
            }

            var cmd = new SqliteCommand
                          {
                              CommandText =
                                  "CREATE TABLE " + table + "__temp(" + renamedTempTableColumnDefinition + ");"
                          };
            try {
                ExecuteNonQuery(cmd);
            } catch (SqliteException e) {
                MainConsole.Instance.Error ("[Sqlite]: Create temporary table, " + e);
            }
            CloseReaderCommand(cmd);

            cmd = new SqliteCommand
                      {
                          CommandText =
                              "INSERT INTO " + table + "__temp SELECT " + renamedTempTableColumn + " from " + table +
                              ";"
                      };
            try {
                ExecuteNonQuery(cmd);
            } catch (SqliteException e) {
                MainConsole.Instance.Error ("[Sqlite]: Copy to tempory table, " + e);
            }
            CloseReaderCommand(cmd);

            cmd = new SqliteCommand
                      {
                          CommandText = "drop table " + table
                      };
            try {
                ExecuteNonQuery(cmd);
            } catch (SqliteException e) {
                MainConsole.Instance.Error ("[Sqlite]: Drop table, " + e);
            }
            CloseReaderCommand(cmd);

            List<string> newTableColumnDefinition = new List<string>(columns.Length);

            IndexDefinition primary = null;
            foreach (IndexDefinition index in indexDefinitions)
            {
                if (index.Type == IndexType.Primary)
                {
                    primary = index;
                    break;
                }
            }

            bool has_auto_increment = false;
            foreach (ColumnDefinition column in columns)
            {
                has_auto_increment |= column.Type.auto_increment;
                newTableColumnDefinition.Add(column.Name + " " + GetColumnTypeStringSymbol(column.Type));
            }
            if (!has_auto_increment && primary != null && primary.Fields.Length > 0)
            {
                newTableColumnDefinition.Add("PRIMARY KEY (" + string.Join(", ", primary.Fields) + ")");
            }

            cmd = new SqliteCommand
                      {
                          CommandText =
                              string.Format("create table " + table + " ({0}) ",
                                            string.Join(", ", newTableColumnDefinition.ToArray()))
//.........这里部分代码省略.........
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:101,代码来源:SQLiteDataManager.cs


示例19: UnescapeSql

 static void UnescapeSql(SqliteCommand cmd)
 {
     foreach (SqliteParameter v in cmd.Parameters)
     {
         if (v.Value == null)
             v.Value = "";
         
         if (v.Value.ToString().Contains("\\'"))
             v.Value = v.Value.ToString().Replace("\\'", "\'");
         
         if (v.Value.ToString().Contains("\\\""))
             v.Value = v.Value.ToString().Replace("\\\"", "\"");
        
     }
 }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:15,代码来源:SQLiteDataManager.cs


示例20: ExecuteNonQuery

 // TODO: As all exceptions apper to be caught here the ExecuteNonQuery() calls probably 
 // do not need to be in try/catch 's
 protected int ExecuteNonQuery(SqliteCommand cmd)
 {
     int retries = 0;
     restart:
     try
     {
         lock (GetLock())
         {
             PrepReader(ref cmd);
             UnescapeSql(cmd);
             var value = cmd.ExecuteNonQuery();
             cmd.Connection.Close();
             return value;
         }
     }
     catch (SqliteBusyException ex)
     {
         if (retries++ > 5)
             MainConsole.Instance.WarnFormat("[Sqlite]: Exception processing command: {0}, Exception: {1}",
                                     cmd.CommandText, ex);
         else
             goto restart;
         return 0;
     }
     catch (SqliteException ex)
     {
         MainConsole.Instance.WarnFormat("[Sqlite]: Exception processing command: {0}, Exception: {1}",
                                 cmd.CommandText, ex);
     }
     catch (Exception ex)
     {
         MainConsole.Instance.WarnFormat("[Sqlite]: Exception processing command: {0}, Exception: {1}",
                                 cmd.CommandText, ex); 
     }
     return 0;
 }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:38,代码来源:SQLiteDataManager.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SQLiteClient.SqliteConnection类代码示例发布时间:2022-05-24
下一篇:
C# CsharpSqlite.sqlite3_mutex类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap