C# Class Shared.Data.DatabaseImplementation

This is the implementation of the database with all queries, commands, etc.
Inheritance: IDisposable
Mostrar archivo Open project: sealuzh/PersonalAnalytics Class Usage Examples

Public Properties

Property Type Description
CurrentDatabaseDumpFile string

Public Methods

Method Description
Connect ( ) : void

Opens a connection to the database with the current database save path

CreateLogTable ( ) : void

Creates a table for the log inputs (if it doesn't yet exist)

CreateSettingsTable ( ) : void

Creates a table for the settings (keys) (if it doesn't yet exist)

CreateTimeZoneTable ( ) : void

Creates a table for the time zone (if it doesn't yet exist)

DatabaseImplementation ( string dbFilePath ) : System
Disconnect ( ) : void

Closes the connection to the database.

Dispose ( ) : void
ExecuteDefaultQuery ( string query ) : int

Executes a query (given as parameter). Also logs the query.

ExecuteQueryWithTransaction ( List commands ) : void
ExecuteReadQuery ( string query ) : DataTable

Executes a query (given as a parameter).

ExecuteScalar ( string query ) : int

Executes a query scalar. Return 1 in case of an entry, or 0 in case of no entry or an error

ExecuteScalar2 ( string query ) : object

Executes a query scalar and returns null if there was an error (or no entry) used for settings. Somehow strange?

GetDateFilteringStringForQuery ( VisType type, DateTimeOffset date, string datePropertyName = "time" ) : string
GetDbPragmaVersion ( ) : int

Get the actual database version

GetLastTimeZoneEntry ( ) : TimeZoneInfo
GetSettingsBool ( string key, bool byDefault ) : bool

Gets the stored setting value for a given key

GetSettingsDate ( string key, DateTimeOffset byDefault ) : DateTimeOffset
GetSettingsInt ( string key, int byDefault ) : int

Gets the stored setting value for a given key

GetSettingsString ( string key, string byDefault ) : string

gets the stored setting value for a given key

GetUserWorkEnd ( DateTimeOffset date ) : DateTime
GetUserWorkStart ( DateTimeOffset date ) : DateTime
HasSetting ( string key ) : bool

Checks if a settings for a given key is stored. returns false in case of an error

LogError ( string message ) : void

Inserts the message (given as a parameter) into the log-database-table (flag: Error).

LogErrorUnknown ( string tracker ) : void

Inserts an unknown error with the name of the tracker into the log-database-table (flag: Error). Also logs the query.

LogInfo ( string message ) : void

Inserts the message (given as a parameter) into the log-database-table (flag: Info). Also logs the query.

LogTimeZoneChange ( TimeZoneInfo currentTimeZone ) : void
LogWarning ( string message ) : void

Inserts the message (given as a parameter) into the log-database-table (flag: Warning). Also logs the query.

Q ( bool str ) : string

Q is the James-Bond guy. But for bools.

Q ( int str ) : string

Q is the James-Bond guy. But for ints.

Q ( long str ) : string

Q is the James-Bond guy. But for longs.

Q ( string str ) : string

Q is the James-Bond guy. Improves the string characters not to mess it up in the query string.

QDate ( DateTime dateTime ) : string

Formats and magicifies a datetime '%Y-%m-%d'

QTime ( DateTime dateTime ) : string

Formats and magicifies a datetime '%Y-%m-%d %H:%M:%S'

Reconnect ( ) : void
SetSettings ( string key, bool value ) : void

Saves a setting with a given key or value. Inserts new entry if nothing is yet stored or updates the value.

SetSettings ( string key, string value ) : void

Saves a setting with a given key or value. Inserts new entry if nothing is yet stored or updates the value.

UpdateDbPragmaVersion ( int version ) : void

Update the database version when an existing table changes

Private Methods

Method Description
WriteQueryToLog ( string query, bool force = false ) : void

Logs the query if the global setting allows it and it's not enforced my the calling method.

Method Details

Connect() public method

Opens a connection to the database with the current database save path
public Connect ( ) : void
return void

CreateLogTable() public method

Creates a table for the log inputs (if it doesn't yet exist)
public CreateLogTable ( ) : void
return void

CreateSettingsTable() public method

Creates a table for the settings (keys) (if it doesn't yet exist)
public CreateSettingsTable ( ) : void
return void

CreateTimeZoneTable() public method

Creates a table for the time zone (if it doesn't yet exist)
public CreateTimeZoneTable ( ) : void
return void

DatabaseImplementation() public method

public DatabaseImplementation ( string dbFilePath ) : System
dbFilePath string
return System

Disconnect() public method

Closes the connection to the database.
public Disconnect ( ) : void
return void

Dispose() public method

public Dispose ( ) : void
return void

ExecuteDefaultQuery() public method

Executes a query (given as parameter). Also logs the query.
public ExecuteDefaultQuery ( string query ) : int
query string
return int

ExecuteQueryWithTransaction() public method

public ExecuteQueryWithTransaction ( List commands ) : void
commands List
return void

ExecuteReadQuery() public method

Executes a query (given as a parameter).
public ExecuteReadQuery ( string query ) : DataTable
query string
return DataTable

ExecuteScalar() public method

Executes a query scalar. Return 1 in case of an entry, or 0 in case of no entry or an error
public ExecuteScalar ( string query ) : int
query string
return int

ExecuteScalar2() public method

Executes a query scalar and returns null if there was an error (or no entry) used for settings. Somehow strange?
public ExecuteScalar2 ( string query ) : object
query string
return object

GetDateFilteringStringForQuery() public method

public GetDateFilteringStringForQuery ( VisType type, DateTimeOffset date, string datePropertyName = "time" ) : string
type VisType
date DateTimeOffset
datePropertyName string
return string

GetDbPragmaVersion() public method

Get the actual database version
public GetDbPragmaVersion ( ) : int
return int

GetLastTimeZoneEntry() public method

public GetLastTimeZoneEntry ( ) : TimeZoneInfo
return TimeZoneInfo

GetSettingsBool() public method

Gets the stored setting value for a given key
public GetSettingsBool ( string key, bool byDefault ) : bool
key string
byDefault bool
return bool

GetSettingsDate() public method

public GetSettingsDate ( string key, DateTimeOffset byDefault ) : DateTimeOffset
key string
byDefault DateTimeOffset
return DateTimeOffset

GetSettingsInt() public method

Gets the stored setting value for a given key
public GetSettingsInt ( string key, int byDefault ) : int
key string
byDefault int
return int

GetSettingsString() public method

gets the stored setting value for a given key
public GetSettingsString ( string key, string byDefault ) : string
key string
byDefault string
return string

GetUserWorkEnd() public method

public GetUserWorkEnd ( DateTimeOffset date ) : DateTime
date DateTimeOffset
return DateTime

GetUserWorkStart() public method

public GetUserWorkStart ( DateTimeOffset date ) : DateTime
date DateTimeOffset
return DateTime

HasSetting() public method

Checks if a settings for a given key is stored. returns false in case of an error
public HasSetting ( string key ) : bool
key string
return bool

LogError() public method

Inserts the message (given as a parameter) into the log-database-table (flag: Error).
public LogError ( string message ) : void
message string
return void

LogErrorUnknown() public method

Inserts an unknown error with the name of the tracker into the log-database-table (flag: Error). Also logs the query.
public LogErrorUnknown ( string tracker ) : void
tracker string
return void

LogInfo() public method

Inserts the message (given as a parameter) into the log-database-table (flag: Info). Also logs the query.
public LogInfo ( string message ) : void
message string
return void

LogTimeZoneChange() public method

public LogTimeZoneChange ( TimeZoneInfo currentTimeZone ) : void
currentTimeZone TimeZoneInfo
return void

LogWarning() public method

Inserts the message (given as a parameter) into the log-database-table (flag: Warning). Also logs the query.
public LogWarning ( string message ) : void
message string
return void

Q() public method

Q is the James-Bond guy. But for bools.
public Q ( bool str ) : string
str bool
return string

Q() public method

Q is the James-Bond guy. But for ints.
public Q ( int str ) : string
str int
return string

Q() public method

Q is the James-Bond guy. But for longs.
public Q ( long str ) : string
str long
return string

Q() public method

Q is the James-Bond guy. Improves the string characters not to mess it up in the query string.
public Q ( string str ) : string
str string
return string

QDate() public method

Formats and magicifies a datetime '%Y-%m-%d'
public QDate ( DateTime dateTime ) : string
dateTime DateTime
return string

QTime() public method

Formats and magicifies a datetime '%Y-%m-%d %H:%M:%S'
public QTime ( DateTime dateTime ) : string
dateTime DateTime
return string

Reconnect() public method

public Reconnect ( ) : void
return void

SetSettings() public method

Saves a setting with a given key or value. Inserts new entry if nothing is yet stored or updates the value.
public SetSettings ( string key, bool value ) : void
key string
value bool
return void

SetSettings() public method

Saves a setting with a given key or value. Inserts new entry if nothing is yet stored or updates the value.
public SetSettings ( string key, string value ) : void
key string
value string
return void

UpdateDbPragmaVersion() public method

Update the database version when an existing table changes
public UpdateDbPragmaVersion ( int version ) : void
version int
return void

Property Details

CurrentDatabaseDumpFile public_oe property

public string CurrentDatabaseDumpFile
return string