public int DeleteRow(string tableName, SQLiteDB.DB_ConditionPair condition) { if (!this.Exists) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Database does not exists!"); } return(-1); } if (!this.IsTableExists(tableName)) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Table does not exists!"); } return(-1); } if (string.IsNullOrEmpty(condition.fieldName.Trim()) || string.IsNullOrEmpty(condition.value.Trim())) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Wrong condition!"); } return(-1); } int result = -1; try { string commandText = string.Concat(new string[] { "delete from ", tableName, " where ", condition.fieldName, this.GetConditionSymbol(condition.condition), "'", condition.value, "'" }); this.connection.Open(); this.command = this.connection.CreateCommand(); this.command.CommandText = commandText; result = this.command.ExecuteNonQuery(); } catch (Exception ex) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Unable to delete row.\n" + ex.Message); } } finally { this.command.Dispose(); this.connection.Close(); } return(result); }
public DBReader Select(string tableName, List <string> fields, SQLiteDB.DB_ConditionPair condition) { if (!this.Exists) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Database does not exists!"); } return(null); } if (!this.IsTableExists(tableName)) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Table does not exists!"); } return(null); } if (string.IsNullOrEmpty(condition.fieldName.Trim()) || string.IsNullOrEmpty(condition.value.Trim())) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Wrong condition!"); } return(null); } DBReader result = null; try { string text = "select "; for (int i = 0; i < fields.Count; i++) { if (i == fields.Count - 1) { text += fields[i]; } else { text = text + fields[i] + ","; } } text = text + " from " + tableName; string text2 = text; text = string.Concat(new string[] { text2, " where ", condition.fieldName, this.GetConditionSymbol(condition.condition), "'", condition.value, "'" }); this.connection.Open(); this.command = this.connection.CreateCommand(); this.command.CommandText = text; this.reader = this.command.ExecuteReader(); result = new DBReader(this.reader); } catch (Exception ex) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Unable to select data.\n" + ex.Message); } } finally { this.command.Dispose(); this.connection.Close(); } return(result); }
public int Update(string tableName, List <SQLiteDB.DB_DataPair> dataList, SQLiteDB.DB_ConditionPair condition) { if (!this.Exists) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Database does not exists!"); } return(-1); } if (!this.IsTableExists(tableName)) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Table does not exists!"); } return(-1); } if (string.IsNullOrEmpty(condition.fieldName.Trim()) || string.IsNullOrEmpty(condition.value.Trim())) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Wrong condition!"); } return(-1); } int result = -1; try { string text = "update " + tableName + " set "; for (int i = 0; i < dataList.Count; i++) { if (i == dataList.Count - 1) { string text2 = text; text = string.Concat(new string[] { text2, dataList[i].fieldName, "='", dataList[i].value, "' where ", condition.fieldName, this.GetConditionSymbol(condition.condition), "'", condition.value, "'" }); } else { string text2 = text; text = string.Concat(new string[] { text2, dataList[i].fieldName, "='", dataList[i].value, "'," }); } } this.connection.Open(); this.command = this.connection.CreateCommand(); this.command.CommandText = text; result = this.command.ExecuteNonQuery(); } catch (Exception ex) { if (SQLiteEventListener.onErrorInvoker != null) { SQLiteEventListener.onErrorInvoker("Unable to update.\n" + ex.Message); } } finally { this.command.Dispose(); this.connection.Close(); } return(result); }