/// <summary> /// This query will return a string. Run the query and get a return value /// from the query. /// </summary> /// <param name="dbConnection">Database connection string.</param> /// <param name="query">Query to send to the database.</param> /// <returns>String value from the database.</returns> public static string GetValueOnPulseDb(string dbConnection, string query) { string result = ""; try { // Open a connection to the database using (SQLiteConnection cnn = DbCommon.OpenPulseDB(dbConnection)) { // If a connection could not be made, do nothing if (cnn == null) { return(result); } using (DbTransaction dbTrans = cnn.BeginTransaction()) { using (DbCommand cmd = cnn.CreateCommand()) { // Create the statement cmd.CommandText = query; result = Convert.ToString(cmd.ExecuteScalar()); } // Add all the data dbTrans.Commit(); } // Close the connection to the database cnn.Close(); } } catch (SQLiteException e) { log.Error(String.Format("Error getting value on PulseDb: {0}", query), e); } catch (Exception e) { log.Error(String.Format("Unknown error getting value on PulseDb: {0}", query), e); } return(result); }
/// <summary> /// This query returns nothing. It it will just run the query /// given as a string on the Pulse database. /// </summary> /// <param name="dbConnection">Database connection string.</param> /// <param name="query">Query to send to the database.</param> public static void RunQueryOnPulseDb(string dbConnection, string query) { try { // Open a connection to the database using (SQLiteConnection cnn = DbCommon.OpenPulseDB(dbConnection)) { // If a connection could not be made, do nothing if (cnn == null) { return; } using (DbTransaction dbTrans = cnn.BeginTransaction()) { using (DbCommand cmd = cnn.CreateCommand()) { // Create the statement cmd.CommandText = query; cmd.ExecuteNonQuery(); } // Add all the data dbTrans.Commit(); } // Close the connection to the database cnn.Close(); } } catch (SQLiteException e) { log.Error(String.Format("Error running query on PulseDb: {0}", query), e); } catch (Exception e) { log.Error(String.Format("Unknown Error running query on PulseDb: {0}", query), e); } }