public QueryResult Update(string table, string[] columns, object[] arguments, string where) { QueryResult result = QueryResult.Default; try { MySqlCommand command = connection.CreateCommand(); String sql = GenerateUpdate(table, columns, arguments, where); command.CommandText = sql; result = new QueryResult(command.ExecuteNonQuery()); return result; } catch (Exception ex) { result = new QueryResult(ex); } return result; }
public QueryResult IsInTable(String table, String column, String compareColumn, Object value) { QueryResult result = QueryResult.Default; try { String c = ""; if (value is String) c = "'"; MySqlCommand command = connection.CreateCommand(); String sql = String.Format("SELECT {0} FROM {1} WHERE {2} = {3}{4}{5};", column, table, compareColumn, c, value, c); command.CommandText = sql; var reader = command.ExecuteReader( CommandBehavior.SingleResult ); bool hasRows = reader.HasRows; result = new QueryResult(0, hasRows, false, null); reader.Close(); } catch (Exception ex) { result = new QueryResult(ex); } return result; }
public QueryResult TableExists(String table) { QueryResult result = QueryResult.Default; try { MySqlCommand command = connection.CreateCommand(); String sql = String.Format("SHOW TABLES LIKE '{0}';",table); command.CommandText = sql; var reader = command.ExecuteReader(CommandBehavior.SingleResult); bool hasRows = reader.HasRows; result = new QueryResult(0, hasRows, false, null); reader.Close(); } catch (Exception ex) { result = new QueryResult(ex); } return result; }
public QueryResult ExecuteSQL(String sql) { QueryResult result = QueryResult.Default; try { connection = new MySqlConnection(conString); connection.Open(); MySqlCommand command = connection.CreateCommand(); command.CommandText = sql; result = new QueryResult(command.ExecuteNonQuery()); } catch { } return result; }