Embedded Python Real-Time FrameWork : API  Build 20250616.1
 All Classes Namespaces Files Functions Variables Pages
pyRT.gatea.sys.GLodbc Namespace Reference

Resilient pyodbc connection to ODBC d/b. More...

Classes

class  GLodbc
 A connection to an ODBC data source, usually a specific database. More...
 

Functions

def BuildInsert
 Builds an INSERT statement from list of columns and values. More...
 
def GetColHdr
 Return list of column headers. More...
 
def GetColInfo
 Return column headers for 'tbl'. More...
 
def GetColTypes
 Query d/b for column types for a list of column names. More...
 
def Insert
 Execute a list of prebuilt INSERT statements. More...
 
def Query
 Execute SELECT statement. More...
 
def RawQuery
 Execute raw query. More...
 
def SyncInsert
 Blocking Insert. More...
 
def Update
 Execute UPDATE command. More...
 
def Value2String
 Returns string-ified version of native Python type. More...
 

Variables

 _err
 
 _state
 [ row for row in rows ] More...
 
 _sts
 
 _tQry
 

Detailed Description

Resilient pyodbc connection to ODBC d/b.

Function Documentation

def pyRT.gatea.sys.GLodbc.BuildInsert (   self,
  tbl,
  cols,
  vals 
)

Builds an INSERT statement from list of columns and values.

Parameters
tbl- Table name
cols- List of column names
vals- List of values
Returns
INSERT statement
def pyRT.gatea.sys.GLodbc.GetColHdr (   self,
  tbl 
)

Return list of column headers.

Currently this function only supports the MySQL DESCRIBE command

Parameters
tbl- Table Name
Returns
List of column headers
def pyRT.gatea.sys.GLodbc.GetColInfo (   self,
  tbl,
  bType = False 
)

Return column headers for 'tbl'.

From https://github.com/mkleehammer/pyodbc/wiki/Cursor:

  • self._db.cursor().description is a read-only attribute
  • Returns a list of 7-item tuples
  • One tuple for each column returned by the last SQL select statement.

Each tuple contains:

  1. column name (or alias, if specified in the SQL)
  2. type code
  3. display size (pyodbc does not set this value)
  4. internal size (in bytes)
  5. precision
  6. scale
  7. nullable (True/False)

We return a list of Column Names or Types, depending on bType

Parameters
tbl- Table name
bType- True to return Type; False for names
Returns
List of names or types
def pyRT.gatea.sys.GLodbc.GetColTypes (   self,
  tbl,
  flds 
)

Query d/b for column types for a list of column names.

Return values is a string list of type mnemonics:

Mnemonic Data Type
D datetime
i int
l long
d double
s string
u unicode
Parameters
tbl- Table name
flds- List of Fields to query
Returns
String list of type mnemonics
See Also
GetColInfo()
def pyRT.gatea.sys.GLodbc.Insert (   self,
  inserts 
)

Execute a list of prebuilt INSERT statements.

This method is thread-safe:

GLodbc Thread Operation
YES Execute directly into ODBC
NO Package up the ( hdr,vals ) args and stuff it into our thread's GLeventQueue
Parameters
inserts- Semi-colon separated list of statements
def pyRT.gatea.sys.GLodbc.Query (   self,
  sel,
  tbl = None 
)

Execute SELECT statement.

Parameters
sel- SELECT statement
tbl- Table; If provided, append 'from s' % tbl
Returns
List of rows from pyodbc result set
def pyRT.gatea.sys.GLodbc.RawQuery (   self,
  qry 
)

Execute raw query.

Parameters
qry- Raw Query
Returns
[ List of rows, ColInfo ]
def pyRT.gatea.sys.GLodbc.SyncInsert (   self,
  inserts 
)

Blocking Insert.

Parameters
inserts- Semi-colon separated list of statements
See Also
_Execute()
def pyRT.gatea.sys.GLodbc.Update (   self,
  stmt 
)

Execute UPDATE command.

Parameters
stmt- UPDATE command
Returns
True if successful
def pyRT.gatea.sys.GLodbc.Value2String (   self,
  val,
  ty,
  sigFig = '%.6f' 
)

Returns string-ified version of native Python type.

Data Types from the following table:

Mnemonic Data Type
D datetime
i int
l long
d double
s string
u unicode
Parameters
val- Value to convert
ty- Type mnemonic from above)
sigFig- Formatting string for double; Default is %.6f
Returns
string-ified version of native Python type

Variable Documentation

pyRT.gatea.sys.GLodbc._err
pyRT.gatea.sys.GLodbc._state

[ row for row in rows ]

pyRT.gatea.sys.GLodbc._sts
pyRT.gatea.sys.GLodbc._tQry