private TableBase(DatabaseBase db, string tableName, Type recordType, bool pIsTemporaryTable, bool?pUseConcurrenyChecking) { if (db == null) { throw new NullReferenceException("DefaultDatabase cannot be null"); } if (string.IsNullOrWhiteSpace(tableName)) { throw new Exception("tableName cannot be null or empty"); } if (recordType == (Type)null) { throw new NullReferenceException("recordType cannot be null"); } if (!recordType.IsSubclassOf(typeof(Record))) { throw new Exception("recordType must be a subclass of Sql.ARow"); } this.defaultDatabase = db; this.tableName = tableName; this.rowType = recordType; this.isTemporaryTable = pIsTemporaryTable; this.alias = "_" + TableBase.GetNextAlias(); this.useConcurrenyChecking = pUseConcurrenyChecking; }
/// <summary> /// Loads row from select query /// /// </summary> /// <param name="table"/><param name="selectColumns"/><param name="reader"/> internal void LoadFromQuery(DatabaseBase database, TableBase table, IList <ISelectable> selectColumns, DbDataReader reader) { if (database == null) { throw new NullReferenceException("database cannot be null"); } if (table == null) { throw new NullReferenceException("table cannot be null"); } if (this.mIsInit) { throw new Exception("Row is already initialised"); } this.mIsInit = true; this.table = table; this.rowData = new object[this.table.Columns.Count]; this.mCurrentData = new object[this.table.Columns.Count]; this.mPersistedData = new object[this.table.Columns.Count]; int index = 0; while (index < this.table.Columns.Count) { ColumnBase ColumnBase = this.table.Columns[index]; int num = selectColumns.IndexOf((ISelectable)ColumnBase); this.rowData[index] = num == -1 ? Record.NOT_SET : (!reader.IsDBNull(num) ? ColumnBase.GetValue(database, reader, num) : null); this.mCurrentData[index] = this.rowData[index]; this.mPersistedData[index] = Record.NOT_SET; checked { ++index; } } this.mPreviousRowState = Record.RowStateEnum.Exists; this.mRowState = Record.RowStateEnum.Exists; }
public static DbTable GetTable(DatabaseBase database, TableBase table, DatabaseType type) { if (Query.SCHEMA_PROVIDERS.ContainsKey(type)) { return(Query.SCHEMA_PROVIDERS[type].GetTable(database, table)); } return(null); }
static void Settings_QueryPerformed(DatabaseBase database, string pSql, int records, QueryType pQueryType, DateTime?pStart, DateTime?pEnd, Exception pException, IsolationLevel pIsolationLevel, int?pResultSize, ulong?transactionId) { if (pException == null) { LOG.Debug("End:start:{0:MM-dd-yy HH:mm:ss.fff}, end:{1:MM-dd-yy HH:mm:ss.fff}, rows affected:{2}", pStart, pEnd, records); } else { LOG.Error(string.Format("End:start:{0:MM-dd-yy HH:mm:ss.fff}, end:{1:MM-dd-yy HH:mm:ss.fff}, ERROR:{2}", pStart, pEnd, pException.Message), pException); } }
internal static string CreateTableComment(string tableName, string desc, DatabaseBase database) { if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentException("tableName cannot be null or empty"); } if (database == null) { throw new NullReferenceException("database cannot be null"); } var builder = GetBuilder(database.DatabaseType); return(builder.CreateTableComment("", tableName, desc)); }
internal static void FireQueryExecutingEvent(DatabaseBase database, string pSql, QueryType pQueryType, DateTime?pStart, IsolationLevel pIsolationLevel, ulong?transactionId) { try { if (Settings.QueryExecuting == null) { return; } Settings.QueryExecuting(database, pSql, pQueryType, pStart, pIsolationLevel, transactionId); } catch { } }
internal static void FireQueryPerformedEvent(DatabaseBase database, string pSql, int records, QueryType pQueryType, DateTime?pStart, DateTime?pEnd, Exception pException, IsolationLevel pIsolationLevel, IResult pResult, ulong?transactionId) { try { if (Settings.QueryPerformed == null) { return; } int?pResultSize = !Settings.ReturnResultSize || pResult == null ? new int?() : new int?(pResult.GetDataSetSizeInBytes()); Settings.QueryPerformed(database, pSql, records, pQueryType, pStart, pEnd, pException, pIsolationLevel, pResultSize, transactionId); } catch { } }
public Transaction(IsolationLevel pIsolationLevel, bool pForceUseOnThread) { if (database == null) { throw new NullReferenceException("database cannot be null"); } this.database = DatabaseProvider.INSTANCE; this.mId = Transaction.GetNextId(); this.isolationLevel = pIsolationLevel; if (!pForceUseOnThread) { return; } Transaction.RegisterForceThread(this); }
/// <summary> /// Executes non query in pSql /// /// </summary> /// <param name="pSql">Plain text sql query to be executed</param><param name="database">Database to execute query on</param><param name="transaction">Transaction to execute query in</param> /// <returns/> public static int ExecuteNonQuery(string pSql, DatabaseBase database, Transaction transaction) { if (string.IsNullOrWhiteSpace(pSql)) { throw new Exception("pSql cannot be null or empty"); } if (database == null) { throw new NullReferenceException("database cannot be null"); } if (transaction == null) { throw new NullReferenceException("transaction cannot be null"); } DbConnection dbConnection = (DbConnection)null; DateTime? pStart = new DateTime?(); DateTime? pEnd = new DateTime?(); try { dbConnection = transaction.GetOrSetConnection(database); using (DbCommand command = Transaction.CreateCommand(dbConnection, transaction)) { command.CommandText = pSql; command.CommandType = CommandType.Text; if (transaction != null) { command.Transaction = transaction.GetOrSetDbTransaction(database); } pStart = new DateTime?(DateTime.Now); Settings.FireQueryExecutingEvent(database, pSql, QueryType.PlainText, pStart, transaction.IsolationLevel, new ulong?(transaction.Id)); int records = command.ExecuteNonQuery(); pEnd = new DateTime?(DateTime.Now); Settings.FireQueryPerformedEvent(database, pSql, records, QueryType.PlainText, pStart, pEnd, (Exception)null, transaction.IsolationLevel, (IResult)null, new ulong?(transaction.Id)); return(records); } } catch (Exception ex) { if (dbConnection != null && dbConnection.State != ConnectionState.Closed) { dbConnection.Close(); } Settings.FireQueryPerformedEvent(database, pSql, 0, QueryType.PlainText, pStart, pEnd, ex, transaction.IsolationLevel, (IResult)null, new ulong?(transaction.Id)); throw; } }
internal DbConnection GetOrSetConnection(DatabaseBase database) { if (database == null) { throw new NullReferenceException("database cannot be null"); } if (this.database != null && this.database != database) { throw new Exception("Transaction connecting was opened using a different database class. All queries used within a transaction must have tables using the same DatabaseBase class."); } lock (this) { if (this.dbConnection == null) { this.dbConnection = database.GetConnection(false); } return(this.dbConnection); } }
internal static string GetDeleteQuery(DatabaseBase database, DeleteBuilder deleteBuilder, Parameters parameters) { var builder = GetBuilder(database.DatabaseType); return(builder.GetDeleteQuery(database, deleteBuilder, parameters)); }
static void Settings_QueryExecuting(DatabaseBase database, string pSql, QueryType pQueryType, DateTime?pStart, IsolationLevel pIsolationLevel, ulong?transactionId) { LOG.Debug("Begin:{0:MM-dd-yy HH:mm:ss.fff}, query:{1}", pStart, pSql); }
public Transaction(DatabaseBase database) : this(database, IsolationLevel.ReadCommitted, false) { }
public Transaction(DatabaseBase database, IsolationLevel pIsolationLevel) : this(database, pIsolationLevel, false) { }
public StoredProcBase(DatabaseBase db, string pProcName, Type recordType) : base(db, pProcName, recordType) { }
protected TableBase(DatabaseBase db, string tableName, Type recordType) : this(db, tableName, recordType, false, new bool?()) { }
internal static string GetInsertSelectQuery(DatabaseBase database, InsertSelectBuilder insertBuilder, Parameters parameters) { var builder = GetBuilder(database.DatabaseType); return(builder.GetInsertSelectQuery(database, insertBuilder, parameters)); }
protected TableBase(DatabaseBase db, string tableName, bool pUseConcurrenyChecking, Type recordType) : this(db, tableName, recordType, false, new bool?(pUseConcurrenyChecking)) { }
internal static string GetTruncateQuery(DatabaseBase database, TableBase table) { var builder = GetBuilder(database.DatabaseType); return(builder.GetTruncateQuery(table)); }
public abstract object GetValue(DatabaseBase database, DbDataReader dataReader, int columnIndex);
internal static string GetStoreProcedureQuery(DatabaseBase database, TableBase table, Parameters parameters, object[] objectParams) { var builder = GetBuilder(database.DatabaseType); return(builder.GetStoreProcedureQuery(database, table, parameters, objectParams)); }