/// <summary> /// Returns a dataset which contains data specified in the criteria query /// </summary> /// <param name="criteria">QueryCriteria based upon which the data is selected</param> /// <returns>DataSet containing the selected data</returns> public DataSet GetDataSet(QueryCriteria criteria) { IQueryCriteriaGenerator iql = null; DataFactory factory = new DataFactory(); iql = factory.InitializeQueryCriteriaGenerator(database); DataSet dsTemp = null; ExecutionQuery selectQuery = iql.GenerateSelect(criteria); //check for session if (contextSession != null) { dsTemp = execEngine.ExecuteDataSet(selectQuery); } else { using (ExecutionEngine e = new ExecutionEngine()) { dsTemp = e.ExecuteDataSet(database, connectionString, selectQuery); } } return(dsTemp); }
/// <summary> /// Gets a DataTable by running the specified criteria /// </summary> /// <param name="criteria">Specified criteria</param> /// <returns>Resulting DataTable</returns> public DataTable GetDataTable(QueryCriteria criteria) { IQueryCriteriaGenerator iql = null; DataFactory factory = new DataFactory(); iql = factory.InitializeQueryCriteriaGenerator(database); DataTable table = null; ExecutionQuery selectQuery = iql.GenerateSelect(criteria); //check for session if (contextSession != null) { table = execEngine.ExecuteDataTable(selectQuery); } else { using (ExecutionEngine e = new ExecutionEngine()) { //no session table = e.ExecuteDataTable(selectQuery); } } return(table); }
/// <summary> /// Returns a ArraList with the data from the specified field using the specified QueryCriteria /// </summary> /// <param name="criteria">QueryCriteria based upon which data is selected</param> /// <returns>ArrayList which contains the selected result</returns> public virtual ArrayList GetFieldList(QueryCriteria criteria) { IQueryCriteriaGenerator iql = null; IDataReader iread = null; ArrayList scData = null; ExecutionEngine exec = null; try { if (criteria.Fields.Length > 1) { throw new ArgumentException("Invalid field length. Must have only one field "); } scData = new ArrayList(); DataFactory factory = new DataFactory(); iql = factory.InitializeQueryCriteriaGenerator(database); ExecutionQuery selectQuery = iql.GenerateSelect(criteria); if (contextSession != null) { iread = execEngine.ExecuteReader(selectQuery); } else { exec = new ExecutionEngine(database, connectionString); iread = exec.ExecuteReader(selectQuery); } while (iread.Read()) { scData.Add(iread.GetValue(0)); } iread.Close(); return(scData); } finally { if (iread != null) { iread.Close(); } if (exec != null) { exec.Dispose(); } } }
/// <summary> /// Deletes the row by the specified primary key value. /// </summary> /// <param name="primaryKeyValue">The primary key value.</param> /// <returns>Number of affected rows</returns> public int Delete(object primaryKeyValue) { IQueryCriteriaGenerator queryCriteriaGenerator = null; DataFactory factory = new DataFactory(); int affectedRows = 0; ExecutionEngine exec = null; try { queryCriteriaGenerator = factory.InitializeQueryCriteriaGenerator(database); DatabaseField field = mappedObject.GetPrimaryKeyField(); field.fieldValue = primaryKeyValue; QueryCriteria criteria = new QueryCriteria(mappedObject.TableName); criteria.Add(CriteriaOperator.Equality, field, primaryKeyValue); ExecutionQuery query = queryCriteriaGenerator.GenerateDelete(criteria); if (contextSession != null) { if (contextSession.IsInTransaction) { contextSession.Queries.Add(query); } else { affectedRows = execEngine.ExecuteNonQuery(query); } } else { exec = new ExecutionEngine(); affectedRows = exec.ExecuteNonQuery(query); } return(affectedRows); } finally { if (exec != null) { exec.Dispose(); } } }
/// <summary> /// Get data as a TableMetadata array /// </summary> /// <param name="criteria">QueryCriteria based upon which data is selected</param> /// <returns>A TableMetadata array containing all the data</returns> public Array GetTableMetadata(QueryCriteria criteria) { if (criteria.TableName != mappedObject.TableName) { throw new ArgumentException("Invalid criteria query. Must be the same as current table metadata"); } DataFactory factory = new DataFactory(); IQueryCriteriaGenerator iql = factory.InitializeQueryCriteriaGenerator(database); ExecutionQuery selectQuery = iql.GenerateSelect(criteria); return(GetTableMetadata(selectQuery)); }
/// <summary> /// Returns a single value from the database using the specified QueryCriteria /// </summary> /// <param name="criteria">QueryCriteria based upon which data is selected</param> /// <returns>The selected fieldValue</returns> public object GetValue(QueryCriteria criteria) { IQueryCriteriaGenerator iql = null; object result = null; ExecutionEngine exec = null; try { if (criteria.Fields.Length > 1) { throw new ArgumentException("Invalid fields length. Must have only one field"); } DataFactory factory = new DataFactory(); iql = factory.InitializeQueryCriteriaGenerator(database); ExecutionQuery selectQuery = iql.GenerateSelect(criteria); if (contextSession != null) { result = execEngine.ExecuteScalar(selectQuery); } else { exec = new ExecutionEngine(); result = exec.ExecuteScalar(selectQuery); } return(result); } finally { if (exec != null) { exec.Dispose(); } } }
/// <summary> /// Delete multiple rows from the table using the specified criteria from a QueryCriteria /// </summary> /// <param name="criteria">QueryCriteria based on which data is deleted</param> public int Delete(QueryCriteria criteria) { int affectedRows = 0; DataFactory factory = new DataFactory(); ExecutionEngine exec = null; try { IQueryCriteriaGenerator iql = factory.InitializeQueryCriteriaGenerator(database); ExecutionQuery query = iql.GenerateDelete(criteria); if (contextSession != null) { if (contextSession.IsInTransaction) { contextSession.Queries.Add(query); } else { affectedRows = execEngine.ExecuteNonQuery(query); } } else { exec = new ExecutionEngine(); affectedRows = exec.ExecuteNonQuery(query); } return(affectedRows); } finally { if (exec != null) { exec.Dispose(); } } }
private object RunIntrinsecFunction(CriteriaOperator criteria, DatabaseField field) { IQueryCriteriaGenerator iql = null; object result; ExecutionEngine exec = null; try { QueryCriteria qc = new QueryCriteria(mappedObject.TableName, field); qc.Add(criteria, field); DataFactory factory = new DataFactory(); iql = factory.InitializeQueryCriteriaGenerator(database); ExecutionQuery query = iql.GenerateSelect(qc); if (contextSession != null) { result = execEngine.ExecuteScalar(query); } else { exec = new ExecutionEngine(); result = exec.ExecuteScalar(database, connectionString, query); } return(result); } finally { if (exec != null) { exec.Dispose(); } } }
/// <summary> /// Updates the specified entities using the specified QueryCriteria /// </summary> /// <param name="criteria">QueryCriteria based upon which data is updated</param> /// <returns>Number of affected rows</returns> public int Update(QueryCriteria criteria) { DataFactory factory = new DataFactory(); ExecutionEngine exec = null; try { IQueryCriteriaGenerator iql = factory.InitializeQueryCriteriaGenerator(database); ExecutionQuery query = iql.GenerateUpdate(criteria); if (contextSession != null) { if (contextSession.IsInTransaction) { contextSession.Queries.Add(query); return(0); } return(execEngine.ExecuteNonQuery(query)); } exec = new ExecutionEngine(); return(exec.ExecuteNonQuery(query)); } finally { if (exec != null) { exec.Dispose(); } } }