public SqlTransaction() { IDatabaseBackend db = Database.Backend; conn = db.CreateConnection(); conn.Open(); if (db.MultipleSchema) { conn.ChangeDatabase(Server.Config.MySQLDatabaseName); } transaction = conn.BeginTransaction(); }
/// <summary> Executes an SQL command that does not return any results. </summary> public static void Execute(string sql, object[] parameters, bool createDB) { IDatabaseBackend db = Database.Backend; using (IDbConnection conn = db.CreateConnection()) { conn.Open(); if (!createDB && db.MultipleSchema) { conn.ChangeDatabase(Server.Config.MySQLDatabaseName); } using (IDbCommand cmd = db.CreateCommand(sql, conn)) { FillParams(cmd, parameters); cmd.ExecuteNonQuery(); } conn.Close(); } }
/// <summary> Excecutes an SQL query, invoking a callback on the returned rows one by one. </summary> public static object Iterate(string sql, object[] parameters, object arg, ReaderCallback callback) { IDatabaseBackend db = Database.Backend; using (IDbConnection conn = db.CreateConnection()) { conn.Open(); if (db.MultipleSchema) { conn.ChangeDatabase(Server.Config.MySQLDatabaseName); } using (IDbCommand cmd = db.CreateCommand(sql, conn)) { FillParams(cmd, parameters); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { arg = callback(reader, arg); } } } conn.Close(); } return(arg); }