1<?php
2
3namespace Safe;
4
5use Safe\Exceptions\CubridException;
6
7/**
8 * This function frees the memory occupied by the result data. It returns
9 * TRUE on success. Note that it can only frees the
10 * client fetch buffer now, and if you want free all memory, use function
11 * cubrid_close_request.
12 *
13 * @param resource $req_identifier This is the request identifier.
14 * @throws CubridException
15 *
16 */
17function cubrid_free_result($req_identifier): void
18{
19    error_clear_last();
20    $result = \cubrid_free_result($req_identifier);
21    if ($result === false) {
22        throw CubridException::createFromPhpError();
23    }
24}
25
26
27/**
28 * This function returns the current CUBRID connection charset and is similar
29 * to the CUBRID MySQL compatible function
30 * cubrid_client_encoding.
31 *
32 * @param resource $conn_identifier The CUBRID connection.
33 * @return string A string that represents the CUBRID connection charset; on success.
34 *
35 * FALSE on failure.
36 * @throws CubridException
37 *
38 */
39function cubrid_get_charset($conn_identifier): string
40{
41    error_clear_last();
42    $result = \cubrid_get_charset($conn_identifier);
43    if ($result === false) {
44        throw CubridException::createFromPhpError();
45    }
46    return $result;
47}
48
49
50/**
51 * This function returns a string that represents the client library version.
52 *
53 * @return string A string that represents the client library version; on success.
54 *
55 * FALSE on failure.
56 * @throws CubridException
57 *
58 */
59function cubrid_get_client_info(): string
60{
61    error_clear_last();
62    $result = \cubrid_get_client_info();
63    if ($result === false) {
64        throw CubridException::createFromPhpError();
65    }
66    return $result;
67}
68
69
70/**
71 * This function returns the CUBRID database parameters or it returns FALSE on
72 * failure. It returns an associative array with the values for the following
73 * parameters:
74 *
75 *
76 * PARAM_ISOLATION_LEVEL
77 * PARAM_LOCK_TIMEOUT
78 * PARAM_MAX_STRING_LENGTH
79 * PARAM_AUTO_COMMIT
80 *
81 *
82 *
83 * Database parameters
84 *
85 *
86 *
87 * Parameter
88 * Description
89 *
90 *
91 *
92 *
93 * PARAM_ISOLATION_LEVEL
94 * The transaction isolation level.
95 *
96 *
97 * LOCK_TIMEOUT
98 * CUBRID provides the lock timeout feature, which sets the waiting
99 * time (in seconds) for the lock until the transaction lock setting is
100 * allowed. The default value of the lock_timeout_in_secs parameter is
101 * -1, which means the application client will wait indefinitely until
102 * the transaction lock is allowed.
103 *
104 *
105 *
106 * PARAM_AUTO_COMMIT
107 * In CUBRID PHP, auto-commit mode is disabled by default for
108 * transaction management. It can be set by using
109 * cubrid_set_autocommit.
110 *
111 *
112 *
113 *
114 *
115 *
116 * The following table shows the isolation levels from 1 to 6. It consists of
117 * table schema (row) and isolation level:
118 *
119 * Levels of Isolation Supported by CUBRID
120 *
121 *
122 *
123 * Name
124 * Description
125 *
126 *
127 *
128 *
129 * SERIALIZABLE (6)
130 * In this isolation level, problems concerning concurrency (e.g.
131 * dirty read, non-repeatable read, phantom read, etc.) do not
132 * occur.
133 *
134 *
135 * REPEATABLE READ CLASS with REPEATABLE READ INSTANCES (5)
136 * Another transaction T2 cannot update the schema of table A while
137 * transaction T1 is viewing table A.
138 * Transaction T1 may experience phantom read for the record R that was
139 * inserted by another transaction T2 when it is repeatedly retrieving a
140 * specific record.
141 *
142 *
143 * REPEATABLE READ CLASS with READ COMMITTED INSTANCES (or CURSOR STABILITY) (4)
144 * Another transaction T2 cannot update the schema of table A while
145 * transaction T1 is viewing table A.
146 * Transaction T1 may experience R read (non-repeatable read) that was
147 * updated and committed by another transaction T2 when it is repeatedly
148 * retrieving the record R.
149 *
150 *
151 * REPEATABLE READ CLASS with READ UNCOMMITTED INSTANCES (3)
152 * Default isolation level.  Another transaction T2 cannot update
153 * the schema of table A  while transaction T1 is viewing table A.
154 * Transaction T1 may experience R' read (dirty read) for the record that
155 * was updated but not committed by another transaction T2.
156 *
157 *
158 * READ COMMITTED CLASS with READ COMMITTED INSTANCES (2)
159 * Transaction T1 may experience A' read (non-repeatable read) for
160 * the table that was updated and committed by another transaction  T2
161 * while it is viewing table A repeatedly.  Transaction T1 may experience
162 * R' read (non-repeatable read) for the record that was updated and
163 * committed by another transaction T2 while it is retrieving the record
164 * R repeatedly.
165 *
166 *
167 * READ COMMITTED CLASS with READ UNCOMMITTED INSTANCES (1)
168 * Transaction T1 may experience A' read (non-repeatable read) for
169 * the table that was updated and committed by another transaction T2
170 * while it is repeatedly viewing table A.  Transaction T1 may experience
171 * R' read (dirty read) for the record that was updated but not committed
172 * by another transaction T2.
173 *
174 *
175 *
176 *
177 *
178 * @param resource $conn_identifier The CUBRID connection. If the connection identifier is not specified,
179 * the last link opened by cubrid_connect is assumed.
180 * @return array An associative array with CUBRID database parameters; on success.
181 *
182 * FALSE on failure.
183 * @throws CubridException
184 *
185 */
186function cubrid_get_db_parameter($conn_identifier): array
187{
188    error_clear_last();
189    $result = \cubrid_get_db_parameter($conn_identifier);
190    if ($result === false) {
191        throw CubridException::createFromPhpError();
192    }
193    return $result;
194}
195
196
197/**
198 * This function returns a string that represents the CUBRID server version.
199 *
200 * @param resource $conn_identifier The CUBRID connection.
201 * @return string A string that represents the CUBRID server version; on success.
202 *
203 * FALSE on failure.
204 * @throws CubridException
205 *
206 */
207function cubrid_get_server_info($conn_identifier): string
208{
209    error_clear_last();
210    $result = \cubrid_get_server_info($conn_identifier);
211    if ($result === false) {
212        throw CubridException::createFromPhpError();
213    }
214    return $result;
215}
216
217
218/**
219 * The cubrid_insert_id function retrieves the ID
220 * generated for the AUTO_INCREMENT column which is updated by the previous
221 * INSERT query. It returns 0 if the previous query does not generate new
222 * rows.
223 *
224 * @param resource $conn_identifier The connection identifier previously obtained by a call to
225 * cubrid_connect.
226 * @return string A string representing the ID generated for an AUTO_INCREMENT column by the
227 * previous query, on success.
228 *
229 * 0, if the previous query does not generate new rows.
230 *
231 * FALSE on failure.
232 * @throws CubridException
233 *
234 */
235function cubrid_insert_id($conn_identifier = null): string
236{
237    error_clear_last();
238    if ($conn_identifier !== null) {
239        $result = \cubrid_insert_id($conn_identifier);
240    } else {
241        $result = \cubrid_insert_id();
242    }
243    if ($result === false) {
244        throw CubridException::createFromPhpError();
245    }
246    return $result;
247}
248
249
250/**
251 * The cubrid_lob2_new function is used to create a lob object (both BLOB and CLOB).
252 * This function should be used before you bind a lob object.
253 *
254 * @param resource $conn_identifier Connection identifier. If the connection identifier is not specified,
255 * the last connection opened by cubrid_connect or
256 * cubrid_connect_with_url is assumed.
257 * @param string $type It may be "BLOB" or "CLOB", it won't be case-sensitive. The default value is "BLOB".
258 * @return resource Lob identifier when it is successful.
259 *
260 * FALSE  on failure.
261 * @throws CubridException
262 *
263 */
264function cubrid_lob2_new($conn_identifier = null, string $type = "BLOB")
265{
266    error_clear_last();
267    if ($type !== "BLOB") {
268        $result = \cubrid_lob2_new($conn_identifier, $type);
269    } elseif ($conn_identifier !== null) {
270        $result = \cubrid_lob2_new($conn_identifier);
271    } else {
272        $result = \cubrid_lob2_new();
273    }
274    if ($result === false) {
275        throw CubridException::createFromPhpError();
276    }
277    return $result;
278}
279
280
281/**
282 * The cubrid_lob2_size function is used to get the size of a lob object.
283 *
284 * @param resource $lob_identifier Lob identifier as a result of cubrid_lob2_new or get from the result set.
285 * @return int It will return the size of the LOB object when it processes successfully.
286 *
287 * FALSE on failure.
288 * @throws CubridException
289 *
290 */
291function cubrid_lob2_size($lob_identifier): int
292{
293    error_clear_last();
294    $result = \cubrid_lob2_size($lob_identifier);
295    if ($result === false) {
296        throw CubridException::createFromPhpError();
297    }
298    return $result;
299}
300
301
302/**
303 * The cubrid_lob2_size64 function is used to get the
304 * size of a lob object.  If the size of a lob object is larger than an
305 * integer data can be stored, you can use this function and it will return
306 * the size as a string.
307 *
308 * @param resource $lob_identifier Lob identifier as a result of cubrid_lob2_new or get from the result set.
309 * @return string It will return the size of the LOB object as a string when it processes successfully.
310 *
311 * FALSE on failure.
312 * @throws CubridException
313 *
314 */
315function cubrid_lob2_size64($lob_identifier): string
316{
317    error_clear_last();
318    $result = \cubrid_lob2_size64($lob_identifier);
319    if ($result === false) {
320        throw CubridException::createFromPhpError();
321    }
322    return $result;
323}
324
325
326/**
327 * The cubrid_lob2_tell function is used to tell the cursor position of the LOB object.
328 *
329 * @param resource $lob_identifier Lob identifier as a result of cubrid_lob2_new or get from the result set.
330 * @return int It will return the cursor position on the LOB object when it processes successfully.
331 *
332 * FALSE on failure.
333 * @throws CubridException
334 *
335 */
336function cubrid_lob2_tell($lob_identifier): int
337{
338    error_clear_last();
339    $result = \cubrid_lob2_tell($lob_identifier);
340    if ($result === false) {
341        throw CubridException::createFromPhpError();
342    }
343    return $result;
344}
345
346
347/**
348 * The cubrid_lob2_tell64 function is used to tell the
349 * cursor position of the LOB object. If the size of a lob object is larger
350 * than an integer data can be stored, you can use this function and it will
351 * return the position information as a string.
352 *
353 * @param resource $lob_identifier Lob identifier as a result of cubrid_lob2_new or get from the result set.
354 * @return string It will return the cursor position on the LOB object as a string when it processes successfully.
355 *
356 * FALSE on failure.
357 * @throws CubridException
358 *
359 */
360function cubrid_lob2_tell64($lob_identifier): string
361{
362    error_clear_last();
363    $result = \cubrid_lob2_tell64($lob_identifier);
364    if ($result === false) {
365        throw CubridException::createFromPhpError();
366    }
367    return $result;
368}
369
370
371/**
372 * The cubrid_set_db_parameter function is used to set
373 * the CUBRID database parameters. It can set the following CUBRID database
374 * parameters:
375 *
376 *
377 * PARAM_ISOLATION_LEVEL
378 * PARAM_LOCK_TIMEOUT
379 *
380 *
381 * @param resource $conn_identifier The CUBRID connection. If the connection identifier is not specified,
382 * the last link opened by cubrid_connect is assumed.
383 * @param int $param_type Database parameter type.
384 * @param int $param_value Isolation level value (1-6) or lock timeout (in seconds) value.
385 * @throws CubridException
386 *
387 */
388function cubrid_set_db_parameter($conn_identifier, int $param_type, int $param_value): void
389{
390    error_clear_last();
391    $result = \cubrid_set_db_parameter($conn_identifier, $param_type, $param_value);
392    if ($result === false) {
393        throw CubridException::createFromPhpError();
394    }
395}
396