SQL Developer Kit (SQD) Users Guide
Version 0.5.0
Date: 12/11/2013
Author: Anthony Daniels
Company: Pyramid Solutions
http://www.pyramidsolutions.com
The SQL Developer Kit, or SQD, is an interface wrapper around the SQLite 3 Database engine. SQD provides a collection of convenience classes that simplify access to SQLite data. There are four classes in the library,
SQLField
, SQLRecord
, SQLQuerySet
, and
SQLDatabase
. SQLite an open source, zero configuration, and embeddable Structured Query Language (SQL) database engine. There are a number of SQLite wrappers in existence. This wrapper is based on an Microsoft ADO style. It was developed mainly as a learning exercise in SQLite3. The decision was made to make it open source. If you find a bug please let the author know. The use of the classes are outlined in the following paragraphs.
SQDDatabase Reference:
A Database can be opened easily by setting the file path and then calling
OpenDB();
.
SQDDatabase m_objSqlDB;
this->m_objSqlDB.Set_strDBPathName(strFullPathName);
intRet = this->m_objSqlDB.OpenDB();
Closing a database is equally simple.
this->m_objSqlDB.CloseDB();
SQDDatabase Methods:
public:
HTLMEMVAR_BYVAL_STYLE1(public,std::string,strUserName)
HTLMEMVAR_BYVAL_STYLE1(public,std::string,strPassword)
HTLMEMVAR_BYVAL_STYLE1(public,std::string,strDBPathName)
HTLMEMVAR_BYVAL_STYLE1(public,int,intPort)
HTLMEMVAR_BYVAL_STYLE1(public,bool,blnIsOpen)
HTLMEMVAR_BYVAL_STYLE1(public,std::string,strError)
public:
sqlite3* Get_ptrDB(void);
int OpenDB(void);
int CloseDB(void);
bool IsOpen(void);
std::vector<std::string> GetTableNames(void);
SQDQuerySet Reference
The Query Set is the primary interface with the SQLite database engine. The user sets the query string and then executes the query. If the query is a SELECT statement, then the records retrieve are collected in the recordset of the query. It is important that in best practice the user performs
queries with 'rowid' as the first column being retrieved. Unless it is specifically requested, the rowid primary key is not returned.
For example: SELECT rowid,* FROM strTableName
For example: SELECT rowid, col01, col02, col03 FROM strTableName
Important! The SQLDevKit assumes that the first column of the recordset is the primary key. Otherwise it has no means of saving data back to the correct row in the database. The following is an example of performing a query.
SQDQuery m_objQuery;
std::string strTableName;
int intRes;
std::stringstream strCom;
strTableName; = "tblContactInfo";
strCom << "SELECT rowid,* FROM " << strTableName.c_str();
m_objQuery.Set_ptrDatabase(&m_objSqlDB);
m_objQuery.Set_strQuery(strCom.str());
intRes = m_objQuery.Execute();
SQDQuerySet Methods
public:
HTLMEMVAR_BYVAL_STYLE1(public,std::string,strQuery)
HTLMEMVAR_BYVAL_STYLE1(public,int,intResult)
HTLMEMVAR_BYVAL_STYLE1(public, std::string, strTableName)
HTLMEMVAR_BYVAL_STYLE1(public, sqlite3_stmt *, ptrStatement)
void Set_ptrDatabase(SQDDatabase* ptrDB);
SQDDatabase* Get_ptrDatabase(void);
void Set_AllTableNames(std::string strTableName);
void Set_AllDatabasePtrs(SQDDatabase* ptrDB);
int Execute(void);
int UpdateAll(void);
int UpdateRow(size_t intRow);
int CommitAll(void);
int CommitRow(size_t index);
SQDRecordCollection * GetRecordCollPtr(void);
SQDRecord * AtRecord(size_t index);
size_t CountRecords(void);
size_t Size(void);
size_t CountColumns (void);
std::string GetColumnName (int index);
std::vector<std::string> GetColumnNames (void);
SQDRecordIterator BeginRecord(void);
SQDRecordIterator EndRecord(void);
SQDRecordIterator NextRecord(void);
SQDRecordIterator GetCursor(void);
SQDRecord * CreateRecord();
int InsertRecord(SQDRecord * ptrRec);
int DeleteRecord(size_t index);
int DeleteAllRecords(void);
int UnDeleteRecord(size_t index);
int UnDeleteAllRecords(void);
int RemoveRecord(size_t index);
int RemoveAllRecords(void);
int DeleteCommitRecord(size_t index);
int DeleteCommitAllRecords(void);
SQDRecord Reference
At the heart of the information of a table relational database such as SQLite is the record, or row.
It is the collection of fields that make up one row of data in the set. SQLite rows have a unique rowid from which they are accessed. The record has a collection of fields
for each column of data in the set. Individual rows can be updated and commit their information to the database independent of one another.
They can commit or update just one field or the entire collection of fields. Fields are accessed via STL like
AtField()
functions or via iterators.
The collection is managed like an STL vector with similar functions.
SQDRecord Methods
public:
HTLMEMVAR_BYVAL_STYLE1(public,bool,blnNewRecord);
HTLMEMVAR_BYVAL_STYLE1(public,bool,blnDeleteRecord);
HTLMEMVAR_BYVAL_STYLE1(public,bool,blnModified);
HTLMEMVAR_BYVAL_STYLE1(public,std::string,strTableName)
HTLMEMVAR_BYVAL_STYLE1(public,SQDDatabase*,ptrDatabase)
public:
int UpdateAll(void);
int UpdateField(size_t index);
int CommitAll(void);
int CommitField(size_t index);
SQDFieldCollection * GetFieldCollPtr(void);
bool DoesFieldExist(std::string strName);
SQDField * GetField(std::string strName);
int GetFieldLoc(std::string strName);
SQDField * AtField(size_t index);
int CountFields(void);
int Size(void);
std::string GetFieldName(size_t index);
SQDFieldIterator BeginField(void);
SQDFieldIterator EndField(void);
SQDFieldIterator NextField(void);
SQDFieldIterator GetCursor(void);
SQDField * CreateField(std::string strName, SQDFieldType enmType);
int DeleteField(std::string strName);
int DeleteAllFields(void);
SQDField Reference
The field is essentially a name value pair container of the field name and the field value. SQLDevKit handles all data types except BLOB. This feature is intended to be added at a later date. All information is natively stored in the field as text and converted via convenience Get and Set functions for the value.
SQDField Methods
public:
HTLMEMVAR_BYVAL_STYLE1(public,std::string,strName);
HTLMEMVAR_BYVAL_STYLE1(public,SQDRecord*,ptrParent);
void Set_strValue(const std::string & strValue);
void Set_strValue(const char * ptrCharString);
void Set_strValue(bool blnVal);
void Set_strValue(short shrtVal);
void Set_strValue(unsigned short ushrtVal);
void Set_strValue(int intVal);
void Set_strValue(unsigned int uint);
void Set_strValue(long lngVal);
void Set_strValue(unsigned long ulngVal);
void Set_strValue(float sngVal);
void Set_strValue(double dblVal);
void Set_strValue(char chrVal);
void Set_strValue(unsigned char uchrVal);
std::string Get_strValue(void);
void Get_strValue(bool & blnValReturn);
void Get_strValue(short & shrtValReturn);
void Get_strValue(unsigned short & ushrtValReturn);
void Get_strValue(int & intValReturn);
void Get_strValue(unsigned int & uintValReturn);
void Get_strValue(long & lngValReturn);
void Get_strValue(unsigned long & ulngValReturn);
void Get_strValue(float & sngValReturn);
void Get_strValue(double & dblValReturn);
void Get_strValue(char & chrValReturn);
void Get_strValue(unsigned char & uchrValReturn);
void Get_strValue(std::string & strValReturn);