oci8_interface.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Stig Sæther Bakken <ssb@php.net> |
  14. | Thies C. Arntzen <thies@thieso.net> |
  15. | |
  16. | Collection support by Andy Sautins <asautins@veripost.net> |
  17. | Temporary LOB support by David Benson <dbenson@mancala.com> |
  18. | ZTS per process OCIPLogon by Harald Radi <harald.radi@nme.at> |
  19. | |
  20. | Redesigned by: Antony Dovgal <antony@zend.com> |
  21. | Andi Gutmans <andi@php.net> |
  22. | Wez Furlong <wez@omniti.com> |
  23. +----------------------------------------------------------------------+
  24. */
  25. #ifdef HAVE_CONFIG_H
  26. #include "config.h"
  27. #endif
  28. #include "php.h"
  29. #include "ext/standard/info.h"
  30. #include "php_ini.h"
  31. #ifdef HAVE_OCI8
  32. #include "php_oci8.h"
  33. #include "php_oci8_int.h"
  34. #ifndef OCI_STMT_CALL
  35. #define OCI_STMT_CALL 10
  36. #endif
  37. #define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
  38. /* {{{ Register a callback function for Oracle Transparent Application Failover (TAF) */
  39. PHP_FUNCTION(oci_register_taf_callback)
  40. {
  41. zval *z_connection;
  42. php_oci_connection *connection;
  43. zend_fcall_info fci;
  44. zend_fcall_info_cache fcc;
  45. zval *callback = NULL;
  46. if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|f!", &z_connection, &fci, &fcc) == FAILURE) {
  47. RETURN_THROWS();
  48. }
  49. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  50. /* If callable passed, assign callback zval so that it can be passed to php_oci_register_taf_callback() */
  51. if (ZEND_FCI_INITIALIZED(fci)) {
  52. callback = &fci.function_name;
  53. }
  54. if (php_oci_register_taf_callback(connection, callback) == 0) {
  55. RETURN_TRUE;
  56. } else {
  57. RETURN_FALSE;
  58. }
  59. }
  60. /* }}} */
  61. /* {{{ Unregister a callback function for Oracle Transparent Application Failover (TAF) */
  62. PHP_FUNCTION(oci_unregister_taf_callback)
  63. {
  64. zval *z_connection;
  65. php_oci_connection *connection;
  66. if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_connection) == FAILURE) {
  67. RETURN_THROWS();
  68. }
  69. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  70. if (php_oci_unregister_taf_callback(connection) == 0) {
  71. RETURN_TRUE;
  72. } else {
  73. RETURN_FALSE;
  74. }
  75. }
  76. /* }}} */
  77. /* {{{ Define a PHP variable to an Oracle column by name */
  78. /* if you want to define a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE defining!!! */
  79. PHP_FUNCTION(oci_define_by_name)
  80. {
  81. zval *stmt, *var;
  82. char *name;
  83. size_t name_len;
  84. zend_long type = 0;
  85. php_oci_statement *statement;
  86. php_oci_define *define;
  87. zend_string *zvtmp;
  88. ZEND_PARSE_PARAMETERS_START(3, 4)
  89. Z_PARAM_RESOURCE(stmt)
  90. Z_PARAM_STRING(name, name_len)
  91. Z_PARAM_ZVAL(var)
  92. Z_PARAM_OPTIONAL
  93. Z_PARAM_LONG(type)
  94. ZEND_PARSE_PARAMETERS_END();
  95. if (!name_len) {
  96. zend_argument_value_error(2, "cannot be empty");
  97. RETURN_THROWS();
  98. }
  99. PHP_OCI_ZVAL_TO_STATEMENT(stmt, statement);
  100. if (statement->defines == NULL) {
  101. ALLOC_HASHTABLE(statement->defines);
  102. zend_hash_init(statement->defines, 13, NULL, php_oci_define_hash_dtor, 0);
  103. }
  104. else if (zend_hash_str_exists(statement->defines, (const char *)name, name_len)) {
  105. RETURN_FALSE;
  106. }
  107. define = ecalloc(1,sizeof(php_oci_define));
  108. /* if (zend_hash_add(statement->defines, name, name_len, define, sizeof(php_oci_define), (void **)&tmp_define) == SUCCESS) { */
  109. zvtmp = zend_string_init(name, name_len, 0);
  110. if ((define = zend_hash_add_new_ptr(statement->defines, zvtmp, define)) != NULL) {
  111. zend_string_release_ex(zvtmp, 0);
  112. } else {
  113. efree(define);
  114. zend_string_release_ex(zvtmp, 0);
  115. RETURN_FALSE;
  116. }
  117. define->name = (text*) ecalloc(1, name_len+1);
  118. memcpy(define->name, name, name_len);
  119. define->name[name_len] = '\0';
  120. define->name_len = (ub4) name_len;
  121. define->type = (ub4) type;
  122. ZEND_ASSERT(Z_ISREF_P(var));
  123. ZVAL_COPY(&define->val, var);
  124. RETURN_TRUE;
  125. }
  126. /* }}} */
  127. /* {{{ Bind a PHP variable to an Oracle placeholder by name */
  128. /* if you want to bind a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE binding!!! */
  129. PHP_FUNCTION(oci_bind_by_name)
  130. {
  131. ub2 bind_type = SQLT_CHR; /* unterminated string */
  132. size_t name_len;
  133. zend_long maxlen = -1, type = 0;
  134. char *name;
  135. zval *z_statement;
  136. zval *bind_var = NULL;
  137. php_oci_statement *statement;
  138. ZEND_PARSE_PARAMETERS_START(3, 5)
  139. Z_PARAM_RESOURCE(z_statement)
  140. Z_PARAM_STRING(name, name_len)
  141. Z_PARAM_ZVAL(bind_var)
  142. Z_PARAM_OPTIONAL
  143. Z_PARAM_LONG(maxlen)
  144. Z_PARAM_LONG(type)
  145. ZEND_PARSE_PARAMETERS_END();
  146. if (type) {
  147. bind_type = (ub2) type;
  148. }
  149. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  150. if (php_oci_bind_by_name(statement, name, name_len, bind_var, maxlen, bind_type)) {
  151. RETURN_FALSE;
  152. }
  153. RETURN_TRUE;
  154. }
  155. /* }}} */
  156. /* {{{ Bind a PHP array to an Oracle PL/SQL type by name */
  157. PHP_FUNCTION(oci_bind_array_by_name)
  158. {
  159. size_t name_len;
  160. zend_long max_item_len = -1;
  161. zend_long max_array_len = 0;
  162. zend_long type = SQLT_AFC;
  163. char *name;
  164. zval *z_statement;
  165. zval *bind_var = NULL;
  166. php_oci_statement *statement;
  167. ZEND_PARSE_PARAMETERS_START(4, 6)
  168. Z_PARAM_RESOURCE(z_statement)
  169. Z_PARAM_STRING(name, name_len)
  170. Z_PARAM_ZVAL(bind_var)
  171. Z_PARAM_LONG(max_array_len)
  172. Z_PARAM_OPTIONAL
  173. Z_PARAM_LONG(max_item_len)
  174. Z_PARAM_LONG(type)
  175. ZEND_PARSE_PARAMETERS_END();
  176. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  177. if (ZEND_NUM_ARGS() == 5 && max_item_len <= 0) {
  178. max_item_len = -1;
  179. }
  180. if (max_array_len <= 0) {
  181. zend_argument_value_error(4, "must be greater than 0");
  182. RETURN_THROWS();
  183. }
  184. if (php_oci_bind_array_by_name(statement, name, (sb4) name_len, bind_var, max_array_len, max_item_len, type)) {
  185. RETURN_FALSE;
  186. }
  187. RETURN_TRUE;
  188. }
  189. /* }}} */
  190. /* {{{ Deletes large object description */
  191. PHP_FUNCTION(oci_free_descriptor)
  192. {
  193. zval *tmp, *z_descriptor;
  194. php_oci_descriptor *descriptor;
  195. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
  196. RETURN_THROWS();
  197. }
  198. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  199. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  200. RETURN_FALSE;
  201. }
  202. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  203. zend_list_close(descriptor->id);
  204. RETURN_TRUE;
  205. }
  206. /* }}} */
  207. /* {{{ Saves a large object */
  208. PHP_FUNCTION(oci_lob_save)
  209. {
  210. zval *tmp, *z_descriptor;
  211. php_oci_descriptor *descriptor;
  212. char *data;
  213. size_t data_len;
  214. zend_long offset = 0;
  215. ub4 bytes_written;
  216. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &offset) == FAILURE) {
  217. RETURN_THROWS();
  218. }
  219. if (offset < 0) {
  220. zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
  221. RETURN_THROWS();
  222. }
  223. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  224. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  225. RETURN_FALSE;
  226. }
  227. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  228. if (php_oci_lob_write(descriptor, (ub4) offset, data, (ub4) data_len, &bytes_written)) {
  229. RETURN_FALSE;
  230. }
  231. RETURN_TRUE;
  232. }
  233. /* }}} */
  234. /* {{{ Loads file into a LOB */
  235. PHP_FUNCTION(oci_lob_import)
  236. {
  237. zval *tmp, *z_descriptor;
  238. php_oci_descriptor *descriptor;
  239. char *filename;
  240. size_t filename_len;
  241. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) {
  242. RETURN_THROWS();
  243. }
  244. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  245. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  246. RETURN_FALSE;
  247. }
  248. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  249. if (php_oci_lob_import(descriptor, filename)) {
  250. RETURN_FALSE;
  251. }
  252. RETURN_TRUE;
  253. }
  254. /* }}} */
  255. /* {{{ Loads a large object */
  256. PHP_FUNCTION(oci_lob_load)
  257. {
  258. zval *tmp, *z_descriptor;
  259. php_oci_descriptor *descriptor;
  260. char *buffer = NULL;
  261. ub4 buffer_len;
  262. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
  263. RETURN_THROWS();
  264. }
  265. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  266. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  267. RETURN_FALSE;
  268. }
  269. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  270. if (php_oci_lob_read(descriptor, -1, 0, &buffer, &buffer_len)) {
  271. RETURN_FALSE;
  272. }
  273. if (buffer_len > 0) {
  274. zend_string *ret = zend_string_init(buffer, buffer_len, 0);
  275. if (buffer)
  276. efree(buffer);
  277. RETURN_STR(ret);
  278. }
  279. else {
  280. RETURN_EMPTY_STRING();
  281. }
  282. }
  283. /* }}} */
  284. /* {{{ Reads particular part of a large object */
  285. PHP_FUNCTION(oci_lob_read)
  286. {
  287. zval *tmp, *z_descriptor;
  288. php_oci_descriptor *descriptor;
  289. zend_long length;
  290. char *buffer;
  291. ub4 buffer_len;
  292. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &z_descriptor, oci_lob_class_entry_ptr, &length) == FAILURE) {
  293. RETURN_THROWS();
  294. }
  295. if (length <= 0) {
  296. zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than 0");
  297. RETURN_THROWS();
  298. }
  299. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  300. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  301. RETURN_FALSE;
  302. }
  303. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  304. if (php_oci_lob_read(descriptor, length, descriptor->lob_current_position, &buffer, &buffer_len)) {
  305. RETURN_FALSE;
  306. }
  307. if (buffer_len > 0) {
  308. zend_string *ret = zend_string_init(buffer, buffer_len, 0);
  309. efree(buffer);
  310. RETURN_STR(ret);
  311. }
  312. else {
  313. RETURN_EMPTY_STRING();
  314. }
  315. }
  316. /* }}} */
  317. /* {{{ Checks if EOF is reached */
  318. PHP_FUNCTION(oci_lob_eof)
  319. {
  320. zval *tmp, *z_descriptor;
  321. php_oci_descriptor *descriptor;
  322. ub4 lob_length;
  323. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
  324. RETURN_THROWS();
  325. }
  326. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  327. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  328. RETURN_FALSE;
  329. }
  330. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  331. if (!php_oci_lob_get_length(descriptor, &lob_length)) {
  332. if (lob_length == descriptor->lob_current_position) {
  333. RETURN_TRUE;
  334. }
  335. }
  336. RETURN_FALSE;
  337. }
  338. /* }}} */
  339. /* {{{ Tells LOB pointer position */
  340. PHP_FUNCTION(oci_lob_tell)
  341. {
  342. zval *tmp, *z_descriptor;
  343. php_oci_descriptor *descriptor;
  344. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
  345. RETURN_THROWS();
  346. }
  347. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  348. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  349. RETURN_FALSE;
  350. }
  351. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  352. RETURN_LONG(descriptor->lob_current_position);
  353. }
  354. /* }}} */
  355. /* {{{ Rewind pointer of a LOB */
  356. PHP_FUNCTION(oci_lob_rewind)
  357. {
  358. zval *tmp, *z_descriptor;
  359. php_oci_descriptor *descriptor;
  360. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
  361. RETURN_THROWS();
  362. }
  363. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  364. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  365. RETURN_FALSE;
  366. }
  367. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  368. descriptor->lob_current_position = 0;
  369. RETURN_TRUE;
  370. }
  371. /* }}} */
  372. /* {{{ Moves the pointer of a LOB */
  373. PHP_FUNCTION(oci_lob_seek)
  374. {
  375. zval *tmp, *z_descriptor;
  376. php_oci_descriptor *descriptor;
  377. zend_long offset, whence = PHP_OCI_SEEK_SET;
  378. ub4 lob_length;
  379. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol|l", &z_descriptor, oci_lob_class_entry_ptr, &offset, &whence) == FAILURE) {
  380. RETURN_THROWS();
  381. }
  382. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  383. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  384. RETURN_FALSE;
  385. }
  386. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  387. if (php_oci_lob_get_length(descriptor, &lob_length)) {
  388. RETURN_FALSE;
  389. }
  390. switch(whence) {
  391. case PHP_OCI_SEEK_CUR:
  392. descriptor->lob_current_position += (ub4) offset;
  393. break;
  394. case PHP_OCI_SEEK_END:
  395. if ((descriptor->lob_size + offset) >= 0) {
  396. descriptor->lob_current_position = descriptor->lob_size + (ub4) offset;
  397. }
  398. else {
  399. descriptor->lob_current_position = 0;
  400. }
  401. break;
  402. case PHP_OCI_SEEK_SET:
  403. default:
  404. descriptor->lob_current_position = (offset > 0) ? (ub4) offset : 0;
  405. break;
  406. }
  407. if (descriptor->lob_current_position > UB4MAXVAL) {
  408. php_error_docref(NULL, E_WARNING, "Invalid offset or LOB position");
  409. RETURN_FALSE;
  410. }
  411. RETURN_TRUE;
  412. }
  413. /* }}} */
  414. /* {{{ Returns size of a large object */
  415. PHP_FUNCTION(oci_lob_size)
  416. {
  417. zval *tmp, *z_descriptor;
  418. php_oci_descriptor *descriptor;
  419. ub4 lob_length;
  420. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
  421. RETURN_THROWS();
  422. }
  423. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  424. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  425. RETURN_FALSE;
  426. }
  427. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  428. if (php_oci_lob_get_length(descriptor, &lob_length)) {
  429. RETURN_FALSE;
  430. }
  431. RETURN_LONG(lob_length);
  432. }
  433. /* }}} */
  434. /* {{{ Writes data to current position of a LOB */
  435. PHP_FUNCTION(oci_lob_write)
  436. {
  437. zval *tmp, *z_descriptor;
  438. php_oci_descriptor *descriptor;
  439. size_t data_len;
  440. zend_long write_len;
  441. bool write_len_is_null = 1;
  442. ub4 bytes_written;
  443. char *data;
  444. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l!", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &write_len, &write_len_is_null) == FAILURE) {
  445. RETURN_THROWS();
  446. }
  447. if (!write_len_is_null) {
  448. data_len = MIN((zend_long) data_len, write_len);
  449. }
  450. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  451. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  452. RETURN_FALSE;
  453. }
  454. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  455. if (data_len <= 0) {
  456. RETURN_LONG(0);
  457. }
  458. if (php_oci_lob_write(descriptor, descriptor->lob_current_position, data, (ub4) data_len, &bytes_written)) {
  459. RETURN_FALSE;
  460. }
  461. RETURN_LONG(bytes_written);
  462. }
  463. /* }}} */
  464. /* {{{ Appends data from a LOB to another LOB */
  465. PHP_FUNCTION(oci_lob_append)
  466. {
  467. zval *tmp_dest, *tmp_from, *z_descriptor_dest, *z_descriptor_from;
  468. php_oci_descriptor *descriptor_dest, *descriptor_from;
  469. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr) == FAILURE) {
  470. RETURN_THROWS();
  471. }
  472. if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor")-1)) == NULL) {
  473. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
  474. RETURN_FALSE;
  475. }
  476. if ((tmp_from = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_from), "descriptor", sizeof("descriptor")-1)) == NULL) {
  477. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
  478. RETURN_FALSE;
  479. }
  480. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_dest, descriptor_dest);
  481. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_from, descriptor_from);
  482. if (php_oci_lob_append(descriptor_dest, descriptor_from)) {
  483. RETURN_FALSE;
  484. }
  485. /* XXX should we increase lob_size here ? */
  486. RETURN_TRUE;
  487. }
  488. /* }}} */
  489. /* {{{ Truncates a LOB */
  490. PHP_FUNCTION(oci_lob_truncate)
  491. {
  492. zval *tmp, *z_descriptor;
  493. php_oci_descriptor *descriptor;
  494. zend_long trim_length = 0;
  495. ub4 ub_trim_length;
  496. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &z_descriptor, oci_lob_class_entry_ptr, &trim_length) == FAILURE) {
  497. RETURN_THROWS();
  498. }
  499. if (trim_length < 0) {
  500. zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
  501. RETURN_THROWS();
  502. }
  503. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  504. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  505. RETURN_FALSE;
  506. }
  507. ub_trim_length = (ub4) trim_length;
  508. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  509. if (php_oci_lob_truncate(descriptor, ub_trim_length)) {
  510. RETURN_FALSE;
  511. }
  512. RETURN_TRUE;
  513. }
  514. /* }}} */
  515. /* {{{ Erases a specified portion of the internal LOB, starting at a specified offset */
  516. PHP_FUNCTION(oci_lob_erase)
  517. {
  518. zval *tmp, *z_descriptor;
  519. php_oci_descriptor *descriptor;
  520. ub4 bytes_erased;
  521. zend_long offset, length;
  522. bool offset_is_null = 1, length_is_null = 1;
  523. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &offset, &offset_is_null, &length, &length_is_null) == FAILURE) {
  524. RETURN_THROWS();
  525. }
  526. if (offset_is_null) {
  527. offset = -1;
  528. } else if (offset < 0) {
  529. zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
  530. RETURN_THROWS();
  531. }
  532. if (length_is_null) {
  533. length = -1;
  534. } else if (length < 0) {
  535. zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
  536. RETURN_THROWS();
  537. }
  538. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  539. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  540. RETURN_FALSE;
  541. }
  542. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  543. if (php_oci_lob_erase(descriptor, offset, (ub4) length, &bytes_erased)) {
  544. RETURN_FALSE;
  545. }
  546. RETURN_LONG(bytes_erased);
  547. }
  548. /* }}} */
  549. /* {{{ Flushes the LOB buffer */
  550. PHP_FUNCTION(oci_lob_flush)
  551. {
  552. zval *tmp, *z_descriptor;
  553. php_oci_descriptor *descriptor;
  554. zend_long flush_flag = 0;
  555. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &z_descriptor, oci_lob_class_entry_ptr, &flush_flag) == FAILURE) {
  556. RETURN_THROWS();
  557. }
  558. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  559. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  560. RETURN_FALSE;
  561. }
  562. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  563. if (descriptor->buffering == PHP_OCI_LOB_BUFFER_DISABLED) {
  564. /* buffering wasn't enabled, there is nothing to flush */
  565. RETURN_FALSE;
  566. }
  567. if (php_oci_lob_flush(descriptor, flush_flag)) {
  568. RETURN_FALSE;
  569. }
  570. RETURN_TRUE;
  571. }
  572. /* }}} */
  573. /* {{{ Enables/disables buffering for a LOB */
  574. PHP_FUNCTION(ocisetbufferinglob)
  575. {
  576. zval *tmp, *z_descriptor;
  577. php_oci_descriptor *descriptor;
  578. bool flag;
  579. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ob", &z_descriptor, oci_lob_class_entry_ptr, &flag) == FAILURE) {
  580. RETURN_THROWS();
  581. }
  582. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  583. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  584. RETURN_FALSE;
  585. }
  586. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  587. if (php_oci_lob_set_buffering(descriptor, flag)) {
  588. RETURN_FALSE;
  589. }
  590. RETURN_TRUE;
  591. }
  592. /* }}} */
  593. /* {{{ Returns current state of buffering for a LOB */
  594. PHP_FUNCTION(ocigetbufferinglob)
  595. {
  596. zval *tmp, *z_descriptor;
  597. php_oci_descriptor *descriptor;
  598. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
  599. RETURN_THROWS();
  600. }
  601. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  602. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  603. RETURN_FALSE;
  604. }
  605. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  606. if (descriptor->buffering != PHP_OCI_LOB_BUFFER_DISABLED) {
  607. RETURN_TRUE;
  608. }
  609. RETURN_FALSE;
  610. }
  611. /* }}} */
  612. /* {{{ Copies data from a LOB to another LOB */
  613. PHP_FUNCTION(oci_lob_copy)
  614. {
  615. zval *tmp_dest, *tmp_from, *z_descriptor_dest, *z_descriptor_from;
  616. php_oci_descriptor *descriptor_dest, *descriptor_from;
  617. zend_long length;
  618. bool length_is_null = 1;
  619. if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO|l!", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr, &length, &length_is_null) == FAILURE) {
  620. RETURN_THROWS();
  621. }
  622. if (length_is_null) {
  623. length = -1;
  624. } else if (length < 0) {
  625. zend_argument_value_error(3, "must be greater than or equal to 0");
  626. RETURN_THROWS();
  627. }
  628. if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor")-1)) == NULL) {
  629. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
  630. RETURN_FALSE;
  631. }
  632. if ((tmp_from = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_from), "descriptor", sizeof("descriptor")-1)) == NULL) {
  633. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
  634. RETURN_FALSE;
  635. }
  636. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_dest, descriptor_dest);
  637. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_from, descriptor_from);
  638. if (php_oci_lob_copy(descriptor_dest, descriptor_from, length)) {
  639. RETURN_FALSE;
  640. }
  641. RETURN_TRUE;
  642. }
  643. /* }}} */
  644. /* {{{ Tests to see if two LOB/FILE locators are equal */
  645. PHP_FUNCTION(oci_lob_is_equal)
  646. {
  647. zval *tmp_first, *tmp_second, *z_descriptor_first, *z_descriptor_second;
  648. php_oci_descriptor *descriptor_first, *descriptor_second;
  649. boolean is_equal;
  650. if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO", &z_descriptor_first, oci_lob_class_entry_ptr, &z_descriptor_second, oci_lob_class_entry_ptr) == FAILURE) {
  651. RETURN_THROWS();
  652. }
  653. if ((tmp_first = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_first), "descriptor", sizeof("descriptor")-1)) == NULL) {
  654. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
  655. RETURN_FALSE;
  656. }
  657. if ((tmp_second = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_second), "descriptor", sizeof("descriptor")-1)) == NULL) {
  658. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
  659. RETURN_FALSE;
  660. }
  661. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_first, descriptor_first);
  662. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_second, descriptor_second);
  663. if (php_oci_lob_is_equal(descriptor_first, descriptor_second, &is_equal)) {
  664. RETURN_FALSE;
  665. }
  666. if (is_equal == TRUE) {
  667. RETURN_TRUE;
  668. }
  669. RETURN_FALSE;
  670. }
  671. /* }}} */
  672. /* {{{ Writes a large object into a file */
  673. PHP_FUNCTION(oci_lob_export)
  674. {
  675. zval *tmp, *z_descriptor;
  676. php_oci_descriptor *descriptor;
  677. char *filename;
  678. char *buffer;
  679. size_t filename_len;
  680. zend_long start, length, block_length;
  681. bool start_is_null = 1, length_is_null = 1;
  682. php_stream *stream;
  683. ub4 lob_length;
  684. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &start_is_null, &length, &length_is_null) == FAILURE) {
  685. RETURN_THROWS();
  686. }
  687. if (start_is_null) {
  688. start = -1;
  689. } else if (start < 0) {
  690. zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
  691. RETURN_THROWS();
  692. }
  693. if (length_is_null) {
  694. length = -1;
  695. } else if (length < 0) {
  696. zend_argument_value_error(ERROR_ARG_POS(4), "must be greater than or equal to 0");
  697. RETURN_THROWS();
  698. }
  699. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  700. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  701. RETURN_FALSE;
  702. }
  703. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  704. if (php_oci_lob_get_length(descriptor, &lob_length)) {
  705. RETURN_FALSE;
  706. }
  707. if (start == -1) {
  708. start = 0;
  709. }
  710. if (length == -1) {
  711. length = lob_length - descriptor->lob_current_position;
  712. }
  713. if (lob_length == 0) {
  714. length = 0;
  715. }
  716. if (length == 0) {
  717. /* nothing to write, fail silently */
  718. RETURN_FALSE;
  719. }
  720. if (php_check_open_basedir(filename)) {
  721. RETURN_FALSE;
  722. }
  723. stream = php_stream_open_wrapper_ex(filename, "w", REPORT_ERRORS, NULL, NULL);
  724. block_length = PHP_OCI_LOB_BUFFER_SIZE;
  725. if (block_length > length) {
  726. block_length = length;
  727. }
  728. while(length > 0) {
  729. ub4 tmp_bytes_read = 0;
  730. if (php_oci_lob_read(descriptor, block_length, start, &buffer, &tmp_bytes_read)) {
  731. php_stream_close(stream);
  732. RETURN_FALSE;
  733. }
  734. if (tmp_bytes_read && !php_stream_write(stream, buffer, tmp_bytes_read)) {
  735. php_stream_close(stream);
  736. if (buffer)
  737. efree(buffer);
  738. RETURN_FALSE;
  739. }
  740. if (buffer) {
  741. efree(buffer);
  742. }
  743. length -= tmp_bytes_read;
  744. descriptor->lob_current_position += tmp_bytes_read;
  745. start += tmp_bytes_read;
  746. if (block_length > length) {
  747. block_length = length;
  748. }
  749. }
  750. php_stream_close(stream);
  751. RETURN_TRUE;
  752. }
  753. /* }}} */
  754. /* {{{ Writes temporary blob */
  755. PHP_METHOD(OCILob, writeTemporary)
  756. {
  757. zval *tmp, *z_descriptor;
  758. php_oci_descriptor *descriptor;
  759. char *data;
  760. size_t data_len;
  761. zend_long type = OCI_TEMP_CLOB;
  762. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &type) == FAILURE) {
  763. RETURN_THROWS();
  764. }
  765. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  766. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  767. RETURN_FALSE;
  768. }
  769. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  770. if (php_oci_lob_write_tmp(descriptor, type, data, (int) data_len)) {
  771. RETURN_FALSE;
  772. }
  773. RETURN_TRUE;
  774. }
  775. /* }}} */
  776. /* {{{ Closes lob descriptor */
  777. PHP_METHOD(OCILob, close)
  778. {
  779. zval *tmp, *z_descriptor;
  780. php_oci_descriptor *descriptor;
  781. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
  782. RETURN_THROWS();
  783. }
  784. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
  785. php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
  786. RETURN_FALSE;
  787. }
  788. PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
  789. if (php_oci_lob_close(descriptor)) {
  790. RETURN_FALSE;
  791. }
  792. RETURN_TRUE;
  793. }
  794. /* }}} */
  795. /* {{{ Initialize a new empty descriptor LOB/FILE (LOB is default) */
  796. PHP_FUNCTION(oci_new_descriptor)
  797. {
  798. zval *z_connection;
  799. php_oci_connection *connection;
  800. php_oci_descriptor *descriptor;
  801. zend_long type = OCI_DTYPE_LOB;
  802. if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &z_connection, &type) == FAILURE) {
  803. RETURN_THROWS();
  804. }
  805. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  806. /* php_oci_lob_create() checks type */
  807. descriptor = php_oci_lob_create(connection, type);
  808. if (!descriptor) {
  809. RETURN_NULL();
  810. }
  811. object_init_ex(return_value, oci_lob_class_entry_ptr);
  812. add_property_resource(return_value, "descriptor", descriptor->id);
  813. }
  814. /* }}} */
  815. /* {{{ Rollback the current context */
  816. PHP_FUNCTION(oci_rollback)
  817. {
  818. zval *z_connection;
  819. php_oci_connection *connection;
  820. ZEND_PARSE_PARAMETERS_START(1, 1)
  821. Z_PARAM_RESOURCE(z_connection)
  822. ZEND_PARSE_PARAMETERS_END();
  823. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  824. if (connection->descriptors) {
  825. php_oci_connection_descriptors_free(connection);
  826. }
  827. if (php_oci_connection_rollback(connection)) {
  828. RETURN_FALSE;
  829. }
  830. RETURN_TRUE;
  831. }
  832. /* }}} */
  833. /* {{{ Commit the current context */
  834. PHP_FUNCTION(oci_commit)
  835. {
  836. zval *z_connection;
  837. php_oci_connection *connection;
  838. ZEND_PARSE_PARAMETERS_START(1, 1)
  839. Z_PARAM_RESOURCE(z_connection)
  840. ZEND_PARSE_PARAMETERS_END();
  841. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  842. if (connection->descriptors) {
  843. php_oci_connection_descriptors_free(connection);
  844. }
  845. if (php_oci_connection_commit(connection)) {
  846. RETURN_FALSE;
  847. }
  848. RETURN_TRUE;
  849. }
  850. /* }}} */
  851. /* {{{ Tell the name of a column */
  852. PHP_FUNCTION(oci_field_name)
  853. {
  854. php_oci_out_column *column;
  855. if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
  856. RETURN_STRINGL(column->name, column->name_len);
  857. }
  858. RETURN_FALSE;
  859. }
  860. /* }}} */
  861. /* {{{ Tell the maximum data size of a column */
  862. PHP_FUNCTION(oci_field_size)
  863. {
  864. php_oci_out_column *column;
  865. if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
  866. /* Handle data type of LONG */
  867. if (column->data_type == SQLT_LNG){
  868. RETURN_LONG(column->storage_size4);
  869. }
  870. RETURN_LONG(column->data_size);
  871. }
  872. RETURN_FALSE;
  873. }
  874. /* }}} */
  875. /* {{{ Tell the scale of a column */
  876. PHP_FUNCTION(oci_field_scale)
  877. {
  878. php_oci_out_column *column;
  879. if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
  880. RETURN_LONG(column->scale);
  881. }
  882. RETURN_FALSE;
  883. }
  884. /* }}} */
  885. /* {{{ Tell the precision of a column */
  886. PHP_FUNCTION(oci_field_precision)
  887. {
  888. php_oci_out_column *column;
  889. if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
  890. RETURN_LONG(column->precision);
  891. }
  892. RETURN_FALSE;
  893. }
  894. /* }}} */
  895. /* {{{ Tell the data type of a column */
  896. PHP_FUNCTION(oci_field_type)
  897. {
  898. php_oci_out_column *column;
  899. column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  900. if (!column) {
  901. RETURN_FALSE;
  902. }
  903. switch (column->data_type) {
  904. #ifdef SQLT_TIMESTAMP
  905. case SQLT_TIMESTAMP:
  906. RETVAL_STRING("TIMESTAMP");
  907. break;
  908. #endif
  909. #ifdef SQLT_TIMESTAMP_TZ
  910. case SQLT_TIMESTAMP_TZ:
  911. RETVAL_STRING("TIMESTAMP WITH TIMEZONE");
  912. break;
  913. #endif
  914. #ifdef SQLT_TIMESTAMP_LTZ
  915. case SQLT_TIMESTAMP_LTZ:
  916. RETVAL_STRING("TIMESTAMP WITH LOCAL TIMEZONE");
  917. break;
  918. #endif
  919. #ifdef SQLT_INTERVAL_YM
  920. case SQLT_INTERVAL_YM:
  921. RETVAL_STRING("INTERVAL YEAR TO MONTH");
  922. break;
  923. #endif
  924. #ifdef SQLT_INTERVAL_DS
  925. case SQLT_INTERVAL_DS:
  926. RETVAL_STRING("INTERVAL DAY TO SECOND");
  927. break;
  928. #endif
  929. case SQLT_DAT:
  930. RETVAL_STRING("DATE");
  931. break;
  932. case SQLT_NUM:
  933. RETVAL_STRING("NUMBER");
  934. break;
  935. case SQLT_LNG:
  936. RETVAL_STRING("LONG");
  937. break;
  938. case SQLT_BIN:
  939. RETVAL_STRING("RAW");
  940. break;
  941. case SQLT_LBI:
  942. RETVAL_STRING("LONG RAW");
  943. break;
  944. case SQLT_CHR:
  945. RETVAL_STRING("VARCHAR2");
  946. break;
  947. case SQLT_RSET:
  948. RETVAL_STRING("REFCURSOR");
  949. break;
  950. case SQLT_AFC:
  951. RETVAL_STRING("CHAR");
  952. break;
  953. case SQLT_BLOB:
  954. RETVAL_STRING("BLOB");
  955. break;
  956. case SQLT_CLOB:
  957. RETVAL_STRING("CLOB");
  958. break;
  959. case SQLT_BFILE:
  960. RETVAL_STRING("BFILE");
  961. break;
  962. case SQLT_RDD:
  963. RETVAL_STRING("ROWID");
  964. break;
  965. default:
  966. RETVAL_LONG(column->data_type);
  967. }
  968. }
  969. /* }}} */
  970. /* {{{ Tell the raw oracle data type of a column */
  971. PHP_FUNCTION(oci_field_type_raw)
  972. {
  973. php_oci_out_column *column;
  974. column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  975. if (column) {
  976. RETURN_LONG(column->data_type);
  977. }
  978. RETURN_FALSE;
  979. }
  980. /* }}} */
  981. /* {{{ Tell whether a field in the current row is NULL */
  982. PHP_FUNCTION(oci_field_is_null)
  983. {
  984. php_oci_out_column *column;
  985. if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
  986. if (column->indicator == -1) {
  987. RETURN_TRUE;
  988. }
  989. }
  990. RETURN_FALSE;
  991. }
  992. /* }}} */
  993. /* {{{ Execute a parsed statement */
  994. PHP_FUNCTION(oci_execute)
  995. {
  996. zval *z_statement;
  997. php_oci_statement *statement;
  998. zend_long mode = OCI_COMMIT_ON_SUCCESS;
  999. ZEND_PARSE_PARAMETERS_START(1, 2)
  1000. Z_PARAM_RESOURCE(z_statement)
  1001. Z_PARAM_OPTIONAL
  1002. Z_PARAM_LONG(mode)
  1003. ZEND_PARSE_PARAMETERS_END();
  1004. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1005. if (php_oci_statement_execute(statement, (ub4) mode)) {
  1006. RETURN_FALSE;
  1007. }
  1008. RETURN_TRUE;
  1009. }
  1010. /* }}} */
  1011. /* {{{ Cancel reading from a cursor */
  1012. PHP_FUNCTION(oci_cancel)
  1013. {
  1014. zval *z_statement;
  1015. php_oci_statement *statement;
  1016. if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_statement) == FAILURE) {
  1017. RETURN_THROWS();
  1018. }
  1019. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1020. if (php_oci_statement_cancel(statement)) {
  1021. RETURN_FALSE;
  1022. }
  1023. RETURN_TRUE;
  1024. }
  1025. /* }}} */
  1026. /* {{{ Prepare a new row of data for reading */
  1027. PHP_FUNCTION(oci_fetch)
  1028. {
  1029. zval *z_statement;
  1030. php_oci_statement *statement;
  1031. ub4 nrows = 1; /* only one row at a time is supported for now */
  1032. ZEND_PARSE_PARAMETERS_START(1, 1)
  1033. Z_PARAM_RESOURCE(z_statement)
  1034. ZEND_PARSE_PARAMETERS_END();
  1035. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1036. if (php_oci_statement_fetch(statement, nrows)) {
  1037. RETURN_FALSE;
  1038. }
  1039. RETURN_TRUE;
  1040. }
  1041. /* }}} */
  1042. /* {{{ Fetch a row of result data into an array */
  1043. PHP_FUNCTION(ocifetchinto)
  1044. {
  1045. php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_NUM, 3);
  1046. }
  1047. /* }}} */
  1048. /* {{{ Fetch all rows of result data into an array */
  1049. PHP_FUNCTION(oci_fetch_all)
  1050. {
  1051. zval *z_statement, *array;
  1052. zval element, tmp;
  1053. php_oci_statement *statement;
  1054. php_oci_out_column **columns;
  1055. zval **outarrs;
  1056. ub4 nrows = 1;
  1057. int i;
  1058. zend_long rows = 0, flags = PHP_OCI_FETCHSTATEMENT_BY_COLUMN | PHP_OCI_ASSOC, skip = 0, maxrows = -1;
  1059. ZEND_PARSE_PARAMETERS_START(2, 5)
  1060. Z_PARAM_RESOURCE(z_statement)
  1061. Z_PARAM_ZVAL(array)
  1062. Z_PARAM_OPTIONAL
  1063. Z_PARAM_LONG(skip)
  1064. Z_PARAM_LONG(maxrows)
  1065. Z_PARAM_LONG(flags)
  1066. ZEND_PARSE_PARAMETERS_END();
  1067. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1068. while (skip--) {
  1069. if (php_oci_statement_fetch(statement, nrows)) {
  1070. zend_try_array_init(array);
  1071. RETURN_LONG(0);
  1072. }
  1073. }
  1074. if (flags & PHP_OCI_FETCHSTATEMENT_BY_ROW) {
  1075. /* Fetch by Row: array will contain one sub-array per query row */
  1076. array = zend_try_array_init(array);
  1077. if (!array) {
  1078. RETURN_THROWS();
  1079. }
  1080. columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0);
  1081. for (i = 0; i < statement->ncolumns; i++) {
  1082. columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0);
  1083. }
  1084. while (!php_oci_statement_fetch(statement, nrows)) {
  1085. zval row;
  1086. array_init_size(&row, statement->ncolumns);
  1087. for (i = 0; i < statement->ncolumns; i++) {
  1088. php_oci_column_to_zval(columns[ i ], &element, PHP_OCI_RETURN_LOBS);
  1089. if (flags & PHP_OCI_NUM) {
  1090. zend_hash_next_index_insert(Z_ARRVAL(row), &element);
  1091. } else { /* default to ASSOC */
  1092. zend_string *zvtmp;
  1093. zvtmp = zend_string_init(columns[ i ]->name, columns[ i ]->name_len, 0);
  1094. zend_symtable_update(Z_ARRVAL(row), zvtmp, &element);
  1095. zend_string_release_ex(zvtmp, 0);
  1096. }
  1097. }
  1098. zend_hash_next_index_insert(Z_ARRVAL_P(array), &row);
  1099. rows++;
  1100. if (maxrows != -1 && rows == maxrows) {
  1101. php_oci_statement_cancel(statement);
  1102. break;
  1103. }
  1104. }
  1105. efree(columns);
  1106. } else { /* default to BY_COLUMN */
  1107. /* Fetch by columns: array will contain one sub-array per query column */
  1108. array = zend_try_array_init_size(array, statement->ncolumns);
  1109. if (!array) {
  1110. RETURN_THROWS();
  1111. }
  1112. columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0);
  1113. outarrs = safe_emalloc(statement->ncolumns, sizeof(zval*), 0);
  1114. if (flags & PHP_OCI_NUM) {
  1115. for (i = 0; i < statement->ncolumns; i++) {
  1116. columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0);
  1117. array_init(&tmp);
  1118. outarrs[ i ] = zend_hash_next_index_insert(Z_ARRVAL_P(array), &tmp);
  1119. }
  1120. } else { /* default to ASSOC */
  1121. for (i = 0; i < statement->ncolumns; i++) {
  1122. zend_string *zvtmp;
  1123. columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0);
  1124. array_init(&tmp);
  1125. zvtmp = zend_string_init(columns[ i ]->name, columns[ i ]->name_len, 0);
  1126. outarrs[ i ] = zend_symtable_update(Z_ARRVAL_P(array), zvtmp, &tmp);
  1127. zend_string_release_ex(zvtmp, 0);
  1128. }
  1129. }
  1130. while (!php_oci_statement_fetch(statement, nrows)) {
  1131. for (i = 0; i < statement->ncolumns; i++) {
  1132. php_oci_column_to_zval(columns[ i ], &element, PHP_OCI_RETURN_LOBS);
  1133. zend_hash_index_update(Z_ARRVAL_P(outarrs[ i ]), rows, &element);
  1134. }
  1135. rows++;
  1136. if (maxrows != -1 && rows == maxrows) {
  1137. php_oci_statement_cancel(statement);
  1138. break;
  1139. }
  1140. }
  1141. efree(columns);
  1142. efree(outarrs);
  1143. }
  1144. RETURN_LONG(rows);
  1145. }
  1146. /* }}} */
  1147. /* {{{ Fetch a result row as an object */
  1148. PHP_FUNCTION(oci_fetch_object)
  1149. {
  1150. php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_ASSOC | PHP_OCI_RETURN_NULLS, 2);
  1151. if (Z_TYPE_P(return_value) == IS_ARRAY) {
  1152. object_and_properties_init(return_value, ZEND_STANDARD_CLASS_DEF_PTR, Z_ARRVAL_P(return_value));
  1153. }
  1154. }
  1155. /* }}} */
  1156. /* {{{ Fetch a result row as an enumerated array */
  1157. PHP_FUNCTION(oci_fetch_row)
  1158. {
  1159. php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_NUM | PHP_OCI_RETURN_NULLS, 1);
  1160. }
  1161. /* }}} */
  1162. /* {{{ Fetch a result row as an associative array */
  1163. PHP_FUNCTION(oci_fetch_assoc)
  1164. {
  1165. php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_ASSOC | PHP_OCI_RETURN_NULLS, 1);
  1166. }
  1167. /* }}} */
  1168. /* {{{ Fetch a result row as an array */
  1169. PHP_FUNCTION(oci_fetch_array)
  1170. {
  1171. php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_BOTH | PHP_OCI_RETURN_NULLS, 2);
  1172. }
  1173. /* }}} */
  1174. /* {{{ Free all resources associated with a statement */
  1175. PHP_FUNCTION(oci_free_statement)
  1176. {
  1177. zval *z_statement;
  1178. php_oci_statement *statement;
  1179. ZEND_PARSE_PARAMETERS_START(1, 1)
  1180. Z_PARAM_RESOURCE(z_statement)
  1181. ZEND_PARSE_PARAMETERS_END();
  1182. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1183. zend_list_close(statement->id);
  1184. RETURN_TRUE;
  1185. }
  1186. /* }}} */
  1187. /* {{{ Disconnect from database */
  1188. PHP_FUNCTION(oci_close)
  1189. {
  1190. /* oci_close for pconnect (if old_oci_close_semantics not set) would
  1191. * release the connection back to the client-side session pool (and to the
  1192. * server-side pool if Database Resident Connection Pool is being used).
  1193. * Subsequent pconnects in the same script are not guaranteed to get the
  1194. * same database session.
  1195. */
  1196. zval *z_connection;
  1197. php_oci_connection *connection;
  1198. ZEND_PARSE_PARAMETERS_START(1, 1)
  1199. Z_PARAM_RESOURCE(z_connection)
  1200. ZEND_PARSE_PARAMETERS_END();
  1201. if (OCI_G(old_oci_close_semantics)) {
  1202. /* do nothing to keep BC */
  1203. RETURN_NULL();
  1204. }
  1205. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1206. if (GC_REFCOUNT(connection->id) == 2) { /* CHANGED VERSION::PHP7
  1207. Changed the refCount to 2 since
  1208. internally Zend engine increments
  1209. RefCount value by 1 */
  1210. /* Unregister Oracle TAF */
  1211. php_oci_unregister_taf_callback(connection);
  1212. zend_list_close(connection->id);
  1213. }
  1214. /* ZVAL_NULL(z_connection); */
  1215. RETURN_TRUE;
  1216. }
  1217. /* }}} */
  1218. /* {{{ Connect to an Oracle database and log on. Returns a new session. */
  1219. PHP_FUNCTION(oci_new_connect)
  1220. {
  1221. php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
  1222. }
  1223. /* }}} */
  1224. /* {{{ Connect to an Oracle database and log on. Returns a new session. */
  1225. PHP_FUNCTION(oci_connect)
  1226. {
  1227. php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
  1228. }
  1229. /* }}} */
  1230. /* {{{ Connect to an Oracle database using a persistent connection and log on. Returns a new session. */
  1231. PHP_FUNCTION(oci_pconnect)
  1232. {
  1233. php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
  1234. }
  1235. /* }}} */
  1236. /* {{{ Return the last error of stmt|connection|global. If no error happened returns false. */
  1237. PHP_FUNCTION(oci_error)
  1238. {
  1239. zval *arg = NULL;
  1240. php_oci_statement *statement;
  1241. php_oci_connection *connection;
  1242. text errbuf[PHP_OCI_ERRBUF_LEN];
  1243. sb4 errcode = 0;
  1244. dvoid *errh = NULL;
  1245. ub2 error_offset = 0;
  1246. text *sqltext = NULL;
  1247. ZEND_PARSE_PARAMETERS_START(0, 1)
  1248. Z_PARAM_OPTIONAL
  1249. Z_PARAM_RESOURCE_OR_NULL(arg)
  1250. ZEND_PARSE_PARAMETERS_END();
  1251. if (arg) {
  1252. statement = (php_oci_statement *) zend_fetch_resource_ex(arg, NULL, le_statement);
  1253. if (statement) {
  1254. errh = statement->err;
  1255. errcode = statement->errcode;
  1256. if (php_oci_fetch_sqltext_offset(statement, &sqltext, &error_offset)) {
  1257. RETURN_FALSE;
  1258. }
  1259. goto go_out;
  1260. }
  1261. connection = (php_oci_connection *) zend_fetch_resource_ex(arg, NULL, le_connection);
  1262. if (connection) {
  1263. errh = connection->err;
  1264. errcode = connection->errcode;
  1265. goto go_out;
  1266. }
  1267. connection = (php_oci_connection *) zend_fetch_resource_ex(arg, NULL, le_pconnection);
  1268. if (connection) {
  1269. errh = connection->err;
  1270. errcode = connection->errcode;
  1271. goto go_out;
  1272. }
  1273. } else {
  1274. errh = OCI_G(err);
  1275. errcode = OCI_G(errcode);
  1276. }
  1277. go_out:
  1278. if (errcode == 0) { /* no error set in the handle */
  1279. RETURN_FALSE;
  1280. }
  1281. if (!errh) {
  1282. php_error_docref(NULL, E_WARNING, "oci_error: unable to find error handle");
  1283. RETURN_FALSE;
  1284. }
  1285. errcode = php_oci_fetch_errmsg(errh, errbuf, sizeof(errbuf));
  1286. if (errcode) {
  1287. array_init(return_value);
  1288. add_assoc_long(return_value, "code", errcode);
  1289. /* TODO: avoid reallocation ??? */
  1290. add_assoc_string(return_value, "message", (char*) errbuf);
  1291. add_assoc_long(return_value, "offset", error_offset);
  1292. add_assoc_string(return_value, "sqltext", sqltext ? (char *) sqltext : "");
  1293. } else {
  1294. RETURN_FALSE;
  1295. }
  1296. }
  1297. /* }}} */
  1298. /* {{{ Return the number of result columns in a statement */
  1299. PHP_FUNCTION(oci_num_fields)
  1300. {
  1301. zval *z_statement;
  1302. php_oci_statement *statement;
  1303. ZEND_PARSE_PARAMETERS_START(1, 1)
  1304. Z_PARAM_RESOURCE(z_statement)
  1305. ZEND_PARSE_PARAMETERS_END();
  1306. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1307. RETURN_LONG(statement->ncolumns);
  1308. }
  1309. /* }}} */
  1310. /* {{{ Parse a SQL or PL/SQL statement and return a statement resource */
  1311. PHP_FUNCTION(oci_parse)
  1312. {
  1313. zval *z_connection;
  1314. php_oci_connection *connection;
  1315. php_oci_statement *statement;
  1316. char *query;
  1317. size_t query_len;
  1318. ZEND_PARSE_PARAMETERS_START(2, 2)
  1319. Z_PARAM_RESOURCE(z_connection)
  1320. Z_PARAM_STRING(query, query_len)
  1321. ZEND_PARSE_PARAMETERS_END();
  1322. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1323. statement = php_oci_statement_create(connection, query, (int) query_len);
  1324. if (statement) {
  1325. RETURN_RES(statement->id);
  1326. }
  1327. RETURN_FALSE;
  1328. }
  1329. /* }}} */
  1330. /* {{{ Sets the number of rows to be prefetched on execute to prefetch_rows for stmt */
  1331. PHP_FUNCTION(oci_set_prefetch)
  1332. {
  1333. zval *z_statement;
  1334. php_oci_statement *statement;
  1335. zend_long size;
  1336. ZEND_PARSE_PARAMETERS_START(2, 2)
  1337. Z_PARAM_RESOURCE(z_statement)
  1338. Z_PARAM_LONG(size)
  1339. ZEND_PARSE_PARAMETERS_END();
  1340. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1341. if (size < 0) {
  1342. zend_argument_value_error(2, "must be greater than or equal to 0");
  1343. RETURN_THROWS();
  1344. }
  1345. if (php_oci_statement_set_prefetch(statement, (ub4)size)) {
  1346. RETURN_FALSE;
  1347. }
  1348. RETURN_TRUE;
  1349. }
  1350. /* }}} */
  1351. /* {{{ Sets the client identifier attribute on the connection */
  1352. PHP_FUNCTION(oci_set_client_identifier)
  1353. {
  1354. zval *z_connection;
  1355. php_oci_connection *connection;
  1356. char *client_id;
  1357. size_t client_id_len;
  1358. sword errstatus;
  1359. ZEND_PARSE_PARAMETERS_START(2, 2)
  1360. Z_PARAM_RESOURCE(z_connection)
  1361. Z_PARAM_STRING(client_id, client_id_len)
  1362. ZEND_PARSE_PARAMETERS_END();
  1363. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1364. PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) client_id, (ub4) client_id_len, (ub4) OCI_ATTR_CLIENT_IDENTIFIER, connection->err));
  1365. if (errstatus != OCI_SUCCESS) {
  1366. connection->errcode = php_oci_error(connection->err, errstatus);
  1367. RETURN_FALSE;
  1368. }
  1369. #ifdef HAVE_OCI8_DTRACE
  1370. /* The alternatives to storing client_id like done below are
  1371. i) display it in a probe here in oci_set_client_identifier and
  1372. let the user D script correlate the connection address probe
  1373. argument and the client_id. This would likely require user D
  1374. script variables, which would use kernel memory.
  1375. ii) call OCIAttrGet for each probe definition that uses
  1376. client_id. This would be slower than storing it.
  1377. */
  1378. if (connection->client_id) {
  1379. pefree(connection->client_id, connection->is_persistent);
  1380. }
  1381. if (client_id) {
  1382. /* this long winded copy allows compatibility with older PHP versions */
  1383. connection->client_id = (char *)pemalloc(client_id_len+1, connection->is_persistent);
  1384. memcpy(connection->client_id, client_id, client_id_len);
  1385. connection->client_id[client_id_len] = '\0';
  1386. } else {
  1387. connection->client_id = NULL;
  1388. }
  1389. #endif /* HAVE_OCI8_DTRACE */
  1390. RETURN_TRUE;
  1391. }
  1392. /* }}} */
  1393. /* {{{ Sets the edition attribute for all subsequent connections created */
  1394. PHP_FUNCTION(oci_set_edition)
  1395. {
  1396. char *edition;
  1397. size_t edition_len;
  1398. ZEND_PARSE_PARAMETERS_START(1, 1)
  1399. Z_PARAM_STRING(edition, edition_len)
  1400. ZEND_PARSE_PARAMETERS_END();
  1401. #if ((OCI_MAJOR_VERSION > 11) || ((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION >= 2)))
  1402. if (OCI_G(edition)) {
  1403. efree(OCI_G(edition));
  1404. }
  1405. if (edition) {
  1406. OCI_G(edition) = (char *)safe_emalloc(edition_len+1, sizeof(char), 0);
  1407. memcpy(OCI_G(edition), edition, edition_len);
  1408. OCI_G(edition)[edition_len] = '\0';
  1409. } else {
  1410. OCI_G(edition) = NULL;
  1411. }
  1412. RETURN_TRUE;
  1413. #else
  1414. php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
  1415. RETURN_FALSE;
  1416. #endif
  1417. }
  1418. /* }}} */
  1419. /* {{{ Sets the module attribute on the connection for end-to-end tracing */
  1420. PHP_FUNCTION(oci_set_module_name)
  1421. {
  1422. zval *z_connection;
  1423. char *module;
  1424. size_t module_len;
  1425. ZEND_PARSE_PARAMETERS_START(2, 2)
  1426. Z_PARAM_RESOURCE(z_connection)
  1427. Z_PARAM_STRING(module, module_len)
  1428. ZEND_PARSE_PARAMETERS_END();
  1429. #if (OCI_MAJOR_VERSION >= 10)
  1430. php_oci_connection *connection;
  1431. sword errstatus;
  1432. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1433. PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) module, (ub4) module_len, (ub4) OCI_ATTR_MODULE, connection->err));
  1434. if (errstatus != OCI_SUCCESS) {
  1435. connection->errcode = php_oci_error(connection->err, errstatus);
  1436. RETURN_FALSE;
  1437. }
  1438. RETURN_TRUE;
  1439. #else
  1440. php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
  1441. RETURN_FALSE;
  1442. #endif
  1443. }
  1444. /* }}} */
  1445. /* {{{ Sets the action attribute on the connection for end-to-end tracing */
  1446. PHP_FUNCTION(oci_set_action)
  1447. {
  1448. zval *z_connection;
  1449. char *action;
  1450. size_t action_len;
  1451. ZEND_PARSE_PARAMETERS_START(2, 2)
  1452. Z_PARAM_RESOURCE(z_connection)
  1453. Z_PARAM_STRING(action, action_len)
  1454. ZEND_PARSE_PARAMETERS_END();
  1455. #if (OCI_MAJOR_VERSION >= 10)
  1456. php_oci_connection *connection;
  1457. sword errstatus;
  1458. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1459. PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) action, (ub4) action_len, (ub4) OCI_ATTR_ACTION, connection->err));
  1460. if (errstatus != OCI_SUCCESS) {
  1461. connection->errcode = php_oci_error(connection->err, errstatus);
  1462. RETURN_FALSE;
  1463. }
  1464. RETURN_TRUE;
  1465. #else
  1466. php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
  1467. RETURN_FALSE;
  1468. #endif
  1469. }
  1470. /* }}} */
  1471. /* {{{ Sets the client info attribute on the connection for end-to-end tracing */
  1472. PHP_FUNCTION(oci_set_client_info)
  1473. {
  1474. zval *z_connection;
  1475. char *client_info;
  1476. size_t client_info_len;
  1477. ZEND_PARSE_PARAMETERS_START(2, 2)
  1478. Z_PARAM_RESOURCE(z_connection)
  1479. Z_PARAM_STRING(client_info, client_info_len)
  1480. ZEND_PARSE_PARAMETERS_END();
  1481. #if (OCI_MAJOR_VERSION >= 10)
  1482. php_oci_connection *connection;
  1483. sword errstatus;
  1484. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1485. PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) client_info, (ub4) client_info_len, (ub4) OCI_ATTR_CLIENT_INFO, connection->err));
  1486. if (errstatus != OCI_SUCCESS) {
  1487. connection->errcode = php_oci_error(connection->err, errstatus);
  1488. RETURN_FALSE;
  1489. }
  1490. RETURN_TRUE;
  1491. #else
  1492. php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
  1493. RETURN_FALSE;
  1494. #endif
  1495. }
  1496. /* }}} */
  1497. /* {{{ Sets the "DB operation" on the connection for Oracle end-to-end tracing.
  1498. For history, see Oracle bug 16695981 */
  1499. PHP_FUNCTION(oci_set_db_operation)
  1500. {
  1501. zval *z_connection;
  1502. char *dbop_name;
  1503. size_t dbop_name_len;
  1504. ZEND_PARSE_PARAMETERS_START(2, 2)
  1505. Z_PARAM_RESOURCE(z_connection)
  1506. Z_PARAM_STRING(dbop_name, dbop_name_len)
  1507. ZEND_PARSE_PARAMETERS_END();
  1508. #if (OCI_MAJOR_VERSION > 11)
  1509. php_oci_connection *connection;
  1510. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1511. PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) dbop_name, (ub4) dbop_name_len, (ub4) OCI_ATTR_DBOP, OCI_G(err)));
  1512. if (OCI_G(errcode) != OCI_SUCCESS) {
  1513. php_oci_error(OCI_G(err), OCI_G(errcode));
  1514. RETURN_FALSE;
  1515. }
  1516. RETURN_TRUE;
  1517. #else
  1518. php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
  1519. RETURN_FALSE;
  1520. #endif
  1521. }
  1522. /* }}} */
  1523. /* {{{ */
  1524. PHP_FUNCTION(oci_set_call_timeout)
  1525. {
  1526. zval *z_connection;
  1527. zend_long call_timeout; // milliseconds
  1528. ZEND_PARSE_PARAMETERS_START(2, 2)
  1529. Z_PARAM_RESOURCE(z_connection)
  1530. Z_PARAM_LONG(call_timeout)
  1531. ZEND_PARSE_PARAMETERS_END();
  1532. #if (OCI_MAJOR_VERSION >= 18)
  1533. php_oci_connection *connection;
  1534. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1535. PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->svc, (ub4) OCI_HTYPE_SVCCTX, (ub4 *) &call_timeout, 0, OCI_ATTR_CALL_TIMEOUT, OCI_G(err)));
  1536. if (OCI_G(errcode) != OCI_SUCCESS) {
  1537. php_oci_error(OCI_G(err), OCI_G(errcode));
  1538. RETURN_FALSE;
  1539. }
  1540. RETURN_TRUE;
  1541. #else
  1542. php_error_docref(NULL, E_NOTICE, "Unsupported with this version of Oracle Client");
  1543. RETURN_FALSE;
  1544. #endif
  1545. }
  1546. /* }}} */
  1547. /* {{{ Changes the password of an account */
  1548. PHP_FUNCTION(oci_password_change)
  1549. {
  1550. zval *z_connection;
  1551. char *user, *pass_old, *pass_new, *dbname;
  1552. size_t user_len, pass_old_len, pass_new_len, dbname_len;
  1553. php_oci_connection *connection;
  1554. if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "rsss", &z_connection, &user, &user_len, &pass_old, &pass_old_len, &pass_new, &pass_new_len) == SUCCESS) {
  1555. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1556. if (!user_len) {
  1557. zend_argument_value_error(2, "cannot be empty");
  1558. RETURN_THROWS();
  1559. }
  1560. if (!pass_old_len) {
  1561. zend_argument_value_error(3, "cannot be empty");
  1562. RETURN_THROWS();
  1563. }
  1564. if (!pass_new_len) {
  1565. zend_argument_value_error(4, "cannot be empty");
  1566. RETURN_THROWS();
  1567. }
  1568. if (php_oci_password_change(connection, user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len)) {
  1569. RETURN_FALSE;
  1570. }
  1571. RETURN_TRUE;
  1572. } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "ssss", &dbname, &dbname_len, &user, &user_len, &pass_old, &pass_old_len, &pass_new, &pass_new_len) == SUCCESS) {
  1573. if (!user_len) {
  1574. zend_argument_value_error(2, "cannot be empty");
  1575. RETURN_THROWS();
  1576. }
  1577. if (!pass_old_len) {
  1578. zend_argument_value_error(3, "cannot be empty");
  1579. RETURN_THROWS();
  1580. }
  1581. if (!pass_new_len) {
  1582. zend_argument_value_error(4, "cannot be empty");
  1583. RETURN_THROWS();
  1584. }
  1585. connection = php_oci_do_connect_ex(user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len, dbname, (int) dbname_len, NULL, OCI_DEFAULT, 0, 0);
  1586. if (!connection) {
  1587. RETURN_FALSE;
  1588. }
  1589. RETURN_RES(connection->id);
  1590. }
  1591. WRONG_PARAM_COUNT;
  1592. }
  1593. /* }}} */
  1594. /* {{{ Return a new cursor (Statement-Handle) - use this to bind ref-cursors! */
  1595. PHP_FUNCTION(oci_new_cursor)
  1596. {
  1597. zval *z_connection;
  1598. php_oci_connection *connection;
  1599. php_oci_statement *statement;
  1600. ZEND_PARSE_PARAMETERS_START(1, 1)
  1601. Z_PARAM_RESOURCE(z_connection)
  1602. ZEND_PARSE_PARAMETERS_END();
  1603. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1604. statement = php_oci_statement_create(connection, NULL, 0);
  1605. if (statement) {
  1606. RETURN_RES(statement->id);
  1607. }
  1608. RETURN_FALSE;
  1609. }
  1610. /* }}} */
  1611. /* {{{ Return a single column of result data */
  1612. PHP_FUNCTION(oci_result)
  1613. {
  1614. php_oci_out_column *column;
  1615. column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  1616. if(column) {
  1617. php_oci_column_to_zval(column, return_value, 0);
  1618. }
  1619. else {
  1620. RETURN_FALSE;
  1621. }
  1622. }
  1623. /* }}} */
  1624. /* {{{ Return a string containing runtime client library version information */
  1625. PHP_FUNCTION(oci_client_version)
  1626. {
  1627. char version[256];
  1628. ZEND_PARSE_PARAMETERS_NONE();
  1629. php_oci_client_get_version(version, sizeof(version));
  1630. RETURN_STRING(version);
  1631. }
  1632. /* }}} */
  1633. /* {{{ Return a string containing server version information */
  1634. PHP_FUNCTION(oci_server_version)
  1635. {
  1636. zval *z_connection;
  1637. php_oci_connection *connection;
  1638. char version[256];
  1639. zend_string *ret;
  1640. ZEND_PARSE_PARAMETERS_START(1, 1)
  1641. Z_PARAM_RESOURCE(z_connection)
  1642. ZEND_PARSE_PARAMETERS_END();
  1643. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1644. if (php_oci_server_get_version(connection, version, sizeof(version))) {
  1645. RETURN_FALSE;
  1646. }
  1647. ret = zend_string_init(version, strlen(version), 0);
  1648. RETURN_STR(ret);
  1649. }
  1650. /* }}} */
  1651. /* {{{ Return the query type of an OCI statement */
  1652. PHP_FUNCTION(oci_statement_type)
  1653. {
  1654. zval *z_statement;
  1655. php_oci_statement *statement;
  1656. ub2 type;
  1657. ZEND_PARSE_PARAMETERS_START(1, 1)
  1658. Z_PARAM_RESOURCE(z_statement)
  1659. ZEND_PARSE_PARAMETERS_END();
  1660. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1661. if (php_oci_statement_get_type(statement, &type)) {
  1662. RETURN_FALSE;
  1663. }
  1664. switch (type) {
  1665. case OCI_STMT_SELECT:
  1666. RETVAL_STRING("SELECT");
  1667. break;
  1668. case OCI_STMT_UPDATE:
  1669. RETVAL_STRING("UPDATE");
  1670. break;
  1671. case OCI_STMT_DELETE:
  1672. RETVAL_STRING("DELETE");
  1673. break;
  1674. case OCI_STMT_INSERT:
  1675. RETVAL_STRING("INSERT");
  1676. break;
  1677. case OCI_STMT_CREATE:
  1678. RETVAL_STRING("CREATE");
  1679. break;
  1680. case OCI_STMT_DROP:
  1681. RETVAL_STRING("DROP");
  1682. break;
  1683. case OCI_STMT_ALTER:
  1684. RETVAL_STRING("ALTER");
  1685. break;
  1686. case OCI_STMT_BEGIN:
  1687. RETVAL_STRING("BEGIN");
  1688. break;
  1689. case OCI_STMT_DECLARE:
  1690. RETVAL_STRING("DECLARE");
  1691. break;
  1692. case OCI_STMT_CALL:
  1693. RETVAL_STRING("CALL");
  1694. break;
  1695. default:
  1696. RETVAL_STRING("UNKNOWN");
  1697. }
  1698. }
  1699. /* }}} */
  1700. /* {{{ Return the row count of an OCI statement */
  1701. PHP_FUNCTION(oci_num_rows)
  1702. {
  1703. zval *z_statement;
  1704. php_oci_statement *statement;
  1705. ub4 rowcount;
  1706. ZEND_PARSE_PARAMETERS_START(1, 1)
  1707. Z_PARAM_RESOURCE(z_statement)
  1708. ZEND_PARSE_PARAMETERS_END();
  1709. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1710. if (php_oci_statement_get_numrows(statement, &rowcount)) {
  1711. RETURN_FALSE;
  1712. }
  1713. RETURN_LONG(rowcount);
  1714. }
  1715. /* }}} */
  1716. /* {{{ Deletes collection object*/
  1717. PHP_FUNCTION(oci_free_collection)
  1718. {
  1719. zval *tmp, *z_collection;
  1720. php_oci_collection *collection;
  1721. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
  1722. RETURN_THROWS();
  1723. }
  1724. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
  1725. php_error_docref(NULL, E_WARNING, "Unable to find collection property");
  1726. RETURN_FALSE;
  1727. }
  1728. PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
  1729. zend_list_close(collection->id);
  1730. RETURN_TRUE;
  1731. }
  1732. /* }}} */
  1733. /* {{{ Append an object to the collection */
  1734. PHP_FUNCTION(oci_collection_append)
  1735. {
  1736. zval *tmp, *z_collection;
  1737. php_oci_collection *collection;
  1738. char *value;
  1739. size_t value_len;
  1740. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &z_collection, oci_coll_class_entry_ptr, &value, &value_len) == FAILURE) {
  1741. RETURN_THROWS();
  1742. }
  1743. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
  1744. php_error_docref(NULL, E_WARNING, "Unable to find collection property");
  1745. RETURN_FALSE;
  1746. }
  1747. PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
  1748. if (php_oci_collection_append(collection, value, (int) value_len)) {
  1749. RETURN_FALSE;
  1750. }
  1751. RETURN_TRUE;
  1752. }
  1753. /* }}} */
  1754. /* {{{ Retrieve the value at collection index ndx */
  1755. PHP_FUNCTION(oci_collection_element_get)
  1756. {
  1757. zval *tmp, *z_collection;
  1758. php_oci_collection *collection;
  1759. zend_long element_index;
  1760. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &z_collection, oci_coll_class_entry_ptr, &element_index) == FAILURE) {
  1761. RETURN_THROWS();
  1762. }
  1763. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
  1764. php_error_docref(NULL, E_WARNING, "Unable to find collection property");
  1765. RETURN_FALSE;
  1766. }
  1767. PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
  1768. if (php_oci_collection_element_get(collection, element_index, return_value)) {
  1769. RETURN_FALSE;
  1770. }
  1771. }
  1772. /* }}} */
  1773. /* {{{ Assign a collection from another existing collection */
  1774. PHP_FUNCTION(oci_collection_assign)
  1775. {
  1776. zval *tmp_dest, *tmp_from, *z_collection_dest, *z_collection_from;
  1777. php_oci_collection *collection_dest, *collection_from;
  1778. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO", &z_collection_dest, oci_coll_class_entry_ptr, &z_collection_from, oci_coll_class_entry_ptr) == FAILURE) {
  1779. RETURN_THROWS();
  1780. }
  1781. if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_collection_dest), "collection", sizeof("collection")-1)) == NULL) {
  1782. php_error_docref(NULL, E_WARNING, "Unable to find collection property. The first argument should be valid collection object");
  1783. RETURN_FALSE;
  1784. }
  1785. if ((tmp_from = zend_hash_str_find(Z_OBJPROP_P(z_collection_from), "collection", sizeof("collection")-1)) == NULL) {
  1786. php_error_docref(NULL, E_WARNING, "Unable to find collection property. The second argument should be valid collection object");
  1787. RETURN_FALSE;
  1788. }
  1789. PHP_OCI_ZVAL_TO_COLLECTION(tmp_dest, collection_dest);
  1790. PHP_OCI_ZVAL_TO_COLLECTION(tmp_from, collection_from);
  1791. if (php_oci_collection_assign(collection_dest, collection_from)) {
  1792. RETURN_FALSE;
  1793. }
  1794. RETURN_TRUE;
  1795. }
  1796. /* }}} */
  1797. /* {{{ Assign element val to collection at index ndx */
  1798. PHP_FUNCTION(oci_collection_element_assign)
  1799. {
  1800. zval *tmp, *z_collection;
  1801. php_oci_collection *collection;
  1802. size_t value_len;
  1803. zend_long element_index;
  1804. char *value;
  1805. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ols", &z_collection, oci_coll_class_entry_ptr, &element_index, &value, &value_len) == FAILURE) {
  1806. RETURN_THROWS();
  1807. }
  1808. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
  1809. php_error_docref(NULL, E_WARNING, "Unable to find collection property");
  1810. RETURN_FALSE;
  1811. }
  1812. PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
  1813. if (php_oci_collection_element_set(collection, element_index, value, (int) value_len)) {
  1814. RETURN_FALSE;
  1815. }
  1816. RETURN_TRUE;
  1817. }
  1818. /* }}} */
  1819. /* {{{ Return the size of a collection */
  1820. PHP_FUNCTION(oci_collection_size)
  1821. {
  1822. zval *tmp, *z_collection;
  1823. php_oci_collection *collection;
  1824. sb4 size = 0;
  1825. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
  1826. RETURN_THROWS();
  1827. }
  1828. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
  1829. php_error_docref(NULL, E_WARNING, "Unable to find collection property");
  1830. RETURN_FALSE;
  1831. }
  1832. PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
  1833. if (php_oci_collection_size(collection, &size)) {
  1834. RETURN_FALSE;
  1835. }
  1836. RETURN_LONG(size);
  1837. }
  1838. /* }}} */
  1839. /* {{{ Return the max value of a collection. For a varray this is the maximum length of the array */
  1840. PHP_FUNCTION(oci_collection_max)
  1841. {
  1842. zval *tmp, *z_collection;
  1843. php_oci_collection *collection;
  1844. zend_long max;
  1845. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
  1846. RETURN_THROWS();
  1847. }
  1848. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
  1849. php_error_docref(NULL, E_WARNING, "Unable to find collection property");
  1850. RETURN_FALSE;
  1851. }
  1852. PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
  1853. if (php_oci_collection_max(collection, &max)) {
  1854. RETURN_FALSE;
  1855. }
  1856. RETURN_LONG(max);
  1857. }
  1858. /* }}} */
  1859. /* {{{ Trim num elements from the end of a collection */
  1860. PHP_FUNCTION(oci_collection_trim)
  1861. {
  1862. zval *tmp, *z_collection;
  1863. php_oci_collection *collection;
  1864. zend_long trim_size;
  1865. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &z_collection, oci_coll_class_entry_ptr, &trim_size) == FAILURE) {
  1866. RETURN_THROWS();
  1867. }
  1868. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
  1869. php_error_docref(NULL, E_WARNING, "Unable to find collection property");
  1870. RETURN_FALSE;
  1871. }
  1872. PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
  1873. if (php_oci_collection_trim(collection, trim_size)) {
  1874. RETURN_FALSE;
  1875. }
  1876. RETURN_TRUE;
  1877. }
  1878. /* }}} */
  1879. /* {{{ Initialize a new collection */
  1880. PHP_FUNCTION(oci_new_collection)
  1881. {
  1882. zval *z_connection;
  1883. php_oci_connection *connection;
  1884. php_oci_collection *collection;
  1885. char *tdo, *schema = NULL;
  1886. size_t tdo_len, schema_len = 0;
  1887. if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s!", &z_connection, &tdo, &tdo_len, &schema, &schema_len) == FAILURE) {
  1888. RETURN_THROWS();
  1889. }
  1890. PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
  1891. if ( (collection = php_oci_collection_create(connection, tdo, (int) tdo_len, schema, (int) schema_len)) ) {
  1892. object_init_ex(return_value, oci_coll_class_entry_ptr);
  1893. add_property_resource(return_value, "collection", collection->id);
  1894. }
  1895. else {
  1896. RETURN_FALSE;
  1897. }
  1898. }
  1899. /* }}} */
  1900. /* {{{ Get the next statement resource from an Oracle 12c PL/SQL Implicit Result Set */
  1901. PHP_FUNCTION(oci_get_implicit_resultset)
  1902. {
  1903. zval *z_statement;
  1904. php_oci_statement *statement;
  1905. php_oci_statement *imp_statement;
  1906. ZEND_PARSE_PARAMETERS_START(1, 1)
  1907. Z_PARAM_RESOURCE(z_statement)
  1908. ZEND_PARSE_PARAMETERS_END();
  1909. PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
  1910. imp_statement = php_oci_get_implicit_resultset(statement);
  1911. if (imp_statement) {
  1912. if (php_oci_statement_execute(imp_statement, (ub4)OCI_DEFAULT))
  1913. RETURN_FALSE;
  1914. RETURN_RES(imp_statement->id);
  1915. }
  1916. RETURN_FALSE;
  1917. }
  1918. /* }}} */
  1919. #endif /* HAVE_OCI8 */