wenxiangchao
4 天以前 559890c482f5973f06aafdfec9550fee5ba3c7f2
HMI.Core/Util/Sqlite3Helper.cs
@@ -11,6 +11,8 @@
        private string ConnectString = string.Empty;
        public const int MAX_ATTACHED = 30;
        private SQLiteConnection conn = null;
        public Sqlite3Helper(string DBFile)
@@ -52,6 +54,46 @@
            }
        }
        public long InsertWithId(string Sql)
        {
            try
            {
                if (Sql.EndsWith(";"))
                {
                    Sql += "SELECT last_insert_rowid();";
                }
                else
                {
                    Sql += ";SELECT last_insert_rowid();";
                }
                using (var cmd = new SQLiteCommand(Sql, conn))
                {
                    return (long)cmd.ExecuteScalar();
                }
            }
            catch (Exception ex)
            {
                string message = "ExecuteSql Error:" + ex.Message;
                throw new Exception(message);
            }
        }
        public object SelectOne(string Sql)
        {
            try
            {
                using (var cmd = new SQLiteCommand(Sql, conn))
                {
                    return cmd.ExecuteScalar();
                }
            }
            catch (Exception ex)
            {
                string message = "ExecuteSql Error:" + ex.Message;
                throw new Exception(message);
            }
        }
        public int ExecuteBatch(IEnumerable<string> sqls)
        {
            SQLiteTransaction tr = null;