/// <summary> /// Performs CRUD execution of queries that do not return result set. Override to do custom Query interpretation /// </summary> protected internal virtual int DoExecuteWithoutFetch(MySqlConnection cnn, MySqlTransaction transaction, Query[] queries) { if (queries == null) { return(0); } var affected = 0; foreach (var query in queries) { var handler = QueryResolver.Resolve(query); try { affected += handler.ExecuteWithoutFetch(new MySQLCRUDQueryExecutionContext(this, cnn, transaction), query); } catch (Exception error) { throw new MySQLDataAccessException( StringConsts.EXECUTE_WITHOUT_FETCH_ERROR + error.ToMessageWithType(), error, KeyViolationKind.Unspecified, CRUDGenerator.KeyViolationName(error)); } } return(affected); }
/// <summary> /// Performs CRUD load. Override to do custom Query interpretation /// </summary> protected internal virtual List <RowsetBase> DoLoad(MySqlConnection cnn, MySqlTransaction transaction, Query[] queries, bool oneRow = false) { var result = new List <RowsetBase>(); if (queries == null) { return(result); } foreach (var query in queries) { var handler = QueryResolver.Resolve(query); try { var rowset = handler.Execute(new MySQLCRUDQueryExecutionContext(this, cnn, transaction), query, oneRow); result.Add(rowset); } catch (Exception error) { throw new MySQLDataAccessException( StringConsts.LOAD_ERROR + error.ToMessageWithType(), error, KeyViolationKind.Unspecified, CRUDGenerator.KeyViolationName(error)); } } return(result); }
/// <summary> /// Populates MySqlCommand with parameters from CRUD Query object /// Note: this code was purposely made provider specific because other providers may treat some nuances differently /// </summary> public void PopulateParameters(MySqlCommand cmd, Query query) { foreach (var par in query.Where(p => p.HasValue)) { cmd.Parameters.AddWithValue(par.Name, par.Value); } if (query.StoreKey != null) { var where = GeneratorUtils.KeyToWhere(query.StoreKey, cmd.Parameters); cmd.CommandText += "\n WHERE \n {0}".Args(where); } CRUDGenerator.ConvertParameters(m_Store, cmd.Parameters); }
/// <summary> /// Performs CRUD load. Override to do custom Query interpretation /// </summary> protected internal virtual Cursor DoOpenCursor(MySqlConnection cnn, MySqlTransaction transaction, Query query) { var context = new MySQLCRUDQueryExecutionContext(this, cnn, transaction); var handler = QueryResolver.Resolve(query); try { return(handler.OpenCursor(context, query)); } catch (Exception error) { throw new MySQLDataAccessException( StringConsts.OPEN_CURSOR_ERROR + error.ToMessageWithType(), error, KeyViolationKind.Unspecified, CRUDGenerator.KeyViolationName(error)); } }
/// <summary> /// Performs CRUD load without fetching data only returning schema. Override to do custom Query interpretation /// </summary> protected internal virtual Schema DoGetSchema(MySqlConnection cnn, MySqlTransaction transaction, Query query) { if (query == null) { return(null); } var handler = QueryResolver.Resolve(query); try { return(handler.GetSchema(new MySQLCRUDQueryExecutionContext(this, cnn, transaction), query)); } catch (Exception error) { throw new MySQLDataAccessException( StringConsts.GET_SCHEMA_ERROR + error.ToMessageWithType(), error, KeyViolationKind.Unspecified, CRUDGenerator.KeyViolationName(error)); } }
/// <summary> /// Based on store settings, converts query parameters into MySQL-acceptable values, i.e. GDID -> BYTe[]. /// This function is not idempotent /// </summary> public void ConvertParameters(MySqlParameterCollection pars) { CRUDGenerator.ConvertParameters(DataStore, pars); }
/// <summary> /// Based on store settings, converts CLR value to MySQL-acceptable value, i.e. GDID -> BYTE[]. /// </summary> public object CLRValueToDB(MySQLDataStoreBase store, object value, out MySqlDbType?convertedDbType) { return(CRUDGenerator.CLRValueToDB(DataStore, value, out convertedDbType)); }
/// <summary> /// Performs CRUD row deletion. Override to do custom deletion /// </summary> protected internal virtual int DoDelete(MySqlConnection cnn, MySqlTransaction transaction, Row row, IDataStoreKey key = null) { checkReadOnly(row.Schema, "delete"); return(CRUDGenerator.CRUDDelete(this, cnn, transaction, row, key)); }
/// <summary> /// Performs CRUD row update. Override to do custom update /// </summary> protected internal virtual int DoUpdate(MySqlConnection cnn, MySqlTransaction transaction, Row row, IDataStoreKey key = null, FieldFilterFunc filter = null) { checkReadOnly(row.Schema, "update"); return(CRUDGenerator.CRUDUpdate(this, cnn, transaction, row, key, filter)); }
/// <summary> /// Performs CRUD row upsert. Override to do custom upsertion /// </summary> protected internal virtual int DoUpsert(MySqlConnection cnn, MySqlTransaction transaction, Row row, FieldFilterFunc filter = null) { checkReadOnly(row.Schema, "upsert"); return(CRUDGenerator.CRUDUpsert(this, cnn, transaction, row, filter)); }
/// <summary> /// Performs CRUD row insert. Override to do custom insertion /// </summary> protected internal virtual int DoInsert(MySqlConnection cnn, MySqlTransaction transaction, Row row) { checkReadOnly(row.Schema, "insert"); return(CRUDGenerator.CRUDInsert(this, cnn, transaction, row)); }