GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
DatabaseSettings.cs
1// =============================================================================
2// GPAL - Generally Positive Automation Library
3// Copyright © 2026 Software Decisions, Inc. All rights reserved.
4//
5// This file is part of GPAL.
6// Licensed under the Business Source License 1.1
7//
8// Primary development, architecture, and vision by Michael B. Vederman,
9// CEO of Software Decisions, Inc., Texas.
10//
11// Internal development maintained privately.
12// Public releases appear on GitHub: https://github.com/SoftwareDecisionsInc/GPAL.
13//
14// See LICENSE for full terms, including Additional Use Grant.
15// =============================================================================
16
17using System;
18using System.Collections.Generic;
19using System.Data;
20using System.Data.SqlClient;
21using System.Linq;
22using System.Text;
23using System.Threading.Tasks;
24using static GenerallyPositive.Enums;
25
26namespace GenerallyPositive
27{
28 internal class DatabaseSettings
29 {
30 public GPALDatabase Database { get; set; }
31 public DatabaseType DatabaseType { get; set; }
32 public string DatabaseName { get; set; }
33 public string TableName { get; set; }
34 public string ServerName { get; set; }
35 public string UserName { get; set; }
36 public string Password { get; set; }
37 public SqlConnection Connection { get; set; }
38 public SqlTransaction SqlTransaction { get; set; }
39 public string ConnectionString { get; set; }
40 private string ExecutionString { get; set; } = null;
41 public string CreateSQL { get; set; } = null;
42 public string ReadSQL { get; set; } = null;
43 public string UpdateSQL { get; set; } = null;
44 public string DeleteSQL { get; set; } = null;
45 public System.Data.CommandType SqlCommandType { get; set; } = CommandType.Text;
46 public List<DatabaseColumn> ColumnList { get; set; }
47 public List<string> ParameterNamesList { get; set; }
48 public List<string> ParametersList { get; set; }
49 public IGPALGrid<string> ParametersGrid { get; set; }
50 public GPALDatabase.DatabaseError LastError { get; set; } // null until something fails
51 public IGPALGrid<string> Tokens { get; set; } // rows and columns of data to enter into text fields, CAVEAT: possibly something other than text? an image?
52 public List<int> LastGridRowCountsPerTable { get; set; } // set by SaveTo(out IGPALGrid<string>); read back by the optional GetRowCount() chained call
53 public int RowCount { get; set; } = -1;
54 public int CommandTimeoutSeconds { get; set; } = -1; // -1 leaves the provider's own default alone
55 public GPALDatabase.CallOnError CallOnErrorHandler { get; set; } = null;
56 public string StoredProcedure
57 {
58 get
59 {
60 return ExecutionString;
61 }
62 internal set
63 {
64 SqlCommandType = CommandType.StoredProcedure;
65 ExecutionString = value;
66 }
67 }
68 public string SqlCommand
69 {
70 get
71 {
72 return ExecutionString;
73 }
74 set
75 {
76 SqlCommandType = CommandType.Text;
77 ExecutionString = value;
78 }
79 }
80
84 internal enum CrudVerb { None, Create, Read, Update, Delete }
85
86 // reading a verb used to copy that verb's sql into SqlCommand, which had two costs. The sql stayed
87 // there for whatever came next, so .Read followed by .Update with no update sql of its own ran the
88 // select again and reported its row count as the update's. And writing SqlCommand sets the command
89 // type to text, so it replaced a stored procedure the caller had set. The verb is recorded instead
90 // and its sql is chosen when the command is built
91 internal CrudVerb Verb { get; set; } = CrudVerb.None;
92
96 internal string VerbSQL
97 {
98 get
99 {
100 string retVal = CrudVerb.Create == Verb ? CreateSQL
101 : CrudVerb.Read == Verb ? ReadSQL
102 : CrudVerb.Update == Verb ? UpdateSQL
103 : CrudVerb.Delete == Verb ? DeleteSQL
104 : null;
105
106 return retVal;
107 }
108 }
109 internal class DatabaseColumn
110 {
111 public string ColumnName { get; set; } = null;
112 public SqlDbType ColumnType { get; set; }
113 public int ColumnLength { get; set; }
114 public int ColumnPrecision { get; set; }
115 public int ColumnScale { get; set; }
116 public string TvTableTypeName { get; set; } // UDTT name for SqlDbType.Structured
117 public DatabaseColumn(string name)
118 {
119 ColumnName = name;
120 }
121 public DatabaseColumn(string name, SqlDbType sqlDbType)
122 {
123 ColumnName = name;
124 ColumnType = sqlDbType;
125 }
126 }
127 public DatabaseSettings(GPALDatabase database)
128 {
129 ColumnList = new List<DatabaseColumn>();
130 ParameterNamesList = new List<string>();
131 ParametersList = new List<string>();
132 ParametersGrid = GPAL.Grid.ToGPALObject();
133 Tokens = GPAL.Grid.ToGPALObject();
134 Database = database;
135 }
136
137 }
138}
139