public virtual System.Data.DataTable getFiltered(String tableName, filtering.BaseFilter filter = null, filtering.Sort sort = null, filtering.Paging page = null) { throw new NotImplementedException("Must override the getFiltered function"); }
protected String buildFilter(filtering.BaseFilter filter) { String sql = ""; if (filter is filtering.Filter) { filtering.Filter f = filter as filtering.Filter; sql += "(" + buildFilter(f.RHS); sql += convertOperator(f.Operator); sql += buildFilter(f.LHS) + ")"; } else if (filter is filtering.FilterExpression) { filtering.FilterExpression fe = filter as filtering.FilterExpression; sql += "(" + fe.ColumnName + convertOperator(fe.Operator, fe.Value) + ")"; } return(sql); }
public override System.Data.DataTable getFiltered(String tableName, filtering.BaseFilter filter = null, filtering.Sort sort = null, filtering.Paging page = null) { int status = -1; System.Data.DataTable results = new System.Data.DataTable(); MySql.Data.MySqlClient.MySqlConnection dbConn = this.ConnectAsync() as MySql.Data.MySqlClient.MySqlConnection; if (dbConn != null && dbConn.State == System.Data.ConnectionState.Open) { String sql = ""; try { sql = "Select * from `" + tableName + "` "; // build filter if (filter != null) { sql += " Where " + buildFilter(filter); } // build sort if (sort != null) { sql += " ORDER BY " + buildSort(sort); } // build paging if (page != null) { sql += " LIMIT " + buildPaging(page); } var cmd = dbConn.CreateCommand(); cmd.CommandText = sql; results = parseResults(cmd.ExecuteReader()); status = 0; } catch (Exception ex) { if (m_DebugInfo) { Console.WriteLine("Error [{0}]: {1}", tableName, ex.Message); } status = -2; } finally { if (dbConn != null) { try { dbConn.Close(); } finally { dbConn.Dispose(); } } } decrementOpenConnections(); } return(results); }