19 Star 33 Fork 26

openLooKeng/hetu-odbc-driver

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
odbc_3_api.c 92.39 KB
一键复制 编辑 原始数据 按行查看 历史
wangmingyue 提交于 2020-06-29 21:58 . openlookeng first commit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255
/************************************************************************************
Copyright (C) 2013,2016 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not see <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#undef MA_ODBC_DEBUG_ALL
#include <ma_odbc.h>
extern Client_Charset utf8;
/* {{{ SQLAllocHandle */
SQLRETURN MA_SQLAllocHandle(SQLSMALLINT HandleType,
SQLHANDLE InputHandle,
SQLHANDLE *OutputHandlePtr)
{
SQLRETURN ret= SQL_ERROR;
switch(HandleType) {
case SQL_HANDLE_DBC:
EnterCriticalSection(&((MADB_Env *)InputHandle)->cs);
MADB_CLEAR_ERROR(&((MADB_Env *)InputHandle)->Error);
if ((*OutputHandlePtr= (SQLHANDLE)MADB_DbcInit((MADB_Env *)InputHandle)) != NULL)
{
ret= SQL_SUCCESS;
}
LeaveCriticalSection(&((MADB_Env *)InputHandle)->cs);
break;
case SQL_HANDLE_DESC:
EnterCriticalSection(&((MADB_Dbc *)InputHandle)->cs);
MADB_CLEAR_ERROR(&((MADB_Dbc *)InputHandle)->Error);
if ((*OutputHandlePtr= (SQLHANDLE)MADB_DescInit((MADB_Dbc *)InputHandle, MADB_DESC_UNKNOWN, TRUE)) != NULL)
{
ret= SQL_SUCCESS;
}
LeaveCriticalSection(&((MADB_Dbc *)InputHandle)->cs);
break;
case SQL_HANDLE_ENV:
if ((*OutputHandlePtr= (SQLHANDLE)MADB_EnvInit()) != NULL)
{
ret= SQL_SUCCESS;
}
break;
case SQL_HANDLE_STMT:
{
MADB_Dbc *Connection= (MADB_Dbc *)InputHandle;
MDBUG_C_ENTER(InputHandle, "MA_SQLAllocHandle(Stmt)");
MDBUG_C_DUMP(InputHandle, InputHandle, 0x);
MDBUG_C_DUMP(InputHandle, OutputHandlePtr, 0x);
MADB_CLEAR_ERROR(&Connection->Error);
if (!CheckConnection(Connection))
{
MADB_SetError(&Connection->Error, MADB_ERR_08003, NULL, 0);
break;
}
ret= MADB_StmtInit(Connection, OutputHandlePtr);
MDBUG_C_DUMP(InputHandle, *OutputHandlePtr, 0x);
MDBUG_C_RETURN(InputHandle,ret, &Connection->Error);
}
break;
default:
/* todo: set error message */
break;
}
return ret;
}
/* }}} */
/* {{{ SQLAllocHandle */
SQLRETURN SQL_API SQLAllocHandle(SQLSMALLINT HandleType,
SQLHANDLE InputHandle,
SQLHANDLE *OutputHandlePtr)
{
SQLRETURN ret;
MDBUG_ENTER("SQLAllocHandle");
MDBUG_DUMP(HandleType, d);
MDBUG_DUMP(InputHandle, 0x);
MDBUG_DUMP(OutputHandlePtr, 0x);
ret= MA_SQLAllocHandle(HandleType, InputHandle, OutputHandlePtr);
MDBUG_DUMP(ret,d);
MDBUG_RETURN(ret);
}
/* }}} */
/* {{{ SQLAllocConnect */
SQLRETURN MA_SQLAllocConnect(SQLHANDLE InputHandle,
SQLHANDLE *OutputHandlePtr)
{
return MA_SQLAllocHandle(SQL_HANDLE_DBC, InputHandle, OutputHandlePtr);
}
SQLRETURN SQL_API SQLAllocConnect(SQLHANDLE InputHandle,
SQLHANDLE *OutputHandlePtr)
{
return MA_SQLAllocConnect(InputHandle, OutputHandlePtr);
}
/* }}} */
/* {{{ SQLAllocStmt */
SQLRETURN SQL_API SQLAllocStmt(SQLHANDLE InputHandle,
SQLHANDLE *OutputHandlePtr)
{
MDBUG_C_ENTER(InputHandle, "SQLAllocStmt");
MDBUG_C_DUMP(InputHandle, InputHandle, 0x);
MDBUG_C_DUMP(InputHandle, OutputHandlePtr, 0x);
return MA_SQLAllocHandle(SQL_HANDLE_STMT, InputHandle, OutputHandlePtr);
}
/* }}} */
/* {{{ SQLAllocEnv */
SQLRETURN SQL_API SQLAllocEnv(SQLHANDLE *OutputHandlePtr)
{
return MA_SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, OutputHandlePtr);
}
/* }}} */
/* {{{ SQLBindCol */
SQLRETURN SQL_API SQLBindCol(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLSMALLINT TargetType,
SQLPOINTER TargetValuePtr,
SQLLEN BufferLength,
SQLLEN *StrLen_or_Ind)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
MADB_CLEAR_ERROR(&Stmt->Error);
MADB_CHECK_STMT_HANDLE(Stmt,stmt);
MDBUG_C_ENTER(Stmt->Connection, "SQLBindCol");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, ColumnNumber, u);
MDBUG_C_DUMP(Stmt->Connection, TargetType, d);
MDBUG_C_DUMP(Stmt->Connection, BufferLength, d);
MDBUG_C_DUMP(Stmt->Connection, StrLen_or_Ind, 0x);
ret= Stmt->Methods->BindColumn(Stmt, ColumnNumber, TargetType, TargetValuePtr, BufferLength, StrLen_or_Ind);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ MA_SQLBindParameter */
SQLRETURN MA_SQLBindParameter(SQLHSTMT StatementHandle,
SQLUSMALLINT ParameterNumber,
SQLSMALLINT InputOutputType,
SQLSMALLINT ValueType,
SQLSMALLINT ParameterType,
SQLULEN ColumnSize,
SQLSMALLINT DecimalDigits,
SQLPOINTER ParameterValuePtr,
SQLLEN BufferLength,
SQLLEN *StrLen_or_IndPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MDBUG_C_ENTER(Stmt->Connection, "SQLBindParameter");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, ParameterNumber, u);
MDBUG_C_DUMP(Stmt->Connection, InputOutputType, d);
MDBUG_C_DUMP(Stmt->Connection, ValueType, d);
MDBUG_C_DUMP(Stmt->Connection, ParameterType, d);
MDBUG_C_DUMP(Stmt->Connection, ColumnSize, u);
MDBUG_C_DUMP(Stmt->Connection, DecimalDigits, d);
MDBUG_C_DUMP(Stmt->Connection, ParameterValuePtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, BufferLength, d);
MDBUG_C_DUMP(Stmt->Connection, StrLen_or_IndPtr, 0x);
MADB_CHECK_STMT_HANDLE(Stmt,stmt);
ret= Stmt->Methods->BindParam(Stmt, ParameterNumber, InputOutputType, ValueType, ParameterType, ColumnSize, DecimalDigits,
ParameterValuePtr, BufferLength, StrLen_or_IndPtr);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLBindParameter */
SQLRETURN SQL_API SQLBindParameter(SQLHSTMT StatementHandle,
SQLUSMALLINT ParameterNumber,
SQLSMALLINT InputOutputType,
SQLSMALLINT ValueType,
SQLSMALLINT ParameterType,
SQLULEN ColumnSize,
SQLSMALLINT DecimalDigits,
SQLPOINTER ParameterValuePtr,
SQLLEN BufferLength,
SQLLEN *StrLen_or_IndPtr)
{
if (!StatementHandle)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLBindParameter(StatementHandle, ParameterNumber, InputOutputType, ValueType, ParameterType,
ColumnSize, DecimalDigits, ParameterValuePtr, BufferLength, StrLen_or_IndPtr);
}
/* }}} */
/* {{{ SQLBrowseConnect */
SQLRETURN SQL_API SQLBrowseConnect(SQLHDBC ConnectionHandle,
SQLCHAR *InConnectionString,
SQLSMALLINT StringLength1,
SQLCHAR *OutConnectionString,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength2Ptr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
MDBUG_C_ENTER(Dbc, "SQLBrowseConnect");
MADB_SetError(&Dbc->Error, MADB_ERR_IM001, NULL, 0);
ret= Dbc->Error.ReturnValue;
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLBrowseConnectW */
SQLRETURN SQL_API SQLBrowseConnectW(SQLHDBC ConnectionHandle,
SQLWCHAR *InConnectionString,
SQLSMALLINT StringLength1,
SQLWCHAR *OutConnectionString,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength2Ptr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
MDBUG_C_ENTER(Dbc, SQLBrowseConnectW);
MADB_SetError(&Dbc->Error, MADB_ERR_IM001, NULL, 0);
ret= Dbc->Error.ReturnValue;
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLBulkOperations */
SQLRETURN SQL_API SQLBulkOperations(SQLHSTMT StatementHandle,
SQLSMALLINT Operation)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLBulkOperations");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, Operation, d);
ret= Stmt->Methods->BulkOperations(Stmt, Operation);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLCancel */
SQLRETURN MA_SQLCancel(SQLHSTMT StatementHandle)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret= SQL_ERROR;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLCancel");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
if (TryEnterCriticalSection(&Stmt->Connection->cs))
{
LeaveCriticalSection(&Stmt->Connection->cs);
ret= Stmt->Methods->StmtFree(Stmt, SQL_CLOSE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
} else
{
MYSQL *MariaDb, *Kill=Stmt->Connection->mariadb;
char StmtStr[30];
if (!(MariaDb= mysql_init(NULL)))
{
ret= SQL_ERROR;
goto end;
}
if (!(mysql_real_connect(MariaDb, Kill->host, Kill->user, Kill->passwd,
"", Kill->port, Kill->unix_socket, 0)))
{
mysql_close(MariaDb);
goto end;
}
_snprintf(StmtStr, 30, "KILL QUERY %ld", mysql_thread_id(Kill));
if (mysql_query(MariaDb, StmtStr))
{
mysql_close(MariaDb);
goto end;
}
mysql_close(MariaDb);
ret= SQL_SUCCESS;
}
end:
LeaveCriticalSection(&Stmt->Connection->cs);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
SQLRETURN SQL_API SQLCancel(SQLHSTMT StatementHandle)
{
return MA_SQLCancel(StatementHandle);
}
/* }}} */
/* {{{ SQLCancelHandle */
/* ODBC version 3.8 */
SQLRETURN SQL_API SQLCancelHandle(SQLSMALLINT HandleType,
SQLHANDLE Handle)
{
if (Handle)
return SQL_INVALID_HANDLE;
switch(HandleType) {
case SQL_HANDLE_DBC:
{
MADB_Stmt Stmt;
Stmt.Connection= (MADB_Dbc *)Handle;
return MA_SQLCancel((SQLHSTMT)&Stmt);
}
break;
case SQL_HANDLE_STMT:
return MA_SQLCancel((SQLHSTMT)Handle);
break;
}
return SQL_INVALID_HANDLE;
}
/* }}} */
/* {{{ SQLCloseCursor */
SQLRETURN SQL_API SQLCloseCursor(SQLHSTMT StatementHandle)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLCloseCursor");
MDBUG_C_DUMP(Stmt->Connection, StatementHandle, 0x);
if (!Stmt->stmt ||
(!mysql_stmt_field_count(Stmt->stmt) &&
Stmt->Connection->Environment->OdbcVersion >= SQL_OV_ODBC3))
{
MADB_SetError(&Stmt->Error, MADB_ERR_24000, NULL, 0);
ret= Stmt->Error.ReturnValue;
}
else
ret= MA_SQLFreeStmt(StatementHandle, SQL_CLOSE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColAttribute */
SQLRETURN SQL_API SQLColAttribute (SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLUSMALLINT FieldIdentifier,
SQLPOINTER CharacterAttributePtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr,
#ifdef SQLCOLATTRIB_SQLPOINTER
SQLPOINTER NumericAttributePtr
#else
SQLLEN *NumericAttributePtr
#endif
)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColAttribute");
MDBUG_C_DUMP(Stmt->Connection, StatementHandle, 0x);
MDBUG_C_DUMP(Stmt->Connection, ColumnNumber, u);
MDBUG_C_DUMP(Stmt->Connection, FieldIdentifier, u);
MDBUG_C_DUMP(Stmt->Connection, CharacterAttributePtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, BufferLength, d);
MDBUG_C_DUMP(Stmt->Connection, StringLengthPtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, NumericAttributePtr, 0x);
ret= Stmt->Methods->ColAttribute(Stmt, ColumnNumber, FieldIdentifier, CharacterAttributePtr,
BufferLength, StringLengthPtr, NumericAttributePtr, FALSE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColAttributeW */
SQLRETURN SQL_API SQLColAttributeW (SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLUSMALLINT FieldIdentifier,
SQLPOINTER CharacterAttributePtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr,
#ifdef SQLCOLATTRIB_SQLPOINTER
SQLPOINTER NumericAttributePtr
#else
SQLLEN *NumericAttributePtr
#endif
)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColAttributeW");
MDBUG_C_DUMP(Stmt->Connection, StatementHandle, 0x);
MDBUG_C_DUMP(Stmt->Connection, ColumnNumber, u);
MDBUG_C_DUMP(Stmt->Connection, FieldIdentifier, u);
MDBUG_C_DUMP(Stmt->Connection, CharacterAttributePtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, BufferLength, d);
MDBUG_C_DUMP(Stmt->Connection, StringLengthPtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, NumericAttributePtr, 0x);
ret= Stmt->Methods->ColAttribute(Stmt, ColumnNumber, FieldIdentifier, CharacterAttributePtr,
BufferLength, StringLengthPtr, NumericAttributePtr, TRUE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColAttributes */
SQLRETURN SQL_API SQLColAttributes(SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLUSMALLINT fDescType,
SQLPOINTER rgbDesc,
SQLSMALLINT cbDescMax,
SQLSMALLINT * pcbDesc,
SQLLEN * pfDesc)
{
MADB_Stmt *Stmt= (MADB_Stmt *)hstmt;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->ColAttribute(Stmt, icol, MapColAttributeDescType(fDescType), rgbDesc,
cbDescMax, pcbDesc, pfDesc, FALSE);
}
/* }}} */
/* {{{ SQLColAttributesW */
SQLRETURN SQL_API SQLColAttributesW(SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLUSMALLINT fDescType,
SQLPOINTER rgbDesc,
SQLSMALLINT cbDescMax,
SQLSMALLINT * pcbDesc,
SQLLEN * pfDesc)
{
/* TODO: use internal function, not api */
return SQLColAttributeW(hstmt, icol, MapColAttributeDescType(fDescType), rgbDesc, cbDescMax, pcbDesc, pfDesc);
}
/* }}} */
/* {{{ SQLColumnPrivileges */
SQLRETURN SQL_API SQLColumnPrivileges(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColumnPrivileges");
ret= Stmt->Methods->ColumnPrivileges(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3, (char *)ColumnName, NameLength4);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColumnPrivilegesW */
SQLRETURN SQL_API SQLColumnPrivilegesW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3,
SQLWCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLULEN CpLength1, CpLength2, CpLength3, CpLength4;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL,
*CpColumn= NULL;
SQLRETURN ret;
if (!StatementHandle)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColumnPrivilegesW");
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
CpColumn= MADB_ConvertFromWChar(ColumnName, NameLength4, &CpLength4, Stmt->Connection->ConnOrSrcCharset, NULL);
ret= Stmt->Methods->ColumnPrivileges(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpTable, (SQLSMALLINT)CpLength3, CpColumn, (SQLSMALLINT)CpLength4);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
MADB_FREE(CpColumn);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColumns */
SQLRETURN SQL_API SQLColumns(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColumns");
ret= Stmt->Methods->Columns(Stmt, (char *)CatalogName,NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3, (char *)ColumnName, NameLength4);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColumnsW */
SQLRETURN SQL_API SQLColumnsW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3,
SQLWCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL,
*CpColumn= NULL;
SQLULEN CpLength1= 0, CpLength2= 0, CpLength3= 0, CpLength4= 0;
SQLRETURN ret;
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColumns");
if (CatalogName != NULL)
{
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (SchemaName != NULL)
{
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (TableName != NULL)
{
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (ColumnName != NULL)
{
CpColumn= MADB_ConvertFromWChar(ColumnName, NameLength4, &CpLength4, Stmt->Connection->ConnOrSrcCharset, NULL);
}
ret= Stmt->Methods->Columns(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpTable, (SQLSMALLINT)CpLength3, CpColumn, (SQLSMALLINT)CpLength4);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
MADB_FREE(CpColumn);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLCompleteAsync */
/* ODBC 3.8 */
SQLRETURN SQL_API SQLCompleteAsync(SQLSMALLINT HandleType,
SQLHANDLE Handle,
RETCODE *AsyncRetCodePtr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ SQLConnectCommon */
SQLRETURN SQLConnectCommon(SQLHDBC ConnectionHandle,
SQLCHAR *ServerName,
SQLSMALLINT NameLength1,
SQLCHAR *UserName,
SQLSMALLINT NameLength2,
SQLCHAR *Authentication,
SQLSMALLINT NameLength3)
{
MADB_Dbc *Connection= (MADB_Dbc *)ConnectionHandle;
MADB_Dsn *Dsn;
SQLRETURN ret;
my_bool DsnFound;
if (!Connection)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Connection->Error);
MDBUG_C_ENTER(Connection, "SQLConnect");
MDBUG_C_DUMP(Connection, Connection, 0x);
MDBUG_C_DUMP(Connection, ServerName, s);
MDBUG_C_DUMP(Connection, NameLength1, d);
MDBUG_C_DUMP(Connection, UserName, s);
MDBUG_C_DUMP(Connection, NameLength2, d);
MDBUG_C_DUMP(Connection, Authentication, s);
MDBUG_C_DUMP(Connection, NameLength3, d);
if (CheckConnection(Connection))
{
MADB_SetError(&Connection->Error, MADB_ERR_08002, NULL, 0);
return SQL_ERROR;
}
if (!(Dsn= MADB_DSN_Init()))
{
MADB_SetError(&Connection->Error, MADB_ERR_HY001, NULL, 0);
return SQL_ERROR;
}
if (ServerName && !ServerName[0])
{
MADB_SetError(&Connection->Error, MADB_ERR_HY000, "Invalid DSN", 0);
return Connection->Error.ReturnValue;
}
MADB_DSN_SET_STR(Dsn, DSNName, (char *)ServerName, NameLength1);
DsnFound= MADB_ReadDSN(Dsn, NULL, TRUE);
MADB_DSN_SET_STR(Dsn, UserName, (char *)UserName, NameLength2);
MADB_DSN_SET_STR(Dsn, Password, (char *)Authentication, NameLength3);
ret= Connection->Methods->ConnectDB(Connection, Dsn);
if (SQL_SUCCEEDED(ret))
{
MADB_DSN_Free(Connection->Dsn);
Connection->Dsn= Dsn;
}
else
{
MADB_DSN_Free(Dsn);
}
MDBUG_C_RETURN(Connection, ret, &Connection->Error);
}
/* }}} */
/* {{{ SQLConnect */
SQLRETURN SQL_API SQLConnect(SQLHDBC ConnectionHandle,
SQLCHAR *ServerName,
SQLSMALLINT NameLength1,
SQLCHAR *UserName,
SQLSMALLINT NameLength2,
SQLCHAR *Authentication,
SQLSMALLINT NameLength3)
{
return SQLConnectCommon(ConnectionHandle, ServerName, NameLength1,
UserName, NameLength2, Authentication, NameLength3);
}
/* }}} */
/* {{{ SQLConnectW */
SQLRETURN SQL_API SQLConnectW(SQLHDBC ConnectionHandle,
SQLWCHAR *ServerName,
SQLSMALLINT NameLength1,
SQLWCHAR *UserName,
SQLSMALLINT NameLength2,
SQLWCHAR *Authentication,
SQLSMALLINT NameLength3)
{
char *MBServerName= NULL, *MBUserName= NULL, *MBAuthentication= NULL;
SQLRETURN ret;
MADB_Dbc *Dbc= (MADB_Dbc*)ConnectionHandle;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
/* Convert parameters to Cp */
if (ServerName)
MBServerName= MADB_ConvertFromWChar(ServerName, NameLength1, 0, Dbc->IsAnsi ? Dbc->ConnOrSrcCharset : &utf8, NULL);
if (UserName)
MBUserName= MADB_ConvertFromWChar(UserName, NameLength2, 0, Dbc->IsAnsi ? Dbc->ConnOrSrcCharset : &utf8, NULL);
if (Authentication)
MBAuthentication= MADB_ConvertFromWChar(Authentication, NameLength3, 0, Dbc->IsAnsi ? Dbc->ConnOrSrcCharset : &utf8, NULL);
ret= SQLConnectCommon(ConnectionHandle, (SQLCHAR *)MBServerName, SQL_NTS, (SQLCHAR *)MBUserName, SQL_NTS,
(SQLCHAR *)MBAuthentication, SQL_NTS);
MADB_FREE(MBServerName);
MADB_FREE(MBUserName);
MADB_FREE(MBAuthentication);
return ret;
}
/* }}} */
/* {{{ SQLCopyDesc */
SQLRETURN SQL_API SQLCopyDesc(SQLHDESC SourceDescHandle,
SQLHDESC TargetDescHandle)
{
/*TODO: clear error */
return MADB_DescCopyDesc((MADB_Desc *)SourceDescHandle, (MADB_Desc *)TargetDescHandle);
}
/* }}} */
/* {{{ SQLDataSources */
SQLRETURN SQL_API SQLDataSources(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLCHAR *ServerName,
SQLSMALLINT BufferLength1,
SQLSMALLINT *NameLength1Ptr,
SQLCHAR *Description,
SQLSMALLINT BufferLength2,
SQLSMALLINT *NameLength2Ptr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ SQLDataSourcesW */
SQLRETURN SQL_API SQLDataSourcesW(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLWCHAR *ServerName,
SQLSMALLINT BufferLength1,
SQLSMALLINT *NameLength1Ptr,
SQLWCHAR *Description,
SQLSMALLINT BufferLength2,
SQLSMALLINT *NameLength2Ptr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ SQLDescribeCol */
SQLRETURN SQL_API SQLDescribeCol(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLCHAR *ColumnName,
SQLSMALLINT BufferLength,
SQLSMALLINT *NameLengthPtr,
SQLSMALLINT *DataTypePtr,
SQLULEN *ColumnSizePtr,
SQLSMALLINT *DecimalDigitsPtr,
SQLSMALLINT *NullablePtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLDescribeCol");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, ColumnNumber, u);
ret= Stmt->Methods->DescribeCol(Stmt, ColumnNumber, (void *)ColumnName, BufferLength,
NameLengthPtr, DataTypePtr, ColumnSizePtr, DecimalDigitsPtr,
NullablePtr, FALSE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLDescribeColW */
SQLRETURN SQL_API SQLDescribeColW(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLWCHAR *ColumnName,
SQLSMALLINT BufferLength,
SQLSMALLINT *NameLengthPtr,
SQLSMALLINT *DataTypePtr,
SQLULEN *ColumnSizePtr,
SQLSMALLINT *DecimalDigitsPtr,
SQLSMALLINT *NullablePtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLDescribeColW");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, ColumnNumber, u);
ret= Stmt->Methods->DescribeCol(Stmt, ColumnNumber, (void *)ColumnName, BufferLength,
NameLengthPtr, DataTypePtr, ColumnSizePtr, DecimalDigitsPtr,
NullablePtr, TRUE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLDescribeParam */
SQLRETURN SQL_API SQLDescribeParam(SQLHSTMT StatementHandle,
SQLUSMALLINT ParameterNumber,
SQLSMALLINT *DataTypePtr,
SQLULEN *ParameterSizePtr,
SQLSMALLINT *DecimalDigitsPtr,
SQLSMALLINT *NullablePtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
/* MariaDB doesn't support metadata for parameters,
so we return default values */
if (DataTypePtr)
*DataTypePtr= SQL_VARCHAR;
if (ParameterSizePtr)
*ParameterSizePtr= 1024 * 1024 * 24;
if (NullablePtr)
*NullablePtr= SQL_NULLABLE_UNKNOWN;
return SQL_SUCCESS;
}
/* }}} */
/* {{{ SQLDisconnect */
SQLRETURN SQL_API SQLDisconnect(SQLHDBC ConnectionHandle)
{
SQLRETURN ret= SQL_ERROR;
MADB_Dbc *Connection = (MADB_Dbc *)ConnectionHandle;
MADB_List *Element, *NextElement;
if (!Connection)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Connection->Error);
MDBUG_C_ENTER(Connection, "SQLDisconnect");
MDBUG_C_DUMP(Connection, ConnectionHandle, 0x);
/* Close all statements */
for (Element= Connection->Stmts; Element; Element= NextElement)
{
NextElement= Element->next;
MA_SQLFreeStmt((SQLHSTMT)Element->data, SQL_DROP);
}
/* Close all explicitly allocated descriptors */
for (Element= Connection->Descrs; Element; Element= NextElement)
{
NextElement= Element->next;
MADB_DescFree((MADB_Desc*)Element->data, FALSE);
}
if (Connection->mariadb)
{
mysql_close(Connection->mariadb);
Connection->mariadb= NULL;
ret= SQL_SUCCESS;
}
else
{
MADB_SetError(&Connection->Error, MADB_ERR_08003, NULL, 0);
ret= Connection->Error.ReturnValue;
}
Connection->ConnOrSrcCharset= NULL;
MDBUG_C_RETURN(Connection, ret, &Connection->Error);
}
/* }}} */
/* {{{ SQLDriverConnect */
SQLRETURN SQL_API SQLDriverConnect(SQLHDBC ConnectionHandle,
SQLHWND WindowHandle,
SQLCHAR *InConnectionString,
SQLSMALLINT StringLength1,
SQLCHAR *OutConnectionString,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength2Ptr,
SQLUSMALLINT DriverCompletion)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SQLDriverConnect");
MDBUG_C_DUMP(Dbc, Dbc, 0x);
MDBUG_C_DUMP(Dbc, InConnectionString, s);
MDBUG_C_DUMP(Dbc, StringLength1, d);
MDBUG_C_DUMP(Dbc, OutConnectionString, 0x);
MDBUG_C_DUMP(Dbc, BufferLength, d);
MDBUG_C_DUMP(Dbc, StringLength2Ptr, 0x);
MDBUG_C_DUMP(Dbc, DriverCompletion, d);
ret= Dbc->Methods->DriverConnect(Dbc, WindowHandle, InConnectionString, StringLength1, OutConnectionString,
BufferLength, StringLength2Ptr, DriverCompletion);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLDriverConnectW */
SQLRETURN SQL_API SQLDriverConnectW(SQLHDBC ConnectionHandle,
SQLHWND WindowHandle,
SQLWCHAR *InConnectionString,
SQLSMALLINT StringLength1,
SQLWCHAR *OutConnectionString,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength2Ptr,
SQLUSMALLINT DriverCompletion)
{
SQLRETURN ret= SQL_ERROR;
SQLULEN Length= 0; /* Since we need bigger(in bytes) buffer for utf8 string, the length may be > max SQLSMALLINT */
char *InConnStrA= NULL;
SQLULEN InStrAOctLen= 0;
char *OutConnStrA= NULL;
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
if (!ConnectionHandle)
{
return SQL_INVALID_HANDLE;
}
MDBUG_C_ENTER(Dbc, "SQLDriverConnectW");
MADB_CLEAR_ERROR(&Dbc->Error);
InConnStrA= MADB_ConvertFromWChar(InConnectionString, StringLength1, &InStrAOctLen, Dbc->IsAnsi ? Dbc->ConnOrSrcCharset : &utf8, NULL);
MDBUG_C_DUMP(Dbc, Dbc, 0x);
MDBUG_C_DUMP(Dbc, InConnStrA, s);
MDBUG_C_DUMP(Dbc, StringLength1, d);
MDBUG_C_DUMP(Dbc, OutConnectionString, 0x);
MDBUG_C_DUMP(Dbc, BufferLength, d);
MDBUG_C_DUMP(Dbc, StringLength2Ptr, 0x);
MDBUG_C_DUMP(Dbc, DriverCompletion, d);
/* Allocate buffer for Asc OutConnectionString */
if (OutConnectionString && BufferLength)
{
Length= BufferLength*4 /*Max bytes per utf8 character */;
OutConnStrA= (char *)MADB_CALLOC(Length);
if (OutConnStrA == NULL)
{
ret= MADB_SetError(&Dbc->Error, MADB_ERR_HY001, NULL, 0);
goto end;
}
}
ret= Dbc->Methods->DriverConnect(Dbc, WindowHandle, (SQLCHAR *)InConnStrA, InStrAOctLen, (SQLCHAR *)OutConnStrA,
Length, StringLength2Ptr, DriverCompletion);
MDBUG_C_DUMP(Dbc, ret, d);
if (!SQL_SUCCEEDED(ret))
goto end;
if (OutConnectionString)
{
Length= MADB_SetString(&utf8, OutConnectionString, BufferLength,
OutConnStrA, SQL_NTS, &((MADB_Dbc *)ConnectionHandle)->Error);
if (StringLength2Ptr)
*StringLength2Ptr= (SQLSMALLINT)Length;
}
end:
MADB_FREE(OutConnStrA);
MADB_FREE(InConnStrA);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLDrivers */
SQLRETURN SQL_API SQLDrivers(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLCHAR *DriverDescription,
SQLSMALLINT BufferLength1,
SQLSMALLINT *DescriptionLengthPtr,
SQLCHAR *DriverAttributes,
SQLSMALLINT BufferLength2,
SQLSMALLINT *AttributesLengthPtr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ SQLDriversW */
SQLRETURN SQL_API SQLDriversW(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLWCHAR *DriverDescription,
SQLSMALLINT BufferLength1,
SQLSMALLINT *DescriptionLengthPtr,
SQLWCHAR *DriverAttributes,
SQLSMALLINT BufferLength2,
SQLSMALLINT *AttributesLengthPtr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ MA_SQLEndTran */
SQLRETURN MA_SQLEndTran(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT CompletionType)
{
SQLRETURN ret= SQL_SUCCESS;
switch (HandleType) {
case SQL_HANDLE_ENV:
{
MADB_Env *Env= (MADB_Env *)Handle;
MADB_List *List= Env->Dbcs;
for (List= Env->Dbcs; List; List= List->next)
((MADB_Dbc *)List->data)->Methods->EndTran((MADB_Dbc *)List->data, CompletionType);
}
break;
case SQL_HANDLE_DBC:
{
MADB_Dbc *Dbc= (MADB_Dbc *)Handle;
if (!Dbc->mariadb)
MADB_SetError(&Dbc->Error, MADB_ERR_08002, NULL, 0);
else
Dbc->Methods->EndTran(Dbc, CompletionType);
ret= Dbc->Error.ReturnValue;
}
break;
default:
/* todo: Do we need to set an error ?! */
break;
}
return ret;
}
SQLRETURN SQL_API SQLEndTran(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT CompletionType)
{
MADB_CHECK_HANDLE_CLEAR_ERROR(HandleType, Handle);
return MA_SQLEndTran(HandleType, Handle, CompletionType);
}
/* }}} */
/* {{{ SQLError */
SQLRETURN SQL_API SQLError(SQLHENV Env, SQLHDBC Dbc, SQLHSTMT Stmt,
SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
SQLCHAR *Message, SQLSMALLINT MessageMax,
SQLSMALLINT *MessageLen)
{
SQLSMALLINT HandleType= 0;
SQLHANDLE Handle= NULL;
MADB_Error *error;
if (Stmt)
{
MDBUG_C_ENTER(((MADB_Stmt*)Stmt)->Connection, "SQLError->SQLGetDiagRec");
MDBUG_C_DUMP(((MADB_Stmt*)Stmt)->Connection, Env, 0x);
MDBUG_C_DUMP(((MADB_Stmt*)Stmt)->Connection, Dbc, 0x);
MDBUG_C_DUMP(((MADB_Stmt*)Stmt)->Connection, Stmt, 0x);
Handle= Stmt;
HandleType= SQL_HANDLE_STMT;
error= &((MADB_Stmt*)Stmt)->Error;
}
else if (Dbc)
{
MDBUG_C_ENTER((MADB_Dbc*)Dbc, "SQLError->SQLGetDiagRec");
MDBUG_C_DUMP((MADB_Dbc*)Dbc, Env, 0x);
MDBUG_C_DUMP((MADB_Dbc*)Dbc, Dbc, 0x);
MDBUG_C_DUMP((MADB_Dbc*)Dbc, Stmt, 0x);
Handle= Dbc;
HandleType= SQL_HANDLE_DBC;
error= &((MADB_Dbc*)Dbc)->Error;
}
else
{
MDBUG_ENTER("SQLError->SQLGetDiagRec");
MDBUG_DUMP(Env, 0x);
MDBUG_DUMP(Dbc, 0x);
MDBUG_DUMP(Stmt, 0x);
Handle= Env;
HandleType= SQL_HANDLE_ENV;
error= &((MADB_Env*)Env)->Error;
}
return MA_SQLGetDiagRec(HandleType, Handle, ++error->ErrorNum, Sqlstate, NativeError, Message, MessageMax, MessageLen);
}
/* }}} */
/* {{{ MA_SQLGetDiagRecW */
SQLRETURN SQL_API MA_SQLGetDiagRecW(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLWCHAR *SQLState,
SQLINTEGER *NativeErrorPtr,
SQLWCHAR *MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT *TextLengthPtr)
{
if (!Handle)
return SQL_INVALID_HANDLE;
/* Maria ODBC driver doesn't support error lists, so only the first record can be retrieved */
if (RecNumber != 1)
return SQL_NO_DATA_FOUND;
switch (HandleType) {
case SQL_HANDLE_DBC:
{
MADB_Dbc *Dbc= (MADB_Dbc *)Handle;
return MADB_GetDiagRec(&Dbc->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, TRUE,
Dbc->Environment->OdbcVersion);
}
break;
case SQL_HANDLE_STMT:
{
MADB_Stmt *Stmt= (MADB_Stmt *)Handle;
return MADB_GetDiagRec(&Stmt->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, TRUE,
Stmt->Connection->Environment->OdbcVersion);
}
break;
case SQL_HANDLE_DESC:
{
MADB_Desc *Desc= (MADB_Desc *)Handle;
return MADB_GetDiagRec(&Desc->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, TRUE,
SQL_OV_ODBC3);
}
break;
case SQL_HANDLE_ENV:
{
MADB_Env *Env= (MADB_Env *)Handle;
return MADB_GetDiagRec(&Env->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, TRUE,
Env->OdbcVersion);
}
default:
return SQL_ERROR;
break;
}
}
/* }}} */
/*{{{ SQLErrorW */
SQLRETURN SQL_API
SQLErrorW(SQLHENV Env, SQLHDBC Dbc, SQLHSTMT Stmt, SQLWCHAR *Sqlstate,
SQLINTEGER *NativeError, SQLWCHAR *Message, SQLSMALLINT MessageMax,
SQLSMALLINT *MessageLen)
{
SQLSMALLINT HandleType= 0;
SQLHANDLE Handle= NULL;
MADB_Error *error;
if (Stmt)
{
Handle= Stmt;
HandleType= SQL_HANDLE_STMT;
error= &((MADB_Stmt*)Stmt)->Error;
}
else if (Dbc)
{
Handle= Dbc;
HandleType= SQL_HANDLE_DBC;
error= &((MADB_Dbc*)Dbc)->Error;
}
else
{
Handle= Env;
HandleType= SQL_HANDLE_ENV;
error= &((MADB_Env*)Env)->Error;
}
return MA_SQLGetDiagRecW(HandleType, Handle, ++error->ErrorNum, Sqlstate, NativeError, Message, MessageMax, MessageLen);
}
/* }}} */
/* {{{ SQLTransact */
SQLRETURN SQL_API SQLTransact(SQLHENV Env, SQLHDBC Dbc, SQLUSMALLINT CompletionType)
{
if (Env != SQL_NULL_HENV)
{
MADB_CLEAR_ERROR(&((MADB_Env*)Env)->Error);
return MA_SQLEndTran(SQL_HANDLE_ENV, Env, CompletionType);
}
else if (Dbc != SQL_NULL_HDBC)
{
MADB_CLEAR_ERROR(&((MADB_Dbc*)Dbc)->Error);
return MA_SQLEndTran(SQL_HANDLE_DBC, Dbc, CompletionType);
}
else
return SQL_INVALID_HANDLE;
}
/* }}} */
/* {{{ SQLExecDirect */
SQLRETURN SQL_API SQLExecDirect(SQLHSTMT StatementHandle,
SQLCHAR *StatementText,
SQLINTEGER TextLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
ret= SQL_INVALID_HANDLE;
else
ret= Stmt->Methods->ExecDirect(Stmt, (char *)StatementText, TextLength);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLExecDirectW */
SQLRETURN SQL_API SQLExecDirectW(SQLHSTMT StatementHandle,
SQLWCHAR *StatementText,
SQLINTEGER TextLength)
{
char *CpStmt;
SQLULEN StmtLength;
SQLRETURN ret;
BOOL ConversionError;
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLExecDirectW");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
CpStmt= MADB_ConvertFromWChar(StatementText, TextLength, &StmtLength, Stmt->Connection->ConnOrSrcCharset, &ConversionError);
MDBUG_C_DUMP(Stmt->Connection, CpStmt, s);
if (ConversionError)
{
MADB_SetError(&Stmt->Error, MADB_ERR_22018, NULL, 0);
ret= Stmt->Error.ReturnValue;
}
else
ret= Stmt->Methods->ExecDirect(Stmt, CpStmt, (SQLINTEGER)StmtLength);
MADB_FREE(CpStmt);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
SQLRETURN SQL_API SQLExecute(SQLHSTMT StatementHandle)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (StatementHandle == SQL_NULL_HSTMT)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLExecute");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
return Stmt->Methods->Execute(Stmt, FALSE);
}
/* }}} */
/* {{{ SQLExtendedFetch */
SQLRETURN SQL_API SQLExtendedFetch(SQLHSTMT StatementHandle,
SQLUSMALLINT FetchOrientation,
SQLLEN FetchOffset,
SQLULEN *RowCountPtr,
SQLUSMALLINT *RowStatusArray)
{
SQLRETURN ret;
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLULEN *SaveRowsProcessedPtr= Stmt->Ird->Header.RowsProcessedPtr;
SQLUSMALLINT *SaveArrayStatusPtr= Stmt->Ird->Header.ArrayStatusPtr;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLExtendedFetch");
MDBUG_C_DUMP(Stmt->Connection, FetchOrientation, u);
MDBUG_C_DUMP(Stmt->Connection, FetchOffset, d);
MDBUG_C_DUMP(Stmt->Connection, RowCountPtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, RowStatusArray, 0x);
Stmt->Ird->Header.RowsProcessedPtr= RowCountPtr;
Stmt->Ird->Header.ArrayStatusPtr= RowStatusArray;
ret= Stmt->Methods->FetchScroll(Stmt, FetchOrientation, FetchOffset);
if (RowStatusArray && SaveArrayStatusPtr)
{
SQLUINTEGER i;
for (i=0; i < Stmt->Ard->Header.ArraySize; i++)
SaveArrayStatusPtr[i]= RowStatusArray[i];
}
Stmt->Ird->Header.RowsProcessedPtr= SaveRowsProcessedPtr;
Stmt->Ird->Header.ArrayStatusPtr= SaveArrayStatusPtr;
if (ret == SQL_NO_DATA)
{
if (RowCountPtr)
*RowCountPtr= 0;
}
if (ret == SQL_ERROR)
if (strcmp(Stmt->Error.SqlState, "22002") == 0)
ret= SQL_SUCCESS_WITH_INFO;
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLFetch */
SQLRETURN SQL_API SQLFetch(SQLHSTMT StatementHandle)
{
MADB_Stmt *Stmt;
if (StatementHandle == SQL_NULL_HSTMT)
return SQL_INVALID_HANDLE;
Stmt= (MADB_Stmt *)StatementHandle;
MDBUG_C_ENTER(Stmt->Connection, "SQLFetch");
MADB_CLEAR_ERROR(&Stmt->Error);
/* SQLFetch is equivalent of SQLFetchScroll(SQL_FETCH_NEXT), 3rd parameter is ignored for SQL_FETCH_NEXT */
MDBUG_C_RETURN(Stmt->Connection, Stmt->Methods->FetchScroll(Stmt, SQL_FETCH_NEXT, 1), &Stmt->Error);
}
/* }}} */
/* {{{ SQLFetchScroll */
SQLRETURN SQL_API SQLFetchScroll(SQLHSTMT StatementHandle,
SQLSMALLINT FetchOrientation,
SQLLEN FetchOffset)
{
MADB_Stmt *Stmt;
if (StatementHandle == SQL_NULL_HSTMT)
return SQL_INVALID_HANDLE;
Stmt= (MADB_Stmt *)StatementHandle;
MDBUG_C_ENTER(Stmt->Connection, "SQLFetchScroll");
MDBUG_C_DUMP(Stmt->Connection, FetchOrientation, d);
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_RETURN(Stmt->Connection, Stmt->Methods->FetchScroll(Stmt, FetchOrientation, FetchOffset), &Stmt->Error);
}
/* }}} */
/* {{{ SQLFreeHandle */
SQLRETURN SQL_API SQLFreeHandle(SQLSMALLINT HandleType,
SQLHANDLE Handle)
{
SQLRETURN ret;
MADB_CHECK_HANDLE_CLEAR_ERROR(HandleType, Handle);
switch (HandleType)
{
case SQL_HANDLE_ENV:
MDBUG_ENTER("SQLFreeHandle");
MDBUG_DUMP(HandleType, d);
MDBUG_DUMP(Handle, 0x);
ret= MADB_EnvFree((MADB_Env *)Handle);
break;
case SQL_HANDLE_DBC:
{
MADB_Dbc *Dbc= (MADB_Dbc *)Handle;
MDBUG_C_ENTER(Dbc, "SQLFreeHandle");
MDBUG_C_DUMP(Dbc, HandleType, d);
MDBUG_C_DUMP(Dbc, Handle, 0x);
ret= MADB_DbcFree(Dbc);
return ret;
/*MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);*/
}
case SQL_HANDLE_DESC:
{
MADB_Desc *Desc= (MADB_Desc *)Handle;
MADB_Dbc *Dbc= Desc->Dbc;
MDBUG_C_ENTER(Dbc, "SQLFreeHandle");
MDBUG_C_DUMP(Dbc, HandleType, d);
MDBUG_C_DUMP(Dbc, Handle, 0x);
/* Error if the descriptor does not belong to application(was automatically alliocated by the driver)
Basically DM is supposed to take care of this. Keeping in mind direct linking */
if (!Desc->AppType)
{
MADB_SetError(&Desc->Error, MADB_ERR_HY017, NULL, 0);
MDBUG_C_RETURN(Dbc, Desc->Error.ReturnValue, &Desc->Error);
}
ret= MADB_DescFree(Desc, FALSE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
case SQL_HANDLE_STMT:
{
MADB_Stmt *Stmt= (MADB_Stmt *)Handle;
MADB_Dbc *Dbc= Stmt->Connection;
MDBUG_C_ENTER(Dbc, "SQLFreeHandle");
MDBUG_C_DUMP(Dbc, HandleType, d);
MDBUG_C_DUMP(Dbc, Handle, 0x);
ret= MA_SQLFreeStmt(Stmt, SQL_DROP);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
}
MDBUG_RETURN(ret);
}
/* }}} */
/* {{{ SQLFreeEnv */
SQLRETURN SQL_API SQLFreeEnv(SQLHANDLE henv)
{
if (henv == SQL_NULL_HENV)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Env*)henv)->Error);
return MADB_EnvFree((MADB_Env *)henv);
}
/* }}} */
/* {{{ SQLFreeConnect */
SQLRETURN SQL_API SQLFreeConnect(SQLHANDLE hdbc)
{
if (hdbc == SQL_NULL_HDBC)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Dbc*)hdbc)->Error);
return MADB_DbcFree((MADB_Dbc*)hdbc);
}
/* }}} */
/* {{{ SQLFreeStmt */
SQLRETURN MA_SQLFreeStmt(SQLHSTMT StatementHandle,
SQLUSMALLINT Option)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
MDBUG_C_PRINT(Stmt->Connection, "%sMA_SQLFreeStmt","\t->");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, Option, d);
return Stmt->Methods->StmtFree(Stmt, Option);
}
SQLRETURN SQL_API SQLFreeStmt(SQLHSTMT StatementHandle,
SQLUSMALLINT Option)
{
if (StatementHandle== SQL_NULL_HSTMT)
return SQL_INVALID_HANDLE;
MDBUG_C_ENTER(((MADB_Stmt*)StatementHandle)->Connection, "SQLFreeStmt");
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLFreeStmt(StatementHandle, Option);
}
/* }}} */
/* {{{ SQLForeignKeys */
SQLRETURN SQL_API SQLForeignKeys(SQLHSTMT StatementHandle,
SQLCHAR *PKCatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *PKSchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *PKTableName,
SQLSMALLINT NameLength3,
SQLCHAR *FKCatalogName,
SQLSMALLINT NameLength4,
SQLCHAR *FKSchemaName,
SQLSMALLINT NameLength5,
SQLCHAR *FKTableName,
SQLSMALLINT NameLength6)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if(!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLForeignKeys");
ret= Stmt->Methods->ForeignKeys(Stmt, (char *)PKCatalogName, NameLength1, (char *)PKSchemaName, NameLength2,
(char *)PKTableName, NameLength3, (char *)FKCatalogName, NameLength4,
(char *)FKSchemaName, NameLength4, (char *)FKTableName, NameLength6);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLForeignKeysW */
SQLRETURN SQL_API SQLForeignKeysW(SQLHSTMT StatementHandle,
SQLWCHAR *PKCatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *PKSchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *PKTableName,
SQLSMALLINT NameLength3,
SQLWCHAR *FKCatalogName,
SQLSMALLINT NameLength4,
SQLWCHAR *FKSchemaName,
SQLSMALLINT NameLength5,
SQLWCHAR *FKTableName,
SQLSMALLINT NameLength6)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
char *CpPkCatalog= NULL,
*CpPkSchema= NULL,
*CpPkTable= NULL,
*CpFkCatalog= NULL,
*CpFkSchema= NULL,
*CpFkTable= NULL;
SQLULEN CpLength1, CpLength2, CpLength3,
CpLength4, CpLength5, CpLength6;
SQLRETURN ret;
if(!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLForeignKeysW");
CpPkCatalog= MADB_ConvertFromWChar(PKCatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpPkSchema= MADB_ConvertFromWChar(PKSchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpPkTable= MADB_ConvertFromWChar(PKTableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
CpFkCatalog= MADB_ConvertFromWChar(FKCatalogName, NameLength4, &CpLength4, Stmt->Connection->ConnOrSrcCharset, NULL);
CpFkSchema= MADB_ConvertFromWChar(FKSchemaName, NameLength5, &CpLength5, Stmt->Connection->ConnOrSrcCharset, NULL);
CpFkTable= MADB_ConvertFromWChar(FKTableName, NameLength6, &CpLength6, Stmt->Connection->ConnOrSrcCharset, NULL);
ret= Stmt->Methods->ForeignKeys(Stmt, CpPkCatalog, (SQLSMALLINT)CpLength1, CpPkSchema, (SQLSMALLINT)CpLength2,
CpPkTable, (SQLSMALLINT)CpLength3, CpFkCatalog, (SQLSMALLINT)CpLength4,
CpFkSchema, (SQLSMALLINT)CpLength5, CpFkTable, (SQLSMALLINT)CpLength6);
MADB_FREE(CpPkCatalog);
MADB_FREE(CpPkSchema);
MADB_FREE(CpPkTable);
MADB_FREE(CpFkCatalog);
MADB_FREE(CpFkSchema);
MADB_FREE(CpFkTable);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLGetConnectAttr */
SQLRETURN MA_SQLGetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MDBUG_C_ENTER(Dbc, "SQLGetConnectAttr");
MDBUG_C_DUMP(Dbc, Attribute, d);
MDBUG_C_DUMP(Dbc, ValuePtr, 0x);
MDBUG_C_DUMP(Dbc, BufferLength, d);
MDBUG_C_DUMP(Dbc, StringLengthPtr, 0x);
ret= Dbc->Methods->GetAttr(Dbc, Attribute, ValuePtr, BufferLength, StringLengthPtr, FALSE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
SQLRETURN SQL_API SQLGetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
if (ConnectionHandle == SQL_NULL_HDBC)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Dbc *)ConnectionHandle)->Error);
return MA_SQLGetConnectAttr(ConnectionHandle, Attribute, ValuePtr, BufferLength, StringLengthPtr);
}
/* }}} */
/* {{{ SQLGetConnectAttrW */
SQLRETURN SQL_API SQLGetConnectAttrW(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SQLGetConnectAttr");
MDBUG_C_DUMP(Dbc, Attribute, d);
MDBUG_C_DUMP(Dbc, ValuePtr, 0x);
MDBUG_C_DUMP(Dbc, BufferLength, d);
MDBUG_C_DUMP(Dbc, StringLengthPtr, 0x);
ret= Dbc->Methods->GetAttr(Dbc, Attribute, ValuePtr, BufferLength, StringLengthPtr, TRUE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLGetConnectOption */
SQLRETURN SQL_API SQLGetConnectOption(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLPOINTER ValuePtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
return MA_SQLGetConnectAttr(ConnectionHandle, Option, ValuePtr,
Option == SQL_ATTR_CURRENT_CATALOG ? SQL_MAX_OPTION_STRING_LENGTH : 0, NULL);
}
/* }}} */
/* {{{ SQLGetConnectOptionW */
SQLRETURN SQL_API SQLGetConnectOptionW(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLPOINTER ValuePtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
return SQLGetConnectAttrW(ConnectionHandle, Option, ValuePtr,
Option == SQL_ATTR_CURRENT_CATALOG ? SQL_MAX_OPTION_STRING_LENGTH : 0, NULL);
}
/* }}} */
/* {{{ SQLGetCursorName */
SQLRETURN SQL_API SQLGetCursorName(
SQLHSTMT StatementHandle,
SQLCHAR * CursorName,
SQLSMALLINT BufferLength,
SQLSMALLINT * NameLengthPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->GetCursorName(Stmt, CursorName, BufferLength, NameLengthPtr, FALSE);
}
/* }}} */
/* {{{ SQLGetCursorNameW */
SQLRETURN SQL_API SQLGetCursorNameW(
SQLHSTMT StatementHandle,
SQLWCHAR * CursorName,
SQLSMALLINT BufferLength,
SQLSMALLINT * NameLengthPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->GetCursorName(Stmt, CursorName, BufferLength, NameLengthPtr, TRUE);
}
/* }}} */
/* {{{ SQLGetData */
SQLRETURN SQL_API SQLGetData(SQLHSTMT StatementHandle,
SQLUSMALLINT Col_or_Param_Num,
SQLSMALLINT TargetType,
SQLPOINTER TargetValuePtr,
SQLLEN BufferLength,
SQLLEN *StrLen_or_IndPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt*)StatementHandle;
unsigned int i;
MADB_DescRecord *IrdRec;
if (StatementHandle== SQL_NULL_HSTMT)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
/* In case we don't have DM(it check for that) */
if (TargetValuePtr == NULL)
{
return MADB_SetError(&Stmt->Error, MADB_ERR_HY009, NULL, 0);
}
/* Bookmark */
if (Col_or_Param_Num == 0)
{
return MADB_GetBookmark(Stmt, TargetType, TargetValuePtr, BufferLength, StrLen_or_IndPtr);
}
/* We don't need this to be checked in case of "internal" use of the GetData, i.e. for internal needs we should always get the data */
if ( Stmt->CharOffset[Col_or_Param_Num - 1] > 0
&& Stmt->CharOffset[Col_or_Param_Num - 1] >= Stmt->Lengths[Col_or_Param_Num - 1])
{
return SQL_NO_DATA;
}
if (BufferLength < 0)
{
return MADB_SetError(&Stmt->Error, MADB_ERR_HY090, NULL, 0);
}
/* reset offsets for other columns. Doing that here since "internal" calls should not do that */
for (i=0; i < mysql_stmt_field_count(Stmt->stmt); i++)
{
if (i != Col_or_Param_Num - 1)
{
IrdRec= MADB_DescGetInternalRecord(Stmt->Ird, i, MADB_DESC_READ);
if (IrdRec)
{
MADB_FREE(IrdRec->InternalBuffer);
}
Stmt->CharOffset[i]= 0;
}
}
return Stmt->Methods->GetData(StatementHandle, Col_or_Param_Num, TargetType, TargetValuePtr, BufferLength, StrLen_or_IndPtr, FALSE);
}
/* }}} */
/* {{{ SQLGetDescField */
SQLRETURN SQL_API SQLGetDescField(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
if (!DescriptorHandle)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Desc*)DescriptorHandle)->Error);
return MADB_DescGetField(DescriptorHandle, RecNumber, FieldIdentifier, ValuePtr, BufferLength, StringLengthPtr, FALSE);
}
/* }}} */
/* {{{ SQLGetDescFieldW */
SQLRETURN SQL_API SQLGetDescFieldW(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
if (!DescriptorHandle)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Desc*)DescriptorHandle)->Error);
return MADB_DescGetField(DescriptorHandle, RecNumber, FieldIdentifier, ValuePtr, BufferLength, StringLengthPtr, TRUE);
}
/* }}} */
/* {{{ SQLGetDescRec */
SQLRETURN SQL_API SQLGetDescRec(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLCHAR *Name,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr,
SQLSMALLINT *TypePtr,
SQLSMALLINT *SubTypePtr,
SQLLEN *LengthPtr,
SQLSMALLINT *PrecisionPtr,
SQLSMALLINT *ScalePtr,
SQLSMALLINT *NullablePtr)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
if (!Desc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Desc->Error);
return MADB_DescGetRec(Desc, RecNumber, Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr,
LengthPtr, PrecisionPtr, ScalePtr, NullablePtr, FALSE);
}
/* }}} */
/* {{{ SQLGetDescRecW */
SQLRETURN SQL_API SQLGetDescRecW(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLWCHAR *Name,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr,
SQLSMALLINT *TypePtr,
SQLSMALLINT *SubTypePtr,
SQLLEN *LengthPtr,
SQLSMALLINT *PrecisionPtr,
SQLSMALLINT *ScalePtr,
SQLSMALLINT *NullablePtr)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
if (!Desc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Desc->Error);
return MADB_DescGetRec(Desc, RecNumber, (SQLCHAR *)Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr,
LengthPtr, PrecisionPtr, ScalePtr, NullablePtr, TRUE);
}
/* }}} */
/* {{{ SQLGetDiagField */
SQLRETURN SQL_API SQLGetDiagField(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLSMALLINT DiagIdentifier,
SQLPOINTER DiagInfoPtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr)
{
if (!Handle)
return SQL_INVALID_HANDLE;
return MADB_GetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfoPtr, BufferLength, StringLengthPtr, FALSE);
}
/* }}} */
/* {{{ SQLGetDiagFieldW */
SQLRETURN SQL_API SQLGetDiagFieldW(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLSMALLINT DiagIdentifier,
SQLPOINTER DiagInfoPtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr)
{
if (!Handle)
return SQL_INVALID_HANDLE;
return MADB_GetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfoPtr, BufferLength, StringLengthPtr, TRUE);
}
/* }}} */
/* {{{ SQLGetDiagRec */
SQLRETURN MA_SQLGetDiagRec(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLCHAR *SQLState,
SQLINTEGER *NativeErrorPtr,
SQLCHAR *MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT *TextLengthPtr)
{
SQLRETURN ret= SQL_ERROR;
if (!Handle)
MDBUG_RETURN(SQL_INVALID_HANDLE);
if (RecNumber < 1 || BufferLength < 0)
MDBUG_RETURN(SQL_ERROR);
/* Maria ODBC driver doesn't support error lists, so only the first record can be retrieved */
if (RecNumber != 1)
MDBUG_RETURN(SQL_NO_DATA_FOUND);
switch (HandleType) {
case SQL_HANDLE_DBC:
{
MADB_Dbc *Dbc= (MADB_Dbc *)Handle;
MDBUG_C_ENTER(Dbc, "SQLGetDiagRec");
MDBUG_C_DUMP(Dbc, HandleType, d);
MDBUG_C_DUMP(Dbc, Handle, 0x);
MDBUG_C_DUMP(Dbc, MessageText, 0x);
MDBUG_C_DUMP(Dbc, BufferLength, d);
MDBUG_C_DUMP(Dbc, TextLengthPtr, 0x);
ret= MADB_GetDiagRec(&Dbc->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *) MessageText, BufferLength, TextLengthPtr, FALSE,
Dbc->Environment->OdbcVersion);
}
break;
case SQL_HANDLE_STMT:
{
MADB_Stmt *Stmt= (MADB_Stmt *)Handle;
MDBUG_C_ENTER(Stmt->Connection, "SQLGetDiagRec");
MDBUG_C_DUMP(Stmt->Connection, HandleType, d);
MDBUG_C_DUMP(Stmt->Connection, Handle, 0x);
MDBUG_C_DUMP(Stmt->Connection, MessageText, 0x);
MDBUG_C_DUMP(Stmt->Connection, BufferLength, d);
MDBUG_C_DUMP(Stmt->Connection, TextLengthPtr, 0x);
ret= MADB_GetDiagRec(&Stmt->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, FALSE,
Stmt->Connection->Environment->OdbcVersion);
}
break;
case SQL_HANDLE_DESC:
{
MADB_Desc *Desc= (MADB_Desc *)Handle;
MDBUG_C_ENTER(Desc->Dbc, "SQLGetDiagRec");
MDBUG_C_DUMP(Desc->Dbc, HandleType, d);
MDBUG_C_DUMP(Desc->Dbc, Handle, 0x);
MDBUG_C_DUMP(Desc->Dbc, MessageText, 0x);
MDBUG_C_DUMP(Desc->Dbc, BufferLength, d);
MDBUG_C_DUMP(Desc->Dbc, TextLengthPtr, 0x);
ret= MADB_GetDiagRec(&Desc->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, FALSE,
SQL_OV_ODBC3);
}
break;
case SQL_HANDLE_ENV:
{
MADB_Env *Env= (MADB_Env *)Handle;
ret= MADB_GetDiagRec(&Env->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, FALSE,
Env->OdbcVersion);
}
break;
}
MDBUG_RETURN(ret);
}
SQLRETURN SQL_API SQLGetDiagRec(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLCHAR *SQLState,
SQLINTEGER *NativeErrorPtr,
SQLCHAR *MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT *TextLengthPtr)
{
return MA_SQLGetDiagRec(HandleType, Handle, RecNumber, SQLState, NativeErrorPtr,
MessageText, BufferLength, TextLengthPtr);
}
/* }}} */
/* {{{ SQLGetDiagRecW */
SQLRETURN SQL_API SQLGetDiagRecW(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLWCHAR *SQLState,
SQLINTEGER *NativeErrorPtr,
SQLWCHAR *MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT *TextLengthPtr)
{
return MA_SQLGetDiagRecW(HandleType, Handle, RecNumber, SQLState, NativeErrorPtr, MessageText,
BufferLength, TextLengthPtr);
}
/* }}} */
/* {{{ SQLGetEnvAttr */
SQLRETURN SQL_API SQLGetEnvAttr(SQLHENV EnvironmentHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
MADB_Env *Env= (MADB_Env *)EnvironmentHandle;
SQLRETURN ret;
MDBUG_ENTER("SQLGetEnvAttr");
MDBUG_DUMP(Attribute, d);
MDBUG_DUMP(ValuePtr, 0x);
MDBUG_DUMP(BufferLength, d);
MDBUG_DUMP(StringLengthPtr, 0x);
if (!Env)
ret= SQL_INVALID_HANDLE;
else
{
MADB_CLEAR_ERROR(&Env->Error);
ret= MADB_EnvGetAttr(Env, Attribute, ValuePtr, BufferLength, StringLengthPtr);
}
MDBUG_DUMP(ret, d);
MDBUG_RETURN(ret);
}
/* {{{ SQLGetFunctions */
SQLRETURN SQL_API SQLGetFunctions(SQLHDBC ConnectionHandle,
SQLUSMALLINT FunctionId,
SQLUSMALLINT *SupportedPtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SQLGetFunctions");
MDBUG_C_DUMP(Dbc, FunctionId, d);
MDBUG_C_DUMP(Dbc, SupportedPtr, 0x);
ret= Dbc->Methods->GetFunctions(Dbc, FunctionId, SupportedPtr);
MDBUG_C_RETURN(Dbc,ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLGetInfo */
SQLRETURN SQL_API SQLGetInfo(SQLHDBC ConnectionHandle,
SQLUSMALLINT InfoType,
SQLPOINTER InfoValuePtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SQLGetInfo");
MDBUG_C_DUMP(Dbc, InfoType, d);
ret= Dbc->Methods->GetInfo(Dbc, InfoType, InfoValuePtr, BufferLength, StringLengthPtr, FALSE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLGetInfoW */
SQLRETURN SQL_API SQLGetInfoW(SQLHDBC ConnectionHandle,
SQLUSMALLINT InfoType,
SQLPOINTER InfoValuePtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SQLGetInfo");
MDBUG_C_DUMP(Dbc, InfoType, d);
MDBUG_C_DUMP(Dbc, InfoValuePtr, 0x);
MDBUG_C_DUMP(Dbc, StringLengthPtr, 0x);
ret= Dbc->Methods->GetInfo(Dbc, InfoType, InfoValuePtr, BufferLength, StringLengthPtr, TRUE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLGetStmtAttr */
SQLRETURN MA_SQLGetStmtAttr(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
return Stmt->Methods->GetAttr(Stmt, Attribute, ValuePtr, BufferLength, StringLengthPtr);
}
SQLRETURN SQL_API SQLGetStmtAttr(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLGetStmtAttr(StatementHandle, Attribute, ValuePtr, BufferLength, StringLengthPtr);
}
/* }}} */
/* {{{ SQLGetStmtAttrW */
SQLRETURN SQL_API SQLGetStmtAttrW(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->GetAttr(Stmt, Attribute, ValuePtr, BufferLength, StringLengthPtr);
}
/* }}} */
/* {{{ SQLGetStmtOption */
SQLRETURN SQL_API SQLGetStmtOption(SQLHSTMT StatementHandle,
SQLUSMALLINT Option, SQLPOINTER Value)
{
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLGetStmtAttr(StatementHandle, Option, Value, SQL_NTS, (SQLINTEGER *)NULL);
}
/* }}} */
/* {{{ SQLGetTypeInfo */
SQLRETURN SQL_API SQLGetTypeInfo(SQLHSTMT StatementHandle,
SQLSMALLINT DataType)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return MADB_GetTypeInfo(Stmt, DataType);
}
/* }}} */
/* {{{ SQLGetTypeInfoW */
SQLRETURN SQL_API SQLGetTypeInfoW(SQLHSTMT StatementHandle,
SQLSMALLINT DataType)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return MADB_GetTypeInfo(Stmt, DataType);}
/* }}} */
/* {{{ SQLMoreResults */
SQLRETURN SQL_API SQLMoreResults(SQLHSTMT StatementHandle)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return MADB_StmtMoreResults(Stmt);
}
/* }}} */
/* {{{ SQLNativeSql */
SQLRETURN SQL_API SQLNativeSql(SQLHDBC ConnectionHandle,
SQLCHAR *InStatementText,
SQLINTEGER TextLength1,
SQLCHAR *OutStatementText,
SQLINTEGER BufferLength,
SQLINTEGER *TextLength2Ptr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLINTEGER Length;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
if (!TextLength2Ptr && (!OutStatementText || !BufferLength))
{
MADB_SetError(&Dbc->Error, MADB_ERR_01004, NULL, 0);
return Dbc->Error.ReturnValue;
}
Length= (SQLINTEGER)MADB_SetString(0, OutStatementText, BufferLength, (char *)InStatementText, TextLength1, &Dbc->Error);
if (TextLength2Ptr)
*TextLength2Ptr= Length;
return Dbc->Error.ReturnValue;
}
/* }}} */
/* {{{ SQLNativeSqlW */
SQLRETURN SQL_API SQLNativeSqlW(SQLHDBC ConnectionHandle,
SQLWCHAR *InStatementText,
SQLINTEGER TextLength1,
SQLWCHAR *OutStatementText,
SQLINTEGER BufferLength,
SQLINTEGER *TextLength2Ptr)
{
MADB_Dbc *Conn= (MADB_Dbc *)ConnectionHandle;
SQLINTEGER Length= (TextLength1 == SQL_NTS) ? SqlwcsCharLen(InStatementText, (SQLLEN)-1) : TextLength1;
if (!Conn)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Conn->Error);
if (TextLength2Ptr)
*TextLength2Ptr= Length;
if(OutStatementText && BufferLength < Length)
MADB_SetError(&Conn->Error, MADB_ERR_01004, NULL, 0);
if(OutStatementText && BufferLength < Length)
MADB_SetError(&Conn->Error, MADB_ERR_01004, NULL, 0);
Length= MIN(Length, BufferLength - 1);
if (OutStatementText && BufferLength)
{
memcpy(OutStatementText, InStatementText, Length * sizeof(SQLWCHAR));
OutStatementText[Length]= 0;
}
return Conn->Error.ReturnValue;
}
/* }}} */
/* {{{ SQLNumParams */
SQLRETURN SQL_API SQLNumParams(SQLHSTMT StatementHandle,
SQLSMALLINT *ParameterCountPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
MADB_CHECK_STMT_HANDLE(Stmt, stmt);
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->ParamCount(Stmt, ParameterCountPtr);
}
/* }}} */
/* {{{ SQLNumResultCols */
SQLRETURN SQL_API SQLNumResultCols(SQLHSTMT StatementHandle,
SQLSMALLINT *ColumnCountPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
MADB_CHECK_STMT_HANDLE(Stmt, stmt);
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->ColumnCount(Stmt, ColumnCountPtr);
}
/* }}} */
/* {{{ SQLParamData */
SQLRETURN SQL_API SQLParamData(SQLHSTMT StatementHandle,
SQLPOINTER *ValuePtrPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->ParamData(Stmt, ValuePtrPtr);
}
/* }}} */
SQLRETURN SQL_API SQLPrepare(SQLHSTMT StatementHandle,
SQLCHAR *StatementText,
SQLINTEGER TextLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MDBUG_C_ENTER(Stmt->Connection, "SQLPrepare");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, StatementText, s);
MDBUG_C_DUMP(Stmt->Connection, TextLength, d);
/* Prepare method clears error */
return Stmt->Methods->Prepare(Stmt, (char *)StatementText, TextLength, FALSE);
}
/* }}} */
/* {{{ SQLPrepareW */
SQLRETURN SQL_API SQLPrepareW(SQLHSTMT StatementHandle,
SQLWCHAR *StatementText,
SQLINTEGER TextLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
char *StmtStr;
SQLULEN StmtLength;
SQLRETURN ret;
BOOL ConversionError;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLPrepareW");
StmtStr= MADB_ConvertFromWChar(StatementText, TextLength, &StmtLength, Stmt->Connection->ConnOrSrcCharset, &ConversionError);
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, StmtStr, s);
MDBUG_C_DUMP(Stmt->Connection, TextLength, d);
if (ConversionError)
{
MADB_SetError(&Stmt->Error, MADB_ERR_22018, NULL, 0);
ret= Stmt->Error.ReturnValue;
}
else
ret= Stmt->Methods->Prepare(Stmt, StmtStr, (SQLINTEGER)StmtLength, FALSE);
MADB_FREE(StmtStr);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLPrimaryKeys */
SQLRETURN SQL_API SQLPrimaryKeys(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
MDBUG_C_ENTER(Stmt->Connection, "SQLPrimaryKeys");
MDBUG_C_DUMP(Stmt->Connection, StatementHandle, 0x);
MDBUG_C_DUMP(Stmt->Connection, CatalogName, s);
MDBUG_C_DUMP(Stmt->Connection, NameLength1, d);
MDBUG_C_DUMP(Stmt->Connection, SchemaName, s);
MDBUG_C_DUMP(Stmt->Connection, NameLength2, d);
MDBUG_C_DUMP(Stmt->Connection, TableName, s);
MDBUG_C_DUMP(Stmt->Connection, NameLength3, d);
if (!Stmt)
ret= SQL_INVALID_HANDLE;
else
{
MADB_CLEAR_ERROR(&Stmt->Error);
ret= Stmt->Methods->PrimaryKeys(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3);
}
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLPrimaryKeysW */
SQLRETURN SQL_API SQLPrimaryKeysW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL;
SQLULEN CpLength1, CpLength2, CpLength3;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
MDBUG_C_ENTER(Stmt->Connection, "SQLPrimaryKeysW");
MDBUG_C_DUMP(Stmt->Connection, StatementHandle, 0x);
MDBUG_C_DUMP(Stmt->Connection, CpCatalog, s);
MDBUG_C_DUMP(Stmt->Connection, CpLength1, d);
MDBUG_C_DUMP(Stmt->Connection, CpSchema, s);
MDBUG_C_DUMP(Stmt->Connection, CpLength2, d);
MDBUG_C_DUMP(Stmt->Connection, CpTable, s);
MDBUG_C_DUMP(Stmt->Connection, CpLength3, d);
ret= Stmt->Methods->PrimaryKeys(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpTable, (SQLSMALLINT)CpLength3);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLProcedureColumns */
SQLRETURN SQL_API SQLProcedureColumns(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *ProcName,
SQLSMALLINT NameLength3,
SQLCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->ProcedureColumns(Stmt, (char *)CatalogName,NameLength1, (char *)SchemaName, NameLength2,
(char *)ProcName, NameLength3, (char *)ColumnName, NameLength4);
}
/* }}} */
/* {{{ SQLProcedureColumnsW */
SQLRETURN SQL_API SQLProcedureColumnsW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *ProcName,
SQLSMALLINT NameLength3,
SQLWCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpProc= NULL,
*CpColumn= NULL;
SQLULEN CpLength1= 0, CpLength2= 0, CpLength3= 0, CpLength4= 0;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
if (CatalogName != NULL)
{
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (SchemaName != NULL)
{
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (ProcName != NULL)
{
CpProc= MADB_ConvertFromWChar(ProcName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (ColumnName != NULL)
{
CpColumn= MADB_ConvertFromWChar(ColumnName, NameLength4, &CpLength4, Stmt->Connection->ConnOrSrcCharset, NULL);
}
ret= Stmt->Methods->ProcedureColumns(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpProc, (SQLSMALLINT)CpLength3, CpColumn, (SQLSMALLINT)CpLength4);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpProc);
MADB_FREE(CpColumn);
return ret;
}
/* }}} */
/* {{{ SQLProcedures */
SQLRETURN SQL_API SQLProcedures(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *ProcName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->Procedures(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName,
NameLength2, (char *)ProcName, NameLength3);
}
/* }}} */
/* {{{ SQLProceduresW */
SQLRETURN SQL_API SQLProceduresW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *ProcName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpProc= NULL;
SQLULEN CpLength1, CpLength2, CpLength3;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpProc= MADB_ConvertFromWChar(ProcName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
ret= Stmt->Methods->Procedures(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpProc, (SQLSMALLINT)CpLength3);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpProc);
return ret;
}
/* }}} */
/* {{{ SQLPutData */
SQLRETURN SQL_API SQLPutData(SQLHSTMT StatementHandle,
SQLPOINTER DataPtr,
SQLLEN StrLen_or_Ind)
{
MADB_Stmt *Stmt=(MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLPutData");
MDBUG_C_DUMP(Stmt->Connection, DataPtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, StrLen_or_Ind, d);
ret= Stmt->Methods->PutData(Stmt, DataPtr, StrLen_or_Ind);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLRowCount */
SQLRETURN SQL_API SQLRowCount(SQLHSTMT StatementHandle,
SQLLEN *RowCountPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
MADB_CHECK_STMT_HANDLE(Stmt, stmt);
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->RowCount(Stmt, RowCountPtr);
}
/* }}} */
/* {{{ SQLSetConnectAttr */
SQLRETURN MA_SQLSetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MDBUG_C_ENTER(Dbc, "SQLSetConnectAttr");
MDBUG_C_DUMP(Dbc, Attribute, d);
MDBUG_C_DUMP(Dbc, ValuePtr, 0x);
MDBUG_C_DUMP(Dbc, StringLength, d);
ret= Dbc->Methods->SetAttr(Dbc, Attribute, ValuePtr, StringLength, FALSE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
SQLRETURN SQL_API SQLSetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
if (ConnectionHandle == SQL_NULL_HDBC)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Dbc *)ConnectionHandle)->Error);
return MA_SQLSetConnectAttr(ConnectionHandle, Attribute, ValuePtr, StringLength);
}
/* {{{ SQLSetConnectAttrW */
SQLRETURN SQL_API SQLSetConnectAttrW(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SetConnectAttrW");
MDBUG_C_DUMP(Dbc, Dbc, 0x);
MDBUG_C_DUMP(Dbc, Attribute, d);
MDBUG_C_DUMP(Dbc, ValuePtr, 0x);
MDBUG_C_DUMP(Dbc, StringLength, d);
ret= Dbc->Methods->SetAttr(Dbc, Attribute, ValuePtr, StringLength, TRUE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLSetConnectOption */
SQLRETURN SQL_API SQLSetConnectOption(SQLHDBC Hdbc, SQLUSMALLINT Option, SQLULEN Param)
{
SQLINTEGER StringLength= 0;
SQLRETURN ret;
if (!Hdbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Dbc*)Hdbc)->Error);
/* todo: do we have more string options ? */
if (Option == SQL_ATTR_CURRENT_CATALOG)
StringLength= SQL_NTS;
ret= MA_SQLSetConnectAttr(Hdbc, Option, (SQLPOINTER)Param, StringLength);
return ret;
}
/* }}} */
/* {{{ SQLSetConnectOptionW */
SQLRETURN SQL_API SQLSetConnectOptionW(SQLHDBC Hdbc, SQLUSMALLINT Option, SQLULEN Param)
{
SQLINTEGER StringLength= 0;
SQLRETURN ret;
MADB_Dbc *Dbc= (MADB_Dbc *)Hdbc;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SetSetConnectOptionW");
MDBUG_C_DUMP(Dbc, Option, d);
MDBUG_C_DUMP(Dbc, Param, u);
/* todo: do we have more string options ? */
if (Option == SQL_ATTR_CURRENT_CATALOG)
StringLength= SQL_NTS;
ret= Dbc->Methods->SetAttr(Dbc, Option, (SQLPOINTER)Param, StringLength, TRUE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLSetCursorName */
SQLRETURN SQL_API SQLSetCursorName(SQLHSTMT StatementHandle,
SQLCHAR *CursorName,
SQLSMALLINT NameLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->SetCursorName(Stmt, (char *)CursorName, NameLength);
}
/* }}} */
/* {{{ SQLSetCursorNameW */
SQLRETURN SQL_API SQLSetCursorNameW(SQLHSTMT StatementHandle,
SQLWCHAR *CursorName,
SQLSMALLINT NameLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
char *CpName= NULL;
SQLULEN Length;
SQLRETURN rc;
if (!Stmt)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&Stmt->Error);
CpName= MADB_ConvertFromWChar(CursorName, NameLength, &Length, Stmt->Connection->ConnOrSrcCharset, NULL);
rc= Stmt->Methods->SetCursorName(Stmt, (char *)CpName, (SQLINTEGER)Length);
MADB_FREE(CpName);
return rc;
}
/* }}} */
/* {{{ SQLSetDescField */
SQLRETURN SQL_API SQLSetDescField(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
if (!Desc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Desc->Error);
return MADB_DescSetField(DescriptorHandle, RecNumber, FieldIdentifier, ValuePtr, BufferLength, FALSE);
}
/* }}} */
/* {{{ SQLSetDescFieldW */
SQLRETURN SQL_API SQLSetDescFieldW(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
if (!Desc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Desc->Error);
return MADB_DescSetField(DescriptorHandle, RecNumber, FieldIdentifier, ValuePtr, BufferLength, TRUE);
}
/* }}} */
/* {{{ SQLSetDescRec */
SQLRETURN SQL_API SQLSetDescRec(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT Type,
SQLSMALLINT SubType,
SQLLEN Length,
SQLSMALLINT Precision,
SQLSMALLINT Scale,
SQLPOINTER DataPtr,
SQLLEN *StringLengthPtr,
SQLLEN *IndicatorPtr)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
MADB_NOT_IMPLEMENTED(Desc);
}
/* }}} */
/* {{{ SQLSetDescRecW */
SQLRETURN SQL_API SQLSetDescRecW(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT Type,
SQLSMALLINT SubType,
SQLLEN Length,
SQLSMALLINT Precision,
SQLSMALLINT Scale,
SQLPOINTER DataPtr,
SQLLEN *StringLengthPtr,
SQLLEN *IndicatorPtr)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
MADB_NOT_IMPLEMENTED(Desc);
}
/* }}} */
/* {{{ SQLSetEnvAttr */
SQLRETURN SQL_API SQLSetEnvAttr(SQLHENV EnvironmentHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
MADB_Env *Env= (MADB_Env *)EnvironmentHandle;
SQLRETURN ret;
MDBUG_ENTER("SQLSetEnvAttr");
MDBUG_DUMP(Attribute, d);
MDBUG_DUMP(ValuePtr, 0x);
if (!Env)
ret= SQL_INVALID_HANDLE;
else
{
MADB_CLEAR_ERROR(&Env->Error);
ret= MADB_EnvSetAttr(Env, Attribute, ValuePtr, StringLength);
}
MDBUG_DUMP(ret, d);
MDBUG_RETURN(ret);
}
/* }}} */
/* {{{ SQLSetPos */
SQLRETURN SQL_API SQLSetPos(SQLHSTMT StatementHandle,
SQLSETPOSIROW RowNumber,
SQLUSMALLINT Operation,
SQLUSMALLINT LockType)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLSetPos");
MDBUG_C_DUMP(Stmt->Connection, RowNumber, d);
MDBUG_C_DUMP(Stmt->Connection, Operation, u);
MDBUG_C_DUMP(Stmt->Connection, LockType, d);
ret= Stmt->Methods->SetPos(Stmt, RowNumber, Operation, LockType, 0);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLSetParam */
SQLRETURN SQL_API SQLSetParam(SQLHSTMT stmt,
SQLUSMALLINT par,
SQLSMALLINT type,
SQLSMALLINT sqltype,
SQLULEN coldef,
SQLSMALLINT scale,
SQLPOINTER val,
SQLLEN *nval)
{
if (!stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Stmt*)stmt)->Error);
return MA_SQLBindParameter(stmt, par, SQL_PARAM_INPUT_OUTPUT, type, sqltype, coldef,
scale, val, SQL_SETPARAM_VALUE_MAX, nval);
}
/* }}} */
/* {{{ SQLBindParam - we need it for direct linking mainly */
SQLRETURN SQL_API SQLBindParam(SQLHSTMT StatementHandle,
SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
SQLSMALLINT ParameterType, SQLULEN LengthPrecision,
SQLSMALLINT ParameterScale, SQLPOINTER ParameterValue,
SQLLEN *StrLen_or_Ind)
{
if (!StatementHandle)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLBindParameter(StatementHandle, ParameterNumber, SQL_PARAM_INPUT, ValueType, ParameterType, LengthPrecision, ParameterScale,
ParameterValue, SQL_SETPARAM_VALUE_MAX, StrLen_or_Ind);
}
/* }}} */
/* {{{ SQLSetStmtAttr */
SQLRETURN MA_SQLSetStmtAttr(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MDBUG_C_ENTER(Stmt->Connection, "SQLSetStmtAttr");
MDBUG_C_DUMP(Stmt->Connection, Attribute, d);
MDBUG_C_DUMP(Stmt->Connection, ValuePtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, StringLength, d);
ret= Stmt->Methods->SetAttr(Stmt, Attribute, ValuePtr, StringLength);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLSetStmtAttr(StatementHandle, Attribute, ValuePtr, StringLength);
}
/* }}} */
/* {{{ SQLSetStmtAttrW */
SQLRETURN SQL_API SQLSetStmtAttrW(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLSetStmtAttr(StatementHandle, Attribute, ValuePtr, StringLength);
}
/* }}} */
/* {{{ SQLSetStmtOption */
SQLRETURN SQL_API SQLSetStmtOption(SQLHSTMT StatementHandle,
SQLUSMALLINT Option, SQLULEN Value)
{
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLSetStmtAttr(StatementHandle, Option, (SQLPOINTER)Value, SQL_NTS);
}
/* }}} */
/* {{{ SQLSpecialColumns */
SQLRETURN SQL_API SQLSpecialColumns(SQLHSTMT StatementHandle,
SQLUSMALLINT IdentifierType,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLUSMALLINT Scope,
SQLUSMALLINT Nullable)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->SpecialColumns(Stmt,IdentifierType, (char *)CatalogName, NameLength1,
(char *)SchemaName, NameLength2,
(char *)TableName, NameLength3, Scope, Nullable);
}
/* }}} */
/* {{{ SQLSpecialColumnsW */
SQLRETURN SQL_API SQLSpecialColumnsW(SQLHSTMT StatementHandle,
SQLUSMALLINT IdentifierType,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3,
SQLUSMALLINT Scope,
SQLUSMALLINT Nullable)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL;
SQLULEN CpLength1, CpLength2, CpLength3;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
ret= Stmt->Methods->SpecialColumns(Stmt,IdentifierType, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema,
(SQLSMALLINT)CpLength2, CpTable, (SQLSMALLINT)CpLength3, Scope, Nullable);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
return ret;
}
/* }}} */
/* {{{ SQLStatistics */
SQLRETURN SQL_API SQLStatistics(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLUSMALLINT Unique,
SQLUSMALLINT Reserved)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->Statistics(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3, Unique, Reserved);
}
/* }}} */
/* {{{ SQLStatisticsW */
SQLRETURN SQL_API SQLStatisticsW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3,
SQLUSMALLINT Unique,
SQLUSMALLINT Reserved)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL;
SQLULEN CpLength1, CpLength2, CpLength3;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
if (!Stmt)
return SQL_INVALID_HANDLE;
ret= Stmt->Methods->Statistics(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpTable, (SQLSMALLINT)CpLength3, Unique, Reserved);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
return ret;
}
/* }}} */
/* {{{ SQLTablePrivileges */
SQLRETURN SQL_API SQLTablePrivileges(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->TablePrivileges(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3);
}
/* }}} */
/* {{{ SQLTablePrivilegesW */
SQLRETURN SQL_API SQLTablePrivilegesW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
char *CpCatalog= NULL,
*CpTable= NULL;
SQLULEN CpLength1= 0, CpLength3= 0;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
if (CatalogName != NULL)
{
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (TableName != NULL)
{
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
}
ret= Stmt->Methods->TablePrivileges(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, NULL, 0, CpTable, (SQLSMALLINT)CpLength3);
MADB_FREE(CpCatalog);
MADB_FREE(CpTable);
return ret;
}
/* }}} */
/* {{{ SQLTables */
SQLRETURN SQL_API SQLTables(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLCHAR *TableType,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->Tables(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName,NameLength3, (char *)TableType, NameLength4);
}
/* }}} */
/* {{{ SQLTablesW */
SQLRETURN SQL_API SQLTablesW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3,
SQLWCHAR *TableType,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL,
*CpType= NULL;
SQLULEN CpLength1= 0, CpLength2= 0, CpLength3= 0, CpLength4= 0;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
if (CatalogName)
{
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (SchemaName)
{
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (TableName)
{
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (TableType)
{
CpType= MADB_ConvertFromWChar(TableType, NameLength4, &CpLength4, Stmt->Connection->ConnOrSrcCharset, NULL);
}
ret= Stmt->Methods->Tables(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpTable, (SQLSMALLINT)CpLength3, CpType, (SQLSMALLINT)CpLength4);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
MADB_FREE(CpType);
return ret;
}
/* }}} */
/* {{{ SQLSetScrollOptions */
SQLRETURN SQL_API SQLSetScrollOptions(SQLHSTMT hstmt,
SQLUSMALLINT Concurrency,
SQLLEN crowKeySet,
SQLUSMALLINT crowRowSet)
{
MADB_Stmt *Stmt= (MADB_Stmt *)hstmt;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return MADB_DescSetField(Stmt->Ard, 0, SQL_DESC_ARRAY_SIZE, (SQLPOINTER)(SQLULEN)crowKeySet, SQL_IS_USMALLINT, 0);
}
/* }}} */
/* {{{ SQLParamOptions */
SQLRETURN SQL_API SQLParamOptions(
SQLHSTMT hstmt,
SQLULEN crow,
SQLULEN *pirow)
{
MADB_Stmt *Stmt= (MADB_Stmt *)hstmt;
SQLRETURN result;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
result= MADB_DescSetField(Stmt->Apd, 0, SQL_DESC_ARRAY_SIZE, (SQLPOINTER)crow, SQL_IS_UINTEGER, 0);
if (SQL_SUCCEEDED(result))
{
result= MADB_DescSetField(Stmt->Ipd, 0, SQL_DESC_ROWS_PROCESSED_PTR, (SQLPOINTER)pirow, SQL_IS_POINTER, 0);
}
return result;
}
/* }}} */
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/openlookeng/hetu-odbc-driver.git
git@gitee.com:openlookeng/hetu-odbc-driver.git
openlookeng
hetu-odbc-driver
hetu-odbc-driver
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385