Ejemplo n.º 1
0
        /// <summary>
        /// 保存日志到数据库
        /// </summary>
        private void SaveLogToDB()
        {
            while (true)
            {
                Thread.Sleep(500);
                if (_logList.Count > 0)
                {
                    lock (logB)
                    {
                        string conStr = LogSQL.GetConnectString();
                        using (SQLiteConnection conn = new SQLiteConnection(conStr))
                        {
                            conn.Open();

                            using (SQLiteCommand cmd = conn.CreateCommand())
                            {
                                foreach (LogData data in _logList)
                                {
                                    if (LogSQL.ExecuteNonQuery(cmd, LOGTABLE.GetTableInsertSQL(data)) == -1)
                                    {
                                        _errorList.Add(data);
                                    }
                                }
                                _logList.Clear();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在数据库初次创建的时候创建表
        /// </summary>
        internal static void InitCreateTables()
        {
            using (SQLiteConnection con = new SQLiteConnection())
            {
                con.ConnectionString = GetConnectString();

                con.Open();
                using (SQLiteCommand cmd = con.CreateCommand())
                {
                    foreach (int type in Enum.GetValues(typeof(LOGTYPE)))
                    {
                        cmd.CommandText = LOGTABLE.GetTableCreateSQL(type);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }