由于C#是半路出家,对QQLite 的开发更是零基础,只有官方文档可以参考。刚开始的时候 存储没有考虑便利性,都是使用 MysqL 保存在服务端,因为要求用户安装插件的同时在本地安装MysqL 数据库不太现实。但是这种做法明显是不合理的。
后来做一个简单的插件的时候,就采用sqlite 来存储在本地,也最终实现成功
主要步骤:
(1)引用QQLite下面的Library 目录下的System.data.sqlite
(2)
sqliteConnection m_dbConnection;
string db_name = "./QQ/" + this.robot_qq + "/DataBase/zhongmeng_speak_controller_part.db";
bool db_file_exist = File.Exists(db_name);
m_dbConnection = new sqliteConnection("Data Source=" + db_name + ";Version=3;");
m_dbConnection.Open();
string extend_id = label_extend_id.Text.ToString();
string select_cluster_cfg = "select * from cluster_speak_period where cluster_id=" + extend_id + ";";
plugin.OnLog("select_cluster_cfg:" + select_cluster_cfg);
sqliteCommand commond_select = new sqliteCommand(select_cluster_cfg,m_dbConnection);
sqliteDataReader reader = commond_select.ExecuteReader();
string record_cluster_id = ""; string record_cluster_name = ""; string record_period1 = ""; string record_period2 = ""; string record_period3 = ""; string record_period4 = ""; while (reader.Read()) { record_cluster_id = reader["cluster_id"].ToString(); record_cluster_name = reader["cluster_name"].ToString(); record_period1 = reader["period_1"].ToString(); record_period2 = reader["period_2"].ToString(); record_period3 = reader["period_3"].ToString(); record_period4 = reader["period_4"].ToString(); } if (record_cluster_id == "") { //不存在 插入记录 string insert_cluster_cfg = "insert into cluster_speak_period(cluster_id,cluster_name,period_1,period_2,period_3,period_4)" + "values(" + extend_id + ",\"" + label_cluster_name.Text + "\",\"" + period1 + "\",\"" + period2 + "\",\"" + period3 + "\",\"" + period4 + "\");"; plugin.OnLog("insert_cluster_cfg:" + insert_cluster_cfg); sqliteCommand insert_cluster_cfg_commond = new sqliteCommand(insert_cluster_cfg,m_dbConnection); insert_cluster_cfg_commond.ExecuteNonQuery(); } else { string update_cluster_cfg = "update cluster_speak_period set period_1=\"" + period1 + "\",period_2=\"" + period2 + "\",period_3=\"" + period3 + "\",period_4=\"" + period4 + "\" where cluster_id= " + extend_id + ";"; plugin.OnLog("update_cluster_cfg:" + update_cluster_cfg); sqliteCommand update_cluster_cfg_commond = new sqliteCommand(update_cluster_cfg,m_dbConnection); update_cluster_cfg_commond.ExecuteNonQuery(); } m_dbConnection.Close();