public void SetString(string tableName, string key, string value) { try { СonnectToDatabase(); _sqlBuilder.Append($"INSERT INTO '{ tableName }' ({ key }) VALUES ('{ value }')"); SQLiteCommand command = new SQLiteCommand(_sqlBuilder.ToString(), m_dbConnection); command.ExecuteNonQuery(); DisconnectFromDatabase(); } catch (Exception ex) { InformationCollector.Error(tableName, ex.Message); } }
public static List <string> ReadFileToArray(string path, bool encoding = false) { List <string> result = new List <string>(); try { StreamReader fs = new StreamReader(path, (!encoding) ? System.Text.Encoding.GetEncoding(1251) : System.Text.Encoding.GetEncoding(65001)); string line = fs.ReadLine(); while (line != null) { result.Add(line); line = fs.ReadLine(); } fs.Close(); } catch (Exception e) { InformationCollector.Error("ReadFileToArray", e.Message); } return(result); }
public List <string> GetList(string tableName, string returnField, List <string> filerList = null) { try { var list = new List <string>(); СonnectToDatabase(); _sqlBuilder.Append($"SELECT * FROM '{ tableName }'"); if (filerList != null) { foreach (var filter in filerList) { _sqlBuilder.Append($" { WhereOrAnd() } { filter }"); } } SQLiteCommand command = new SQLiteCommand(_sqlBuilder.ToString(), m_dbConnection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (reader[returnField] != null) { list.Add(reader[returnField].ToString()); } } return(list); } catch (Exception ex) { InformationCollector.Error(tableName, ex.Message); return(new List <string>()); } finally { DisconnectFromDatabase(); } }
public List <string> GetTables() { try { СonnectToDatabase(); DataTable schema = m_dbConnection.GetSchema("Tables"); DisconnectFromDatabase(); List <string> tableNames = new List <string>(); foreach (DataRow row in schema.Rows) { tableNames.Add(row[2].ToString()); } return(tableNames); } catch (Exception ex) { InformationCollector.Error(string.Empty, ex.Message); return(new List <string>()); } }
public string GetBoltunData(Mode mode, string str, string table, string like = null) { try { СonnectToDatabase(); switch (mode) { case Mode.NOLIKE: _sqlBuilder.Append("SELECT * FROM '" + table + "' WHERE q='" + str + "'"); break; case Mode.RANDOM: _sqlBuilder.Append("SELECT * FROM '" + table + "' ORDER BY RANDOM() LIMIT 1"); break; case Mode.LIKE: _sqlBuilder.Append("SELECT * FROM '" + table + "' WHERE 'q' LIKE '%" + like + "%'"); break; default: break; } InformationCollector.Log("ConnectionToSQL\nstr: " + str + "\ntable: " + table + "\nlike: " + like); SQLiteCommand command = new SQLiteCommand(_sqlBuilder.ToString(), m_dbConnection); SQLiteDataReader reader = command.ExecuteReader(); List <string> answers = new List <string>(); int i = 0; reader.Read(); InformationCollector.Log("ConnectionToSQL\nreader.GetString(1): " + reader.GetString(1)); while (reader.GetString(1) != string.Empty) { answers.Add(reader.GetString(1)); i++; reader.Read(); } if (i == 1) { return(answers[0]); } else if (i > 1) { return(answers[RNG.Next(0, i)]); } else { return(string.Empty); } } catch (Exception ex) { InformationCollector.Error(table, ex.Message); return(string.Empty); } finally { DisconnectFromDatabase(); } }