Class RunDB
RunDB is the class that performs basic database operations. It is prepared
for direct use or used by ExecuteTable.
Example;
runDB = new RunDB(connType);
runDB.setDB(jndiName);
queryString[0] = "select linked_page, theme from vt_jbc_page_link where
link_name = '"+linkName+"'";
if(!runDB.runQuery(queryString, 0, RunDB.QUERY)) errorString =
runDB.errorString;
else resultSet = runDB.getResultSet();
Inheritance
Inherited Members
Namespace: SDBCS.dbwork
Assembly: SDBCS.dll
Syntax
public class RunDB
Remarks
Author Mehmet Hayati KINAŞ
Version 1.0
Constructors
RunDB(Int32)
The constructor retrieves database connection type. By default, DB system is MySQL, isJson is true, isLocale is true, connDB is "DefaultConnection". If you want different config, you must set them.
Declaration
public RunDB(int connType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | connType | The database connection type. |
Fields
batchBegan
Declaration
protected int batchBegan
Field Value
| Type | Description |
|---|---|
| System.Int32 |
BEGINEXECUTENONQUERY
This integer represent of begin non query execution type.
Declaration
public const int BEGINEXECUTENONQUERY = 0
Field Value
| Type | Description |
|---|---|
| System.Int32 |
BEGINEXECUTEREADER
This integer represent of begin query execution type.
Declaration
public const int BEGINEXECUTEREADER = 1
Field Value
| Type | Description |
|---|---|
| System.Int32 |
CONNECTIONSTRING
This integer represent of DB connection type.
Declaration
public const int CONNECTIONSTRING = 1
Field Value
| Type | Description |
|---|---|
| System.Int32 |
connType
Declaration
protected int connType
Field Value
| Type | Description |
|---|---|
| System.Int32 |
DATAFILEPATH
This integer represent of DB connection file path.
Declaration
public const int DATAFILEPATH = 0
Field Value
| Type | Description |
|---|---|
| System.Int32 |
DATE
This integer represent of data type.
Declaration
public const int DATE = 2
Field Value
| Type | Description |
|---|---|
| System.Int32 |
DB2
This integer represent of DB2 RDBMS type.
Declaration
public const int DB2 = 4
Field Value
| Type | Description |
|---|---|
| System.Int32 |
dbSystem
Database system selection integer representation.
Declaration
public int dbSystem
Field Value
| Type | Description |
|---|---|
| System.Int32 |
errorString
String for error messages.
Declaration
public string errorString
Field Value
| Type | Description |
|---|---|
| System.String |
execCount
Declaration
protected int execCount
Field Value
| Type | Description |
|---|---|
| System.Int32 |
EXECUTENONQUERY
This integer represent of execute non query execution type.
Declaration
public const int EXECUTENONQUERY = 2
Field Value
| Type | Description |
|---|---|
| System.Int32 |
EXECUTEREADER
This integer represent of execute query execution type.
Declaration
public const int EXECUTEREADER = 3
Field Value
| Type | Description |
|---|---|
| System.Int32 |
EXECUTESCALAR
This integer represent of execute scalar execution type.
Declaration
public const int EXECUTESCALAR = 4
Field Value
| Type | Description |
|---|---|
| System.Int32 |
INTEGER
This integer represent of data type.
Declaration
public const int INTEGER = 1
Field Value
| Type | Description |
|---|---|
| System.Int32 |
maxRecord
Declaration
protected int maxRecord
Field Value
| Type | Description |
|---|---|
| System.Int32 |
messageScript
String for general messages.
Declaration
public string messageScript
Field Value
| Type | Description |
|---|---|
| System.String |
MYSQL
This integer represent of MySQL RDBMS type.
Declaration
public const int MYSQL = 0
Field Value
| Type | Description |
|---|---|
| System.Int32 |
NUMBER
This integer represent of data type.
Declaration
public const int NUMBER = 3
Field Value
| Type | Description |
|---|---|
| System.Int32 |
ORACLE
This integer represent of ORACLE RDBMS type.
Declaration
public const int ORACLE = 2
Field Value
| Type | Description |
|---|---|
| System.Int32 |
POSTGRESQL
This integer represent of POSTGRESQL RDBMS type.
Declaration
public const int POSTGRESQL = 3
Field Value
| Type | Description |
|---|---|
| System.Int32 |
recordNumber
Declaration
protected int recordNumber
Field Value
| Type | Description |
|---|---|
| System.Int32 |
resultMessage
String for DB process results.
Declaration
public string resultMessage
Field Value
| Type | Description |
|---|---|
| System.String |
SQLSERVER
This integer represent of SQL SERVER RDBMS type.
Declaration
public const int SQLSERVER = 1
Field Value
| Type | Description |
|---|---|
| System.Int32 |
STRING
This integer represent of data type.
Declaration
public const int STRING = 0
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Properties
command
System.Data.Common.DbCommand class instance for getting or setting publicly.
Declaration
public DbCommand command { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Data.Common.DbCommand |
connDB
Connection name at json config file.
Declaration
public string connDB { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
connection
System.Data.Common.DBConnection class instance for getting or setting publicly.
Declaration
public DbConnection connection { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Data.Common.DbConnection |
connString
Database connection string.
Declaration
public string connString { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
dataFilePath
Connection string's file path.
Declaration
public string dataFilePath { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
dataReader
System.Data.Common.DbDataReader class instance for getting or setting publicly.
Declaration
public DbDataReader dataReader { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Data.Common.DbDataReader |
isJson
The connection file is json if true or text if false.
Declaration
public bool isJson { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
isLocale
Locale language or English
Declaration
public bool isLocale { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
retObject
Object for EXECUTESCALAR query type.
Declaration
public object retObject { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Object |
Methods
closeAll()
This method is useful for closing dataReader, command.Connection instances.
Declaration
public void closeAll()
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
closeDataReader()
If DataReader is not null, it will close.
Declaration
public void closeDataReader()
getData(Int32, Int32)
The number of records that have been executed before, the type of data, and retrieves the data according to the number of fields to be drawn from the table (or view). Data as a set of standard data types derived from the string type will return. Returns the array.An error message(errorString) will occur if there is no data return.
Declaration
public string[][] getData(int rowCount, int fieldCount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | rowCount | The specified number of data to retrieve. |
| System.Int32 | fieldCount | Number of fields to withdraw from tables (or views). |
Returns
| Type | Description |
|---|---|
| System.String[][] | Returns in the form of string [number of records] [number of fields]. |
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
getDateData(Int32, Int32)
The number of records that have been executed before, the type of data, and retrieves the data according to the number of fields to be drawn from the table (or view). Data as a set of standard data types derived from the DateTime type will return. Returns the array.An error message(errorString) will occur if there is no data return.
Declaration
public DateTime[][] getDateData(int rowCount, int fieldCount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | rowCount | The specified number of data to retrieve. |
| System.Int32 | fieldCount | Number of fields to withdraw from tables (or views). |
Returns
| Type | Description |
|---|---|
| System.DateTime[][] | Returns in the form of DateTime [number of records] [number of fields]. |
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
getdComm()
For getting dComm.
Declaration
public DB2Command getdComm()
Returns
| Type | Description |
|---|---|
| IBM.Data.DB2.Core.DB2Command |
getDoubleData(Int32, Int32)
The number of records that have been executed before, the type of data, and retrieves the data according to the number of fields to be drawn from the table (or view). Data as a set of standard data types derived from the double type will return. Returns the array.An error message(errorString) will occur if there is no data return.
Declaration
public double[][] getDoubleData(int rowCount, int fieldCount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | rowCount | The specified number of data to retrieve. |
| System.Int32 | fieldCount | Number of fields to withdraw from tables (or views). |
Returns
| Type | Description |
|---|---|
| System.Double[][] | Returns in the form of double [number of records] [number of fields]. |
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
getExecCount()
For getting execCount.
Declaration
public int getExecCount()
Returns
| Type | Description |
|---|---|
| System.Int32 |
getInt32Data(Int32, Int32)
The number of records that have been executed before, the type of data, and retrieves the data according to the number of fields to be drawn from the table (or view). Data as a set of standard data types derived from the Int32 type will return. Returns the array.An error message(errorString) will occur if there is no data return.
Declaration
public int[][] getInt32Data(int rowCount, int fieldCount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | rowCount | The specified number of data to retrieve. |
| System.Int32 | fieldCount | Number of fields to withdraw from tables (or views). |
Returns
| Type | Description |
|---|---|
| System.Int32[][] | Returns in the form of Int32 [number of records] [number of fields]. |
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
getmComm()
For getting mComm.
Declaration
public MySqlCommand getmComm()
Returns
| Type | Description |
|---|---|
| MySql.Data.MySqlClient.MySqlCommand |
getoComm()
For getting oComm.
Declaration
public OracleCommand getoComm()
Returns
| Type | Description |
|---|---|
| Oracle.ManagedDataAccess.Client.OracleCommand |
getpComm()
For getting pComm.
Declaration
public NpgsqlCommand getpComm()
Returns
| Type | Description |
|---|---|
| Npgsql.NpgsqlCommand |
getRefData(Int32)
Retrieves data, based on the previously executed reference data query
and the number of fields to be taken from the table(or views).
Error message(errorString) will occur if there is no data return.
Declaration
public string[] getRefData(int fieldCount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | fieldCount | Number of fields to withdraw from tables (or views). |
Returns
| Type | Description |
|---|---|
| System.String[] | Returns in the form of string [number of fields]. |
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
getRowCount()
After the query is created to calculate the number of records, the number of records returned from the query result.
Declaration
public int getRowCount()
Returns
| Type | Description |
|---|---|
| System.Int32 | Returns the number of records in integer type. An error message will be written to errorString if an error occurs. |
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
getsComm()
For getting sComm.
Declaration
public SqlCommand getsComm()
Returns
| Type | Description |
|---|---|
| System.Data.SqlClient.SqlCommand |
initMessages()
For initializing default values. By default, messages is locale messages.
Declaration
public void initMessages()
runQuery(String[], Int32, Int32)
Runs the query based on the query type and the order in the query array. An error message(errorString) will occur if False is returning.
Declaration
public bool runQuery(string[] queryString, int arrayNo, int queryType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | queryString | A set of query clauses. |
| System.Int32 | arrayNo | The order of the query to be executed in the array. The sequence number starts at 0. |
| System.Int32 | queryType | This integer represent of execution type. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the query ran and returns false if it didn't run. |
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
setCommand(String[], Int32)
Set DBCommand for DB query or non query processes.
Declaration
public bool setCommand(string[] queryString, int arrayNo)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | queryString | A set of query clauses. |
| System.Int32 | arrayNo | The order of the query to be executed in the array. The sequence number starts at 0. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Return true if command generated, else false. |
Exceptions
| Type | Condition |
|---|---|
| System.Data.SqlClient.SqlException | The error message (errorString) will occur if the SQL error occurs. |
setConnection()
Database connection method. if connType is CONNECTIONSTRING, Connects to the database by using the connString. Else(DATAFILEPATH), read file from dataFilePath for connecting to the database by using the connString at dataFilePath. This method will call connectDB() for connecting DB. An error message(errorString) will occur if False is returning.
Declaration
public bool setConnection()
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the connection is provided, and false if it is not. |
setDB(Int32, String)
This method set DB connection info with dbSystem and forData parameters.
Declaration
public void setDB(int dbSystem, string forData)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | dbSystem | Database system selection integer representation. |
| System.String | forData | Connection string or file path for text/json file |
setDB(String)
This method set DB connection info with forData parameter.
Declaration
public void setDB(string forData)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | forData | Connection string or file path for text/json file |
setMaxRecord(Int32)
For setting max record number. Default is 100000.
Declaration
public void setMaxRecord(int maxRecord)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | maxRecord |
setMessageBean(Boolean)
For setting messageBean.
Declaration
public void setMessageBean(bool isLocale)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | isLocale |