12 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||
|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:57:49.383657+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | a23af2f838d45bd9 |
Documentation: Database Export Module – Version 57 (DatabaseExport)
1. Purpose
This module provides infrastructure for exporting and managing database schema and data for Version 57 of the DataPRO system. It defines core abstractions for database interaction, including table/field metadata constants, stored procedure identifiers, version tracking (DbVersion), and timestamp-based concurrency control (DbTimeStampBase/IDbTimeStampAware). Its primary role is to support migration, export, and synchronization workflows by encapsulating versioned database structure and state management logic—particularly for legacy data exports where schema evolution must be tracked and reconciled.
2. Public Interface
DbOperationsEnum.StoredProcedure
- Type:
enum - Members:
sp_DbVersionGet: Represents the stored procedure used to retrieve the current database version.
DbVersion
-
Constructor:
public DbVersion(System.Data.DataRow dr)- Behavior: Initializes a
DbVersioninstance by extracting values from aDataRowexpected to contain columns:"Version","Step","Date","Remarks", and"UserField".
- Behavior: Initializes a
-
Properties:
int Version { get; set; }- Database version number.
int Step { get; set; }- Step within the version (e.g., migration step).
DateTime Date { get; set; }- Timestamp of the version/step.
string Remarks { get; set; }- Optional notes about the version/step.
string UserField { get; set; }- Arbitrary user-defined field.
IDbTimeStampAware Interface & DbTimeStampBase Abstract Class
-
Interface:
public interface IDbTimeStampAware { long GetTimeStampMemory(); void SetTimeStampMemory(long value); long GetTimeStampDb(); bool IsOutOfDate(); } -
Abstract Base Class:
DbTimeStampBase-
Properties:
public abstract string LookupTable { get; }- Name of the database table used to look up the timestamp.
public abstract ConstraintHelper[] GetConstraints();- Returns an array of
ConstraintHelperobjects defining the primary key or unique constraints for the record.
- Returns an array of
-
Methods:
long GetTimeStampMemory()- Returns the in-memory timestamp (
DbTimeStampfield).
- Returns the in-memory timestamp (
void SetTimeStampMemory(long value)- Sets the in-memory timestamp.
void SetTimeStampMemory(System.Data.DataRow row)- Sets in-memory timestamp to
0(currently unimplemented beyond that).
- Sets in-memory timestamp to
void SetTimeStampMemory(System.Data.IDataReader reader)- Sets in-memory timestamp to
0(currently unimplemented beyond that).
- Sets in-memory timestamp to
long GetTimeStampDb()- Currently returns
0(implementation is commented out). Intended to fetch the database timestamp for the current record.
- Currently returns
long GetTimeStampDb(Dictionary<string, long> lookup)- Currently returns
0(implementation is commented out). Intended to fetch timestamp via lookup table.
- Currently returns
Dictionary<string, long> GetAllTimeStampDb()- Currently returns an empty dictionary (implementation is commented out). Intended to fetch all timestamps from the database.
bool IsNotInDb()- Returns
trueifGetTimeStampDb() == 0.
- Returns
bool IsOutOfDate()- Compares DB and memory timestamps:
- Returns
falseif DB timestamp is0. - If memory timestamp is
0and DB is non-zero, sets memory to DB and returnsfalse. - Otherwise returns
trueif DB ≠ memory.
- Returns
- Compares DB and memory timestamps:
-
Nested Types:
ConstraintHelper:public class ConstraintHelper { public string ColumnName { get; set; } public System.Data.SqlDbType DbType { get; set; } public object DbValue { get; set; } }
-
-
Exception:
DbItemOutOfDateException : Exception- Thrown when an item is detected as out-of-date (not used in current code, but defined).
DbOperations
-
Nested Abstract Classes (Table/Field Constants):
Tags:Table = "tblTags",TagFieldsenum (TagId,TagText,Obsolete).TAGASSIGNMENTS_TABLE = "TagAssignments",TagAssignmentFields.
DbVersions:DbVersionFieldsenum (Version,Step,Date,Remarks,UserField).
Settings,Users,SensorDB,CalculatedChannels,LevelTriggers,TestSetups,TestObjectChannelSettings,DigitalOutputSettings,Squib,MMETables,DAS,DigitalInputSettings- All define table names and field enums (e.g.,
TestSetups.TestSetupsTable = "tblTestSetups").
- All define table names and field enums (e.g.,
DbTypeAttr:- Custom attribute for mapping enum fields to SQL types (used in reflection via
GetDbType()).
- Custom attribute for mapping enum fields to SQL types (used in reflection via
CustomChannelFieldSizeAttribute:- Custom attribute for specifying max field size (e.g.,
[CustomChannelFieldSizeAttribute(50)]).
- Custom attribute for specifying max field size (e.g.,
-
Static Methods:
SqlCommand GetSQLCommand(bool newCommand = false)- Returns a
SqlCommandwith an open connection (usesConnection.GetLocalConnectionString()). Clears parameters.
- Returns a
void CreateParam(IDbCommand icmd, string name, SqlDbType type, object value)- Adds a parameter to
icmd. Special handling forDateTime(formats as"yyyy-MM-dd HH:mm:ss").
- Adds a parameter to
DataSet QueryDataSet(IDbCommand icmd)- Executes
icmdand returns results asDataSet. Supports both SQL Server (_usingMSSQL == true) and SQLite (fallback).
- Executes
int ExecuteCommand(IDbCommand icmd)- Executes
icmd(non-query) and returns affected rows. Supports both SQL Server and SQLite.
- Executes
IDbCommand GetISOCommand()- Returns a new
SqlCommandconnected to the ISO database.
- Returns a new
IDbCommand GetCommand()- Returns a new
SqlCommandorSQLiteCommanddepending on_usingMSSQL.
- Returns a new
-
Static Properties:
bool _usingCentralizedDB,_usingMSSQL,_usingNTLMAuthentication,_previousDirDbOperations Connection { get; }- Singleton instance of
DbOperations.
- Singleton instance of
bool LastConnectionStatus { get; set; }- Tracks last connection success/failure.
ConnectionStatusChangedDelegate ConnectionStatusChanged { get; set; }- Event for connection status changes.
-
Instance Properties:
string Server,DBName,Username,Password- Connection configuration.
string GetLocalConnectionString(),GetLocalISOConnectionString()- Builds connection strings based on auth mode and settings.
3. Invariants
-
DbVersion:- All fields (
Version,Step,Date,Remarks,UserField) are required in the sourceDataRow; nulls or missing columns will causeInvalidCastExceptionorNullReferenceException. Dateis parsed viaConvert.ToDateTime, so culture-sensitive formatting may cause failures.
- All fields (
-
DbTimeStampBase:LookupTableandGetConstraints()must be implemented by subclasses; otherwise, runtime errors occur.GetTimeStampDb()andGetAllTimeStampDb()currently always return0or empty, indicating incomplete implementation. No functional timestamp comparison occurs.IsNotInDb()andIsOutOfDate()rely onGetTimeStampDb()returning0for missing records—currently true by design (but not correctness, sinceGetTimeStampDb()is unimplemented).SetTimeStampMemory(DataRow)andSetTimeStampMemory(IDataReader)do not populateDbTimeStamp; they unconditionally set it to0.
-
DbOperations:_usingMSSQLand_usingCentralizedDBcontrol runtime behavior (e.g., which DB provider is used). Changing them mid-execution may cause inconsistent behavior.GetLocalConnectionString()throwsException("db connection not initialized")ifServerisnull.QueryDataSetandExecuteCommandthrowSystemExceptionwith message"NoConnection"on connection failure.CreateParamforDateTimenormalizes to"yyyy-MM-dd HH:mm:ss"format—potentially losing precision.
4. Dependencies
This Module Depends On:
System.Data(ADO.NET):DataRow,DataSet,SqlDataAdapter,SqlCommand,SqlDbType,SqlDataReader,SqlException,ConnectionState.System.Data.SqlClient: For SQL Server connectivity.System.Data.SQLite: For SQLite fallback (used when_usingMSSQL == false).System.ComponentModel:INotifyPropertyChanged(used byDbTimeStampBase).System.Reflection: Used inDbTypeAttr.GetDbType().
This Module Is Used By:
- Other modules in
DataPRO/Modules/PreviousDBVersions/Version57/DatabaseExport/(inferred from namespace). - Likely consumed by migration scripts, export utilities, or data sync components that need to:
- Track DB version (
DbVersion). - Synchronize state with DB via timestamps (
DbTimeStampAware). - Access table/field metadata (
DbOperations.Tags,DbOperations.TestSetups, etc.).
- Track DB version (
5. Gotchas
-
GetTimeStampDb()andGetAllTimeStampDb()are stubbed:
All timestamp-related logic is non-functional. The implementations are commented out, soIsOutOfDate()andIsNotInDb()will always behave as if the record is missing or in-memory is authoritative. Do not rely on timestamp concurrency control in this module. -
SetTimeStampMemory(DataRow)andSetTimeStampMemory(IDataReader)are no-ops:
They setDbTimeStamp = 0regardless of input—likely placeholder code. -
DbOperations.Connectionis a singleton but mutable:
Connection.Server,DBName, etc., can be set externally, potentially causing race conditions if accessed concurrently. -
CreateParamforDateTimetruncates precision:
ConvertsDateTimeto"yyyy-MM-dd HH:mm:ss"(no milliseconds), risking data loss. -
DbVersionconstructor lacks null/invalid column checks:
Assumesdr["Version"],dr["Step"], etc., exist and are non-null. Will throw on schema mismatches. -
MMETablesfield name inconsistencies:
Notes that"MyType"→"CustomChannelType"→"TYPE"and"Id"→"ID"were used across versions. Code using these must handle historical schema differences. -
DbOperations.QueryDataSetandExecuteCommandhave duplicated logic for SQL Server/SQLite:
Code paths for both providers are interleaved, increasing maintenance risk. SQLite fallback uses_previousDirand"db/datapro.db". -
No error handling in
GetTimeStampDb/GetAllTimeStampDbstubs:
The commented-out code hadtry/catchblocks and logging (APILogger.Log(ex)), but the active code silently returns0. -
DbOperations.ConnectionusesGetLocalConnectionString()which is not thread-safe outside thelock:
While the singleton initialization is locked,GetLocalConnectionString()itself is not re-entrant safe (thoughlock(dbLock)is used internally). -
_usingMSSQLand_usingNTLMAuthenticationare static flags:
Changing them afterConnectionis instantiated may not affect existing connections. -
DbItemOutOfDateExceptionis defined but never thrown:
Its purpose is unclear; no usage found in the provided files.
End of Documentation