- ZAS(Zhou’s Adaptor of Sql)is being developed based on the
MYSQL Client/Server Protocol
- ZAS is a C++ library that used by applications to access MYSQL databases
- ZAS can translate SQL syntax automatically
- Cross platforms: 32/64 bit processors supports, linux and windows supports
- Cross languages: you may use ZAS with c++, java, python
- Provides OTLV4-compatible interfaces
- Provides automatically SQL syntax translations that is transparent to upper applications
- Supports most SQL syntaxs in ORACLE/MYSQL
- Good performance in SQL syntax analyzing
- The underlying
MYSQL Client/Server Protocol
is being optimized - Conceals complexities of
MYSQL Client/Server Protocol
- Good extensibility
- Being tested over a year and runs steadily
- Connection String processor: processes the DB connection strings including Oracle TNS and traditional DSN format
- Protocol Management(the
MYSQLC
libray) provides:- implementations of the
MYSQL Client/Server Protocol
- fully support for the
prepare
andquery
mode - API compatibilities with
libmysqlclient
- implementations of the
- SQL Syntax Engine: performs SQL syntax analyzing/checking/translations
- OTLV4 Compatible API: provides a set of c++ classes that compatible with OTLV4 libraries
- First of all, the application should call
rlogon()
to parse connection strings and to do database login - Second, the application should call
open()
to initialize the SQL and translate it - Third, the application should input enough place holder values to execute the statement
- Last, fetching the result
- Further more, one can
reopen
a new SQL orexecute
the old one again
- When login, the connection string is passed to the
connection string processor
which will test the inputed string- if it’s TNS format, the processor will parse the TNS file for login informations
- if it’s DSN format, the processor will parse it directly
- otherwise, throws C++ exception
- when a SQL is inputed, it would be processed by a hard-coding parser and be translated to a syntax tree
- if no errors, the tree will be scaned for syntax errors
- if everythings’ ok, the tree will be scaned again for
translation points
to being translated toMYSQL-style
syntax - then, all place-holders within the tree will be processed
- last, the tree will be serialized to string form and passed to output
- The library provides the following functionalities: database login, SQL execution, result fetching, protocol compression, connection maintainance
- The protocol compression invokes the
deflate
algorithm from zlib - The library employs the
ping
protocol to maintain the database connection - To execute a SQL statement, the application may use
query mode
with which all place holder values are embeded within the SQL statement string that will be sent to server by a singlecom_query
request, here’s the diagram:
- The application may also execute SQL under
prepare mode
. The SQL execution progress is seperated into 2 requests:- the primordial SQL statement is sent to server by
com_stmt_prepare
to prepare resources and do checkings at server side - the place-holder value list are embeded into the
com_stmt_execute
request to initiate theSQL execution
progress, and thebinary/string/blob
type place-holders values should be sent bycom_send_long_data
requests especially, Here’s the diagram:
- the primordial SQL statement is sent to server by
- Simply do
make clean install
under source root directory - The
libzas.a
,libzas.so
, andzas wrapper
library will be generated - Link the
.a
or.so
library to your c++ applications - Load the wrapper library into your java/python applications
src
: core of zas librarytests
: test cases of zaswin
: vss project files of zas under windowswrapper
: library classes for java/python that encapsulates APIs onto ZAS
- both java and python wrappers load a c library named
libcwpr
that encapsulates a set of usage with ZAS APIs. see wrapper/cwpr.c for more details - in java wrapper, it calls
libcwpr
methods with JNI interfaces - in python wrapper, it dynamically loads the
libcwpr
/* initialize connection object and login to database with MYSQL driver */
zas_connect cnn(tnsFilePath,dal_mysql) ;
/* initialize stream object with SQL-prepare mode */
zas_stream stream(cnn,true);
/* initialize the ORACLE-style SQL */
stream.open(0,"select id,nvl(name),price from test_db.test_tbl "
"where id>=:f1<unsigned int> and id<:f2<int,in>");
/* insert place holders and execute the SQL */
streams<<1;
streams<<5;
/* fetch results */
while (!streams[strs].eof()) {
int id=0;
char name[256] = "";
float point = 0.0;
long size = 0L;
streams>>id ;
streams>>name ;
streams>>point ;
streams>>size ;
streams.flush();
printd("%d: name %s, point %f, size %ld\n",
id, name, point, size);
}
public class test_cases {
public static void main(String[] args) throws Exception {
/* initialize instance of zas.class and do initializations with it */
zas mz = (zas)Class.forName("zas").newInstance();
/* login to MYSQL */
mz.login("localhost",3306,"root","123","");
/* initialize the ORACLE-style SQL */
mz.prepare("select id,nvl(name),price,size from test_db.test_tbl where id<:f1<int>");
/* insert placeholder and execute SQL */
mz.insertInt(10);
/* fetch results */
while (!mz.isEof()) {
Integer id = 0;
String name = "" ;
Double price = 0.0;
Long size = 0L;
id = mz.fetchInt();
name = mz.fetchStr();
price = mz.fetchDouble();
size = mz.fetchLong();
System.out.println(id + ": name: " + name + ", point: " +
price + ", size: " + size + "\n");
}
}
}
# path of ZAS python wrapper class
sys.path.append(zasPythonWrapperPath)
# load the wrapper class
from python.zas import *
def main():
# do initializations
mz = zas()
# login to database
if mz.login("localhost",3306,"root","123","")!=0 :
print("login fail\n")
exit(-1)
# initialize the ORACLE-style SQL
if mz.prepare('select nvl(id),name,price,size from test_db.test_tbl where id <:f1<int>')!=0 :
print("prepare fail\n")
exit(-1)
# insert placeholder and execute SQL
if mz.insert_int(10)!=0 :
exit(-1)
# fetch results
while mz.is_eof()==0 :
id = mz.fetch_int()
name = mz.fetch_str()
price = mz.fetch_double()
size = mz.fetch_long()
print("{0}: name: {1}, point: {2}, size: {3}\n".format(id,name,price,size))