oci8_interface.c 68 KB

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