private void Run(string[] args) { string service = "8001"; // Check the correct number of arguments have been supplied if (args.Length < 1 || args.Length > 2) { Console.WriteLine("usage: {0} <sql> [<data service>]", System.AppDomain.CurrentDomain.FriendlyName); return; } string sql = args[0]; // Check whether a service argument has been supplied if (args.Length >= 2) { service = args[1]; } // Build a connection string and connect to the database PolyConnectionStringBuilder builder = new PolyConnectionStringBuilder(); builder.Service = service; PolyConnection connection = new PolyConnection(builder.ConnectionString); Console.WriteLine("Connecting to port {0}...", service); try { connection.Open(); } catch (Exception) { Console.WriteLine("Failed to connect to database"); return; } Console.WriteLine("Connected successfully. Start the transaction:"); Console.WriteLine("{0}", sql); // Create a command and execute it as a non-query to execute the statement PolyCommand command = new PolyCommand(sql, connection); try { command.ExecuteNonQuery(); Console.WriteLine("Transaction completed successfully"); } catch (Exception e) { Console.WriteLine("Failed to execute statement"); WriteException(e); } finally { connection.Close(); } }
private void SaveDatabase(long currentSize) { // The maximum allowable filesize has been exceeded so issue a save statement Console.WriteLine("File size has reached {0}, so time to create new load_file.", currentSize); SizeAtSave = currentSize; // Create a command and execute it in a transaction as a non-query to execute the save statement PolyTransaction transaction = Connection.BeginTransaction(); // Enable safe-commit mode transaction.SafeCommit = true; PolyCommand command = new PolyCommand("save", Connection); command.Transaction = transaction; command.ExecuteNonQuery(); try { transaction.Commit(); Console.WriteLine("Save into completed."); } catch (Exception e) { Console.WriteLine("Failed to execute statement"); WriteException(e); } }