1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#ifndef __SQL_CHH__
#define __SQL_CHH__
#include time.chh
%<_sqlDrivers=%hash()>\
\
%define(sqlRegisterDriver,name,connect,query,close,dbinfo,update,error,
%<_sqlDrivers{%name}=%hash(connect,%&connect,
query,%&query,
close,%&close,
dbinfo,%&dbinfo,
update,%&update,
error,%&error)>
)\
\
%define(sqlConnect,url,dict,
%locals(regs,drivername,hostname,port,database,connection,
%<regs=%list()>\
%if(%[%smatch(%'^chdbc:([^:]+)://([^/:]+)(:([0-9]+))?/([^/]+)/$',%url,%®s) != -1],
%<drivername=%regs[1]>\
%<hostname=%regs[2]>\
%<port=%regs[4]>\
%<database=%regs[5]>\
%if(%hcontains(%_sqlDrivers,%drivername),
%<connection=%_sqlDrivers{%drivername}{connect}(%hostname,%port,%database,%dict)>\
%hash(driver,%&_sqlDrivers{%drivername},
connection,%&connection,
dbinfo,%_sqlDrivers{%drivername}{dbinfo}(%&connection))
,
0
)
,
0
)
))\
\
%define(sqlClose,conn,
%conn{driver}{close}(%&conn{connection})
)\
\
%define(sqlDatabaseInfo,conn,
%&conn{dbinfo}
)\
\
%define(sqlQuery,conn,query,
%locals(result,
%<result=%conn{driver}{query}(%&conn{connection},%query)>\
%if(%result,
%foreachkey(colname,%&result{colinfo},
%cond(%equal(%result{colinfo}{%colname}{type},date),
%foreach(row,%&result{rows},
%<row{%colname}=%timeFromString(%conn{dbinfo}{dateformat},%row{%colname})>
),
%equal(%result{colinfo}{%colname}{type},time),
%foreach(row,%&result{rows},
%<row{%colname}=%timeFromString(%conn{dbinfo}{timeformat},%row{%colname})>
)
)
)
)\
%&result
))\
\
%define(sqlUpdate,conn,query,
%conn{driver}{update}(%&conn{connection},%query)
)\
\
%define(sqlError,conn,
%conn{driver}{error}(%&conn{connection})
)\
\
%define(sqlResultData,result,
%&result{rows}
)\
\
%define(sqlResultColumnInfo,result,
%&result{colinfo}
)\
\
%define(sqlResultColumnNames,result,
%&result{colnames}
)\
\
%if(%bound(_sqlMsqlConnect),
%sqlRegisterDriver(msql,
%&_sqlMsqlConnect,
%&_sqlMsqlQuery,
%&_sqlMsqlClose,
%&_sqlMsqlDatabaseInfo,
%&_sqlMsqlUpdate,
%&_sqlMsqlError)
)\
%if(%bound(_sqlMysqlConnect),
%sqlRegisterDriver(mysql,
%&_sqlMysqlConnect,
%&_sqlMysqlQuery,
%&_sqlMysqlClose,
%&_sqlMysqlDatabaseInfo,
%&_sqlMysqlUpdate,
%&_sqlMysqlError)
)\
%if(%bound(_sqlAdabasConnect),
%sqlRegisterDriver(adabas,
%&_sqlAdabasConnect,
0,
%&_sqlAdabasClose,
%lambda(i,%hash()),
0,
0)
)\
#endif
|