/// <summary> /// Get the affected row count from a database rowset. /// </summary> /// <param name="ConnectionHandle">Supplies a database connection /// handle.</param> /// <param name="Script">Supplies the script object.</param> /// <returns>The affected row count is returned.</returns> public static int GetAffectedRowCountDatabaseConnection(int ConnectionHandle, ACR_ServerMisc Script) { ScriptDatabaseConnection Connection; if (!ConnectionTable.TryGetValue(ConnectionHandle, out Connection)) { Script.WriteTimestampedLogEntry(String.Format( "ScriptDatabaseConnection({0}): Invalid connection handle in GetAffectedRowCountDatabaseConnection().", ConnectionHandle)); return(0); } try { return(Connection.Database.ACR_SQLGetAffectedRows()); } catch (Exception e) { if (Connection.Flags.HasFlag(ScriptDatabaseConnectionFlags.StandardQueryLog)) { LogQuery("! ACR_SQLGetAffectedRows failed."); } Logger.Log("ScriptDatabaseConnection.GetAffectedRowCountDatabaseConnection: Exception: {0}", e); return(0); } }
/// <summary> /// GetEscape a string for subsequent safe use in a database query. /// </summary> /// <param name="ConnectionHandle">Supplies a database connection /// handle.</param> /// <param name="Str">Supplies the string to escape.</param> /// <param name="Script">Supplies the script object.</param> /// <returns>The escaped string if the operation succeeded, else null. /// </returns> public static string EscapeStringDatabaseConnection(int ConnectionHandle, string Str, ACR_ServerMisc Script) { ScriptDatabaseConnection Connection; if (!ConnectionTable.TryGetValue(ConnectionHandle, out Connection)) { Script.WriteTimestampedLogEntry(String.Format( "ScriptDatabaseConnection({0}): Invalid connection handle in EscapeStringDatabaseConnection({1}).", ConnectionHandle, Str)); return(null); } return(Connection.Database.ACR_SQLEncodeSpecialChars(Str)); }
/// <summary> /// Get a column from a fetched a database rowset. /// </summary> /// <param name="ConnectionHandle">Supplies a database connection /// handle.</param> /// <param name="ColumnIndex">Supplies the column index.</param> /// <param name="Script">Supplies the script object.</param> /// <returns>True if the operation succeeded.</returns> public static string GetColumnDatabaseConnection(int ConnectionHandle, int ColumnIndex, ACR_ServerMisc Script) { ScriptDatabaseConnection Connection; if (!ConnectionTable.TryGetValue(ConnectionHandle, out Connection)) { Script.WriteTimestampedLogEntry(String.Format( "ScriptDatabaseConnection({0}): Invalid connection handle in GetColumnDatabaseConnection({1}).", ConnectionHandle, ColumnIndex)); return(null); } string Data; bool Succeeded = true; try { Data = Connection.Database.ACR_SQLGetData(ColumnIndex); } catch (Exception e) { Logger.Log("ScriptDatabaseConnection.GetColumnDatabaseConnection: Exception: {0}", e); Data = ""; Succeeded = false; } if (Connection.Flags.HasFlag(ScriptDatabaseConnectionFlags.Debug)) { Script.WriteTimestampedLogEntry(String.Format( "ScriptDatabaseConnection({0}): Column {1} data: {2}", ConnectionHandle, ColumnIndex, Data)); } if (Connection.Flags.HasFlag(ScriptDatabaseConnectionFlags.StandardQueryLog)) { if (Succeeded) { LogQuery(String.Format("* Returning: {0} (column {1})", Data, ColumnIndex)); } else { LogQuery("! ACR_SQLGetData failed."); } } return(Data); }
/// <summary> /// Execute a database query. /// </summary> /// <param name="ConnectionHandle">Supplies a database connection /// handle.</param> /// <param name="Query">Supplies the query.</param> /// <param name="Script">Supplies the script object.</param> /// <returns>True if the operation succeeded.</returns> public static bool QueryDatabaseConnection(int ConnectionHandle, string Query, ACR_ServerMisc Script) { ScriptDatabaseConnection Connection; if (!ConnectionTable.TryGetValue(ConnectionHandle, out Connection)) { Script.WriteTimestampedLogEntry(String.Format( "ScriptDatabaseConnection({0}): Invalid connection handle in QueryDatabaseConnection({1}).", ConnectionHandle, Query)); return(false); } if (Connection.Flags.HasFlag(ScriptDatabaseConnectionFlags.Debug)) { Script.WriteTimestampedLogEntry(String.Format( "ScriptDatabaseConnection({0}): Executing query '{1}'", ConnectionHandle, Query)); } if (Connection.Flags.HasFlag(ScriptDatabaseConnectionFlags.StandardQueryLog)) { LogQuery(String.Format("* Executing: {0}", Query)); } try { Connection.Database.ACR_SQLQuery(Query); } catch (Exception e) { Logger.Log("ScriptDatabaseConnection.QueryDatabaseConnection: Exception: {0}", e); if (Connection.Flags.HasFlag(ScriptDatabaseConnectionFlags.StandardQueryLog)) { LogQuery("! ACR_SQLQuery failed."); } return(false); } return(true); }