/// <summary> /// this method is used to execute the copy command, by calling each of the appropriate methods to add not only the queries, but also the data to the second table /// </summary> /// <param name="database"> /// the name of the first database /// </param> /// <param name="database2"> /// the name of the second database /// </param> /// <param name="connNumber"> /// the connection number of the first database /// </param> /// <param name="connNumber2"> /// the connection number of the second database /// </param> /// <param name="queryStep"> /// the action we want to take every query action /// </param> /// <param name="justStructure"> /// a boolean dictating if the user just wants to copy the structure for now (incase they want to add any fields to the database before copying the data) /// </param> /// <returns> /// the asyncronous task, so it does not lock the UI /// </returns> public static void ExecuteCopy(string database, string database2, int connNumber, int connNumber2, Action <string> queryStep, Boolean justStructure) { //using the opened connection... using (DbConnection conn = SQLConnectionHandler.GetOpenedConnection(connNumber2)) { //using the opened transaction... using (DbTransaction sqlTran = conn.BeginTransaction()) { try { //run the queries before, after, and copy the data SQLQueryHandler.RunBeforeQueries(connNumber2, conn, sqlTran, queryStep); if (!justStructure) { SQLDataHandler.CopyData(database, database2, connNumber, connNumber2, conn, sqlTran, queryStep); } SQLQueryHandler.RunAfterQueries(connNumber2, conn, sqlTran, queryStep); //commit the changes sqlTran.Commit(); } catch (Exception) { // rollback the transaction on error sqlTran.Rollback(); throw; } } } }
/// <summary> /// this method is used to reset the SQL objects defined, such as remove connections and clear queries /// </summary> public static void Reset() { SQLConnectionHandler.RemoveConnections(); SQLQueryHandler.ClearQueries(); }