1 | /* Copyright (C) 2012-2017 Kentoku Shiba |
2 | |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
15 | |
16 | #define MYSQL_SERVER 1 |
17 | #include <my_global.h> |
18 | #include "mysql_version.h" |
19 | #include "spd_environ.h" |
20 | #if MYSQL_VERSION_ID < 50500 |
21 | #include "mysql_priv.h" |
22 | #include <mysql/plugin.h> |
23 | #else |
24 | #include "sql_priv.h" |
25 | #include "probes_mysql.h" |
26 | #include "sql_partition.h" |
27 | #include "sql_analyse.h" |
28 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
29 | #include "sql_select.h" |
30 | #endif |
31 | #endif |
32 | |
33 | #ifdef HAVE_ORACLE_OCI |
34 | #if (defined(WIN32) || defined(_WIN32) || defined(WINDOWS) || defined(_WINDOWS)) |
35 | #include <Shlwapi.h> |
36 | #define strcasestr StrStr |
37 | #endif |
38 | #include <oci.h> |
39 | #include "spd_err.h" |
40 | #include "spd_param.h" |
41 | #include "spd_db_include.h" |
42 | #include "spd_include.h" |
43 | #include "spd_db_oracle.h" |
44 | #include "ha_spider.h" |
45 | #include "spd_conn.h" |
46 | #include "spd_db_conn.h" |
47 | #include "spd_malloc.h" |
48 | #include "spd_sys_table.h" |
49 | #include "spd_table.h" |
50 | |
51 | extern struct charset_info_st *spd_charset_utf8_bin; |
52 | |
53 | extern handlerton *spider_hton_ptr; |
54 | extern pthread_mutex_t spider_open_conn_mutex; |
55 | extern HASH spider_open_connections; |
56 | extern HASH spider_ipport_conns; |
57 | extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; |
58 | extern const char spider_dig_upper[]; |
59 | |
60 | #define SPIDER_DB_WRAPPER_ORACLE "oracle" |
61 | |
62 | #define SPIDER_SQL_NAME_QUOTE_STR "\"" |
63 | #define SPIDER_SQL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_NAME_QUOTE_STR) - 1) |
64 | static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR; |
65 | |
66 | #define SPIDER_SQL_ISO_READ_COMMITTED_STR "set transaction isolation level read committed" |
67 | #define SPIDER_SQL_ISO_READ_COMMITTED_LEN sizeof(SPIDER_SQL_ISO_READ_COMMITTED_STR) - 1 |
68 | #define SPIDER_SQL_ISO_SERIALIZABLE_STR "set transaction isolation level serializable" |
69 | #define SPIDER_SQL_ISO_SERIALIZABLE_LEN sizeof(SPIDER_SQL_ISO_SERIALIZABLE_STR) - 1 |
70 | |
71 | #define SPIDER_SQL_START_TRANSACTION_STR "set transaction read write" |
72 | #define SPIDER_SQL_START_TRANSACTION_LEN sizeof(SPIDER_SQL_START_TRANSACTION_STR) - 1 |
73 | |
74 | #define SPIDER_SQL_AUTOCOMMIT_OFF_STR "set autocommit off" |
75 | #define SPIDER_SQL_AUTOCOMMIT_OFF_LEN sizeof(SPIDER_SQL_AUTOCOMMIT_OFF_STR) - 1 |
76 | #define SPIDER_SQL_AUTOCOMMIT_ON_STR "set autocommit on" |
77 | #define SPIDER_SQL_AUTOCOMMIT_ON_LEN sizeof(SPIDER_SQL_AUTOCOMMIT_ON_STR) - 1 |
78 | |
79 | #define SPIDER_SQL_LOCK_TABLE_STR "lock table " |
80 | #define SPIDER_SQL_LOCK_TABLE_LEN (sizeof(SPIDER_SQL_LOCK_TABLE_STR) - 1) |
81 | #define SPIDER_SQL_UNLOCK_TABLE_STR "unlock tables" |
82 | #define SPIDER_SQL_UNLOCK_TABLE_LEN (sizeof(SPIDER_SQL_UNLOCK_TABLE_STR) - 1) |
83 | #define SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR " in share mode" |
84 | #define SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN (sizeof(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR) - 1) |
85 | #define SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR " in exclusive mode" |
86 | #define SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN (sizeof(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR) - 1) |
87 | |
88 | #define SPIDER_SQL_COMMIT_STR "commit" |
89 | #define SPIDER_SQL_COMMIT_LEN sizeof(SPIDER_SQL_COMMIT_STR) - 1 |
90 | |
91 | #define SPIDER_SQL_SET_NLS_DATE_FORMAT_STR "alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'" |
92 | #define SPIDER_SQL_SET_NLS_DATE_FORMAT_LEN sizeof(SPIDER_SQL_SET_NLS_DATE_FORMAT_STR) - 1 |
93 | #define SPIDER_SQL_SET_NLS_TIME_FORMAT_STR "alter session set nls_time_format='HH24:MI:SSXFF'" |
94 | #define SPIDER_SQL_SET_NLS_TIME_FORMAT_LEN sizeof(SPIDER_SQL_SET_NLS_TIME_FORMAT_STR) - 1 |
95 | #define SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_STR "alter session set nls_timestamp_format='YYYY-MM-DD HH24:MI:SSXFF'" |
96 | #define SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_LEN sizeof(SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_STR) - 1 |
97 | |
98 | #define SPIDER_SQL_SELECT_WRAPPER_HEAD_STR "select * from (" |
99 | #define SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN sizeof(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR) - 1 |
100 | #define SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR " where rowid in (select rowid from (select rowid, row_number() over (order by " |
101 | #define SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN sizeof(SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR) - 1 |
102 | #define SPIDER_SQL_ROW_NUMBER_HEAD_STR ", row_number() over (order by " |
103 | #define SPIDER_SQL_ROW_NUMBER_HEAD_LEN sizeof(SPIDER_SQL_ROW_NUMBER_HEAD_STR) - 1 |
104 | #define SPIDER_SQL_ROW_NUMBER_TAIL_STR "rowid) row_num" |
105 | #define SPIDER_SQL_ROW_NUMBER_TAIL_LEN sizeof(SPIDER_SQL_ROW_NUMBER_TAIL_STR) - 1 |
106 | #define SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR "rowid desc) row_num" |
107 | #define SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN sizeof(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR) - 1 |
108 | #define SPIDER_SQL_SELECT_WRAPPER_TAIL_STR ") where row_num " |
109 | #define SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN sizeof(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR) - 1 |
110 | #define SPIDER_SQL_ROW_NUM_STR "row_num" |
111 | #define SPIDER_SQL_ROW_NUM_LEN sizeof(SPIDER_SQL_ROW_NUM_STR) - 1 |
112 | #define SPIDER_SQL_ROWNUM_STR "rownum" |
113 | #define SPIDER_SQL_ROWNUM_LEN sizeof(SPIDER_SQL_ROWNUM_STR) - 1 |
114 | #define SPIDER_SQL_NEXTVAL_STR ".nextval" |
115 | #define SPIDER_SQL_NEXTVAL_LEN sizeof(SPIDER_SQL_NEXTVAL_STR) - 1 |
116 | #define SPIDER_SQL_CURRVAL_STR ".currval" |
117 | #define SPIDER_SQL_CURRVAL_LEN sizeof(SPIDER_SQL_CURRVAL_STR) - 1 |
118 | #define SPIDER_SQL_FROM_DUAL_STR " from dual" |
119 | #define SPIDER_SQL_FROM_DUAL_LEN sizeof(SPIDER_SQL_FROM_DUAL_STR) - 1 |
120 | |
121 | #define SPIDER_SQL_SHOW_TABLE_STATUS_STR "show table status from " |
122 | #define SPIDER_SQL_SHOW_TABLE_STATUS_LEN sizeof(SPIDER_SQL_SHOW_TABLE_STATUS_STR) - 1 |
123 | #define SPIDER_SQL_SELECT_TABLES_STATUS_STR "select `table_rows`,`avg_row_length`,`data_length`,`max_data_length`,`index_length`,`auto_increment`,`create_time`,`update_time`,`check_time` from `information_schema`.`tables` where `table_schema` = " |
124 | #define SPIDER_SQL_SELECT_TABLES_STATUS_LEN sizeof(SPIDER_SQL_SELECT_TABLES_STATUS_STR) - 1 |
125 | |
126 | #define SPIDER_SQL_LIKE_STR " like " |
127 | #define SPIDER_SQL_LIKE_LEN (sizeof(SPIDER_SQL_LIKE_STR) - 1) |
128 | #define SPIDER_SQL_LIMIT1_STR "rownum = 1" |
129 | #define SPIDER_SQL_LIMIT1_LEN (sizeof(SPIDER_SQL_LIMIT1_STR) - 1) |
130 | |
131 | #define SPIDER_SQL_ADD_MONTHS_STR "add_months" |
132 | #define SPIDER_SQL_ADD_MONTHS_LEN (sizeof(SPIDER_SQL_ADD_MONTHS_STR) - 1) |
133 | |
134 | #define SPIDER_ORACLE_ERR_BUF_LEN 512 |
135 | |
136 | static uchar SPIDER_SQL_LINESTRING_HEAD_STR[] = |
137 | {0x00,0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00}; |
138 | #define SPIDER_SQL_LINESTRING_HEAD_LEN sizeof(SPIDER_SQL_LINESTRING_HEAD_STR) |
139 | |
140 | static const char *spider_db_table_lock_str[] = |
141 | { |
142 | " in share mode" , |
143 | " in share mode" , |
144 | " in exclusive mode" , |
145 | " in exclusive mode" |
146 | }; |
147 | static const int spider_db_table_lock_len[] = |
148 | { |
149 | sizeof(" in share mode" ) - 1, |
150 | sizeof(" in share mode" ) - 1, |
151 | sizeof(" in exclusive mode" ) - 1, |
152 | sizeof(" in exclusive mode" ) - 1 |
153 | }; |
154 | |
155 | int spider_db_oracle_get_error( |
156 | sword res, |
157 | dvoid *hndlp, |
158 | int error_num, |
159 | const char *error1, |
160 | const char *error2, |
161 | CHARSET_INFO *access_charset, |
162 | char *stored_error_msg |
163 | ) { |
164 | sb4 error_code; |
165 | char buf[SPIDER_ORACLE_ERR_BUF_LEN]; |
166 | char buf2[SPIDER_ORACLE_ERR_BUF_LEN]; |
167 | spider_string tmp_str(buf2, SPIDER_ORACLE_ERR_BUF_LEN, system_charset_info); |
168 | DBUG_ENTER("spider_db_oracle_get_error" ); |
169 | tmp_str.init_calc_mem(176); |
170 | tmp_str.length(0); |
171 | |
172 | switch (res) |
173 | { |
174 | case OCI_SUCCESS: |
175 | DBUG_PRINT("info" ,("spider res=OCI_SUCCESS" )); |
176 | break; |
177 | case OCI_SUCCESS_WITH_INFO: |
178 | DBUG_PRINT("info" ,("spider res=OCI_SUCCESS_WITH_INFO" )); |
179 | OCIErrorGet(hndlp, 1, NULL, &error_code, (OraText *) buf, sizeof(buf), |
180 | OCI_HTYPE_ERROR); |
181 | DBUG_PRINT("info" ,("spider error_code=%d error='%s'" ,error_code ,buf)); |
182 | if (access_charset && access_charset->cset != system_charset_info->cset) |
183 | { |
184 | tmp_str.append(buf, strlen(buf), access_charset); |
185 | } else { |
186 | tmp_str.set(buf, strlen(buf), system_charset_info); |
187 | } |
188 | push_warning_printf(current_thd, SPIDER_WARN_LEVEL_WARN, |
189 | ER_SPIDER_ORACLE_NUM, ER_SPIDER_ORACLE_STR, res, error_code, |
190 | tmp_str.c_ptr_safe()); |
191 | break; |
192 | case OCI_NO_DATA: |
193 | DBUG_PRINT("info" ,("spider res=OCI_NO_DATA" )); |
194 | DBUG_RETURN(HA_ERR_END_OF_FILE); |
195 | case OCI_ERROR: |
196 | DBUG_PRINT("info" ,("spider res=OCI_ERROR" )); |
197 | OCIErrorGet(hndlp, 1, NULL, &error_code, (OraText *) buf, sizeof(buf), |
198 | OCI_HTYPE_ERROR); |
199 | DBUG_PRINT("info" ,("spider error_code=%d error='%s'" ,error_code ,buf)); |
200 | if (error_code == 1) |
201 | { |
202 | DBUG_PRINT("info" ,("spider found dupp key" )); |
203 | if (stored_error_msg) |
204 | strmov(stored_error_msg, buf); |
205 | DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); |
206 | } |
207 | if (error_num) |
208 | { |
209 | if (error1) |
210 | { |
211 | if (error2) |
212 | { |
213 | my_printf_error(error_num, error1, MYF(0), error2); |
214 | } else { |
215 | my_printf_error(error_num, error1, MYF(0)); |
216 | } |
217 | } else if (error2) { |
218 | my_error(error_num, MYF(0), error2); |
219 | } else { |
220 | my_error(error_num, MYF(0)); |
221 | } |
222 | } |
223 | if (access_charset && access_charset->cset != system_charset_info->cset) |
224 | { |
225 | tmp_str.append(buf, strlen(buf), access_charset); |
226 | } else { |
227 | tmp_str.set(buf, strlen(buf), system_charset_info); |
228 | } |
229 | my_printf_error(ER_SPIDER_ORACLE_NUM, ER_SPIDER_ORACLE_STR, MYF(0), |
230 | res, error_code, tmp_str.c_ptr_safe()); |
231 | if (error_num) |
232 | { |
233 | DBUG_RETURN(error_num); |
234 | } else { |
235 | DBUG_RETURN(ER_SPIDER_ORACLE_NUM); |
236 | } |
237 | case OCI_INVALID_HANDLE: |
238 | case OCI_NEED_DATA: |
239 | if (res == OCI_INVALID_HANDLE) |
240 | DBUG_PRINT("info" ,("spider res=OCI_INVALID_HANDLE" )); |
241 | else |
242 | DBUG_PRINT("info" ,("spider res=OCI_NEED_DATA" )); |
243 | default: |
244 | DBUG_PRINT("info" ,("spider res=%d" , res)); |
245 | if (error_num) |
246 | { |
247 | if (error1) |
248 | { |
249 | if (error2) |
250 | { |
251 | my_printf_error(error_num, error1, MYF(0), error2); |
252 | } else { |
253 | my_printf_error(error_num, error1, MYF(0)); |
254 | } |
255 | } else if (error2) { |
256 | my_error(error_num, MYF(0), error2); |
257 | } else { |
258 | my_error(error_num, MYF(0)); |
259 | } |
260 | } |
261 | my_printf_error(ER_SPIDER_ORACLE_NUM, ER_SPIDER_ORACLE_STR, MYF(0), |
262 | res, 0, "" ); |
263 | if (error_num) |
264 | { |
265 | DBUG_RETURN(error_num); |
266 | } else { |
267 | DBUG_RETURN(ER_SPIDER_ORACLE_NUM); |
268 | } |
269 | } |
270 | DBUG_RETURN(0); |
271 | } |
272 | |
273 | int spider_oracle_init() |
274 | { |
275 | DBUG_ENTER("spider_oracle_init" ); |
276 | DBUG_RETURN(0); |
277 | } |
278 | |
279 | int spider_oracle_deinit() |
280 | { |
281 | DBUG_ENTER("spider_oracle_deinit" ); |
282 | DBUG_RETURN(0); |
283 | } |
284 | |
285 | spider_db_share *spider_oracle_create_share( |
286 | SPIDER_SHARE *share |
287 | ) { |
288 | DBUG_ENTER("spider_oracle_create_share" ); |
289 | DBUG_RETURN(new spider_oracle_share(share)); |
290 | } |
291 | |
292 | spider_db_handler *spider_oracle_create_handler( |
293 | ha_spider *spider, |
294 | spider_db_share *db_share |
295 | ) { |
296 | DBUG_ENTER("spider_oracle_create_handler" ); |
297 | DBUG_RETURN(new spider_oracle_handler(spider, |
298 | (spider_oracle_share *) db_share)); |
299 | } |
300 | |
301 | spider_db_copy_table *spider_oracle_create_copy_table( |
302 | spider_db_share *db_share |
303 | ) { |
304 | DBUG_ENTER("spider_oracle_create_copy_table" ); |
305 | DBUG_RETURN(new spider_oracle_copy_table( |
306 | (spider_oracle_share *) db_share)); |
307 | } |
308 | |
309 | SPIDER_DB_CONN *spider_oracle_create_conn( |
310 | SPIDER_CONN *conn |
311 | ) { |
312 | DBUG_ENTER("spider_oracle_create_conn" ); |
313 | DBUG_RETURN(new spider_db_oracle(conn)); |
314 | } |
315 | |
316 | bool spider_oracle_support_direct_join( |
317 | ) { |
318 | DBUG_ENTER("spider_oracle_support_direct_join" ); |
319 | DBUG_RETURN(FALSE); |
320 | } |
321 | |
322 | spider_db_oracle_util spider_db_oracle_utility; |
323 | |
324 | SPIDER_DBTON spider_dbton_oracle = { |
325 | 0, |
326 | SPIDER_DB_WRAPPER_ORACLE, |
327 | SPIDER_DB_ACCESS_TYPE_SQL, |
328 | spider_oracle_init, |
329 | spider_oracle_deinit, |
330 | spider_oracle_create_share, |
331 | spider_oracle_create_handler, |
332 | spider_oracle_create_copy_table, |
333 | spider_oracle_create_conn, |
334 | spider_oracle_support_direct_join, |
335 | &spider_db_oracle_utility |
336 | }; |
337 | |
338 | spider_db_oracle_row::spider_db_oracle_row() : |
339 | spider_db_row(spider_dbton_oracle.dbton_id), |
340 | db_conn(NULL), result(NULL), |
341 | ind(NULL), val(NULL), rlen(NULL), ind_first(NULL), val_first(NULL), |
342 | rlen_first(NULL), val_str(NULL), val_str_first(NULL), defnp(NULL), |
343 | lobhp(NULL), colhp(NULL), coltp(NULL), colsz(NULL), field_count(0), |
344 | row_size(NULL), row_size_first(NULL), access_charset(NULL), cloned(FALSE) |
345 | { |
346 | DBUG_ENTER("spider_db_oracle_row::spider_db_oracle_row" ); |
347 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
348 | DBUG_VOID_RETURN; |
349 | } |
350 | |
351 | spider_db_oracle_row::~spider_db_oracle_row() |
352 | { |
353 | DBUG_ENTER("spider_db_oracle_row::~spider_db_oracle_row" ); |
354 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
355 | deinit(); |
356 | DBUG_VOID_RETURN; |
357 | } |
358 | |
359 | int spider_db_oracle_row::store_to_field( |
360 | Field *field, |
361 | CHARSET_INFO *access_charset |
362 | ) { |
363 | DBUG_ENTER("spider_db_oracle_row::store_to_field" ); |
364 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
365 | DBUG_PRINT("info" ,("spider ind=%d" , *ind)); |
366 | if (*ind == -1) |
367 | { |
368 | DBUG_PRINT("info" , ("spider field is null" )); |
369 | field->set_null(); |
370 | field->reset(); |
371 | } else { |
372 | DBUG_PRINT("info" , ("spider field->type()=%u" , field->type())); |
373 | field->set_notnull(); |
374 | if (field->type() == MYSQL_TYPE_YEAR) |
375 | { |
376 | field->store(val_str->ptr(), 4, |
377 | field->table->s->table_charset); |
378 | } else if (field->type() == MYSQL_TYPE_DATE) |
379 | { |
380 | field->store(val_str->ptr(), 10, |
381 | field->table->s->table_charset); |
382 | } else if (field->type() == MYSQL_TYPE_TIME) |
383 | { |
384 | field->store(val_str->ptr() + 11, 8, |
385 | field->table->s->table_charset); |
386 | } else { |
387 | DBUG_PRINT("info" , ("spider val_str->length()=%u" , val_str->length())); |
388 | if (field->flags & BLOB_FLAG) |
389 | { |
390 | DBUG_PRINT("info" , ("spider blob field" )); |
391 | ((Field_blob *)field)->set_ptr( |
392 | val_str->length(), (uchar *) val_str->ptr()); |
393 | } else { |
394 | field->store(val_str->ptr(), val_str->length(), |
395 | field->table->s->table_charset); |
396 | } |
397 | } |
398 | } |
399 | DBUG_RETURN(0); |
400 | } |
401 | |
402 | int spider_db_oracle_row::append_to_str( |
403 | spider_string *str |
404 | ) { |
405 | DBUG_ENTER("spider_db_oracle_row::append_to_str" ); |
406 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
407 | if (str->reserve(val_str->length())) |
408 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
409 | str->q_append(val_str->ptr(), val_str->length()); |
410 | DBUG_RETURN(0); |
411 | } |
412 | |
413 | int spider_db_oracle_row::append_escaped_to_str( |
414 | spider_string *str, |
415 | uint dbton_id |
416 | ) { |
417 | DBUG_ENTER("spider_db_oracle_row::append_escaped_to_str" ); |
418 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
419 | /* |
420 | spider_string tmp_str(*val, *rlen, str->charset()); |
421 | tmp_str.init_calc_mem(174); |
422 | tmp_str.length(*rlen); |
423 | #ifndef DBUG_OFF |
424 | tmp_str.c_ptr_safe(); |
425 | #endif |
426 | if (str->reserve(*rlen * 2)) |
427 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
428 | util.append_escaped(str, tmp_str.get_str()); |
429 | */ |
430 | if (str->reserve(val_str->length() * 2)) |
431 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
432 | spider_dbton[dbton_id].db_util->append_escaped_util(str, val_str->get_str()); |
433 | DBUG_RETURN(0); |
434 | } |
435 | |
436 | void spider_db_oracle_row::first() |
437 | { |
438 | DBUG_ENTER("spider_db_oracle_row::first" ); |
439 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
440 | DBUG_PRINT("info" ,("spider ind_first=%p" , ind_first)); |
441 | ind = ind_first; |
442 | DBUG_PRINT("info" ,("spider val_first=%p" , val_first)); |
443 | val = val_first; |
444 | DBUG_PRINT("info" ,("spider rlen_first=%p" , rlen_first)); |
445 | rlen = rlen_first; |
446 | DBUG_PRINT("info" ,("spider row_size_first=%p" , row_size_first)); |
447 | row_size = row_size_first; |
448 | DBUG_PRINT("info" ,("spider val_str_first=%p" , val_str_first)); |
449 | val_str = val_str_first; |
450 | DBUG_VOID_RETURN; |
451 | } |
452 | |
453 | void spider_db_oracle_row::next() |
454 | { |
455 | DBUG_ENTER("spider_db_oracle_row::next" ); |
456 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
457 | ind++; |
458 | val++; |
459 | rlen++; |
460 | row_size++; |
461 | val_str++; |
462 | DBUG_VOID_RETURN; |
463 | } |
464 | |
465 | bool spider_db_oracle_row::is_null() |
466 | { |
467 | DBUG_ENTER("spider_db_oracle_row::is_null" ); |
468 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
469 | DBUG_RETURN((*ind == -1)); |
470 | } |
471 | |
472 | int spider_db_oracle_row::val_int() |
473 | { |
474 | DBUG_ENTER("spider_db_oracle_row::val_int" ); |
475 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
476 | DBUG_RETURN((*ind != -1) ? atoi(*val) : 0); |
477 | } |
478 | |
479 | double spider_db_oracle_row::val_real() |
480 | { |
481 | DBUG_ENTER("spider_db_oracle_row::val_real" ); |
482 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
483 | DBUG_RETURN((*ind != -1) ? my_atof(*val) : 0.0); |
484 | } |
485 | |
486 | my_decimal *spider_db_oracle_row::val_decimal( |
487 | my_decimal *decimal_value, |
488 | CHARSET_INFO *access_charset |
489 | ) { |
490 | DBUG_ENTER("spider_db_oracle_row::val_decimal" ); |
491 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
492 | if (*ind == -1) |
493 | DBUG_RETURN(NULL); |
494 | |
495 | #ifdef SPIDER_HAS_DECIMAL_OPERATION_RESULTS_VALUE_TYPE |
496 | decimal_operation_results(str2my_decimal(0, *val, *rlen, access_charset, |
497 | decimal_value), "" , "" ); |
498 | #else |
499 | decimal_operation_results(str2my_decimal(0, *val, *rlen, access_charset, |
500 | decimal_value)); |
501 | #endif |
502 | |
503 | DBUG_RETURN(decimal_value); |
504 | } |
505 | |
506 | SPIDER_DB_ROW *spider_db_oracle_row::clone() |
507 | { |
508 | uint i; |
509 | spider_db_oracle_row *clone_row; |
510 | DBUG_ENTER("spider_db_oracle_row::clone" ); |
511 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
512 | if (!(clone_row = new spider_db_oracle_row())) |
513 | { |
514 | DBUG_RETURN(NULL); |
515 | } |
516 | clone_row->db_conn = db_conn; |
517 | clone_row->result = result; |
518 | clone_row->field_count = field_count; |
519 | clone_row->access_charset = access_charset; |
520 | clone_row->cloned = TRUE; |
521 | if (clone_row->init()) |
522 | { |
523 | delete clone_row; |
524 | DBUG_RETURN(NULL); |
525 | } |
526 | memcpy(clone_row->ind, ind_first, sizeof(ub2) * field_count * 4 + |
527 | sizeof(ulong) * field_count); |
528 | for (i = 0; i < field_count; i++) |
529 | { |
530 | if (clone_row->val_str[i].copy(val_str_first[i])) |
531 | { |
532 | delete clone_row; |
533 | DBUG_RETURN(NULL); |
534 | } |
535 | } |
536 | DBUG_RETURN((SPIDER_DB_ROW *) clone_row); |
537 | } |
538 | |
539 | int spider_db_oracle_row::store_to_tmp_table( |
540 | TABLE *tmp_table, |
541 | spider_string *str |
542 | ) { |
543 | uint i; |
544 | DBUG_ENTER("spider_db_oracle_row::store_to_tmp_table" ); |
545 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
546 | str->length(0); |
547 | for (i = 0; i < field_count; i++) |
548 | { |
549 | if (row_size_first[i]) |
550 | { |
551 | if (str->reserve(val_str_first[i].length())) |
552 | { |
553 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
554 | } |
555 | str->q_append(val_str_first[i].ptr(), val_str_first[i].length()); |
556 | } |
557 | } |
558 | tmp_table->field[0]->set_notnull(); |
559 | tmp_table->field[0]->store( |
560 | (const char *) row_size_first, |
561 | sizeof(ulong) * field_count, &my_charset_bin); |
562 | tmp_table->field[1]->set_notnull(); |
563 | tmp_table->field[1]->store( |
564 | str->ptr(), str->length(), &my_charset_bin); |
565 | tmp_table->field[2]->set_notnull(); |
566 | tmp_table->field[2]->store( |
567 | (char *) ind_first, (uint) (sizeof(sb2) * field_count), &my_charset_bin); |
568 | DBUG_RETURN(tmp_table->file->ha_write_row(tmp_table->record[0])); |
569 | } |
570 | |
571 | int spider_db_oracle_row::init() |
572 | { |
573 | char *tmp_val; |
574 | uint i; |
575 | DBUG_ENTER("spider_db_oracle_row::init" ); |
576 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
577 | if ( |
578 | !(ind = (sb2 *) |
579 | spider_bulk_malloc(spider_current_trx, 161, MYF(MY_WME | MY_ZEROFILL), |
580 | &ind, sizeof(sb2) * field_count, |
581 | &rlen, sizeof(ub2) * field_count, |
582 | &coltp, sizeof(ub2) * field_count, |
583 | &colsz, sizeof(ub2) * field_count, |
584 | &row_size, sizeof(ulong) * field_count, |
585 | &val, sizeof(char *) * field_count, |
586 | &tmp_val, MAX_FIELD_WIDTH * field_count, |
587 | &defnp, sizeof(OCIDefine *) * field_count, |
588 | &lobhp, sizeof(OCILobLocator *) * field_count, |
589 | &colhp, sizeof(OCIParam *) * field_count, |
590 | NullS) |
591 | ) || |
592 | !(val_str = new spider_string[field_count]) |
593 | ) { |
594 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
595 | } |
596 | ind_first = ind; |
597 | val_first = val; |
598 | rlen_first = rlen; |
599 | row_size_first = row_size; |
600 | val_str_first = val_str; |
601 | for (i = 0; i < field_count; i++) |
602 | { |
603 | val[i] = tmp_val; |
604 | val_str[i].init_calc_mem(177); |
605 | val_str[i].set(tmp_val, MAX_FIELD_WIDTH, access_charset); |
606 | tmp_val += MAX_FIELD_WIDTH; |
607 | } |
608 | DBUG_RETURN(0); |
609 | } |
610 | |
611 | void spider_db_oracle_row::deinit() |
612 | { |
613 | uint i; |
614 | DBUG_ENTER("spider_db_oracle_row::deinit" ); |
615 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
616 | if (!cloned) |
617 | { |
618 | for (i = 0; i < field_count; i++) |
619 | { |
620 | if (defnp && defnp[i]) |
621 | { |
622 | OCIHandleFree(defnp[i], OCI_HTYPE_DEFINE); |
623 | defnp[i] = NULL; |
624 | } |
625 | if (lobhp && lobhp[i]) |
626 | { |
627 | OCIDescriptorFree(lobhp[i], OCI_DTYPE_LOB); |
628 | lobhp[i] = NULL; |
629 | } |
630 | } |
631 | } |
632 | if (val_str_first) |
633 | { |
634 | delete [] val_str_first; |
635 | val_str_first = NULL; |
636 | } |
637 | if (ind_first) |
638 | { |
639 | spider_free(spider_current_trx, ind_first, MYF(0)); |
640 | ind_first = NULL; |
641 | } |
642 | DBUG_VOID_RETURN; |
643 | } |
644 | |
645 | int spider_db_oracle_row::define() |
646 | { |
647 | sword res; |
648 | uint i; |
649 | DBUG_ENTER("spider_db_oracle_row::define" ); |
650 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
651 | for (i = 0; i < field_count; i++) |
652 | { |
653 | if (coltp[i] == SQLT_BLOB) |
654 | { |
655 | res = OCIDescriptorAlloc(db_conn->envhp, (dvoid **) &lobhp[i], |
656 | OCI_DTYPE_LOB, 0, 0); |
657 | if (res != OCI_SUCCESS) |
658 | { |
659 | DBUG_RETURN( |
660 | spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, |
661 | access_charset, NULL)); |
662 | } |
663 | res = OCIDefineByPos(result->stmtp, &defnp[i], db_conn->errhp, i + 1, |
664 | &lobhp[i], 0, SQLT_BLOB, &ind[i], &rlen[i], NULL, |
665 | OCI_DEFAULT); |
666 | } else if (coltp[i] == SQLT_DAT) |
667 | { |
668 | res = OCIDefineByPos(result->stmtp, &defnp[i], db_conn->errhp, i + 1, |
669 | (char *) val_str[i].ptr() + 20, sizeof(ub1) * 7, SQLT_DAT, &ind[i], |
670 | &rlen[i], NULL, OCI_DEFAULT); |
671 | } else { |
672 | if (val_str[i].alloc(colsz[i])) |
673 | { |
674 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
675 | } |
676 | res = OCIDefineByPos(result->stmtp, &defnp[i], db_conn->errhp, i + 1, |
677 | (char *) val_str[i].ptr(), colsz[i], SQLT_CHR, &ind[i], &rlen[i], NULL, |
678 | OCI_DEFAULT); |
679 | } |
680 | if (res != OCI_SUCCESS) |
681 | { |
682 | DBUG_RETURN( |
683 | spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, |
684 | access_charset, NULL)); |
685 | } |
686 | } |
687 | DBUG_RETURN(0); |
688 | } |
689 | |
690 | int spider_db_oracle_row::fetch() |
691 | { |
692 | sword res; |
693 | uint i; |
694 | DBUG_ENTER("spider_db_oracle_row::fetch" ); |
695 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
696 | for (i = 0; i < field_count; i++) |
697 | { |
698 | if (ind[i] == -1) |
699 | { |
700 | DBUG_PRINT("info" ,("spider NULL" )); |
701 | val_str[i].length(0); |
702 | } else { |
703 | if (coltp[i] == SQLT_BLOB) |
704 | { |
705 | DBUG_PRINT("info" ,("spider SQLT_BLOB" )); |
706 | oraub8 len; |
707 | res = OCILobGetLength2(db_conn->svchp, db_conn->errhp, lobhp[i], &len); |
708 | if (res != OCI_SUCCESS) |
709 | { |
710 | DBUG_RETURN( |
711 | spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, |
712 | access_charset, NULL)); |
713 | } |
714 | #ifndef DBUG_OFF |
715 | { |
716 | ulonglong print_len = len; |
717 | DBUG_PRINT("info" ,("spider len=%llu" , print_len)); |
718 | } |
719 | #endif |
720 | if (val_str[i].alloc(len)) |
721 | { |
722 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
723 | } |
724 | res = OCILobRead2(db_conn->svchp, db_conn->errhp, lobhp[i], &len, |
725 | NULL, 1, (char *) val_str[i].ptr(), len, OCI_ONE_PIECE, NULL, NULL, |
726 | 0, 0); |
727 | if (res != OCI_SUCCESS) |
728 | { |
729 | DBUG_RETURN( |
730 | spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, |
731 | access_charset, NULL)); |
732 | } |
733 | #ifndef DBUG_OFF |
734 | { |
735 | ulonglong print_len = len; |
736 | DBUG_PRINT("info" ,("spider lenb=%llu" , print_len)); |
737 | } |
738 | #endif |
739 | val_str[i].length(len); |
740 | } else if (coltp[i] == SQLT_DAT) |
741 | { |
742 | DBUG_PRINT("info" ,("spider SQLT_DAT" )); |
743 | char *val = (char *) val_str[i].ptr(); |
744 | ub1 *src = (ub1 *) val + 20; |
745 | val_str[i].length(19); |
746 | if (src[0] < 100) |
747 | my_sprintf(val, (val, "0000-00-00 00:00:00" )); |
748 | else |
749 | my_sprintf(val, (val, "%02u%02u-%02u-%02u %02u:%02u:%02u" , |
750 | src[0] - 100, src[1] - 100, src[2], src[3], |
751 | src[4] - 1, src[5] - 1, src[6] - 1)); |
752 | } else { |
753 | val_str[i].length(rlen[i]); |
754 | } |
755 | } |
756 | row_size[i] = val_str[i].length(); |
757 | } |
758 | DBUG_RETURN(0); |
759 | } |
760 | |
761 | spider_db_oracle_result::spider_db_oracle_result(SPIDER_DB_CONN *in_db_conn) : |
762 | spider_db_result(in_db_conn, spider_dbton_oracle.dbton_id), |
763 | db_conn(NULL), stmtp(NULL), field_count(0), access_charset(NULL), |
764 | fetched(FALSE) |
765 | { |
766 | DBUG_ENTER("spider_db_oracle_result::spider_db_oracle_result" ); |
767 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
768 | DBUG_VOID_RETURN; |
769 | } |
770 | |
771 | spider_db_oracle_result::~spider_db_oracle_result() |
772 | { |
773 | DBUG_ENTER("spider_db_oracle_result::~spider_db_oracle_result" ); |
774 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
775 | free_result(); |
776 | DBUG_VOID_RETURN; |
777 | } |
778 | |
779 | bool spider_db_oracle_result::has_result() |
780 | { |
781 | DBUG_ENTER("spider_db_oracle_result::has_result" ); |
782 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
783 | DBUG_RETURN(stmtp); |
784 | } |
785 | |
786 | void spider_db_oracle_result::free_result() |
787 | { |
788 | DBUG_ENTER("spider_db_oracle_result::free_result" ); |
789 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
790 | if (stmtp) |
791 | { |
792 | OCIHandleFree(stmtp, OCI_HTYPE_STMT); |
793 | stmtp = NULL; |
794 | } |
795 | DBUG_VOID_RETURN; |
796 | } |
797 | |
798 | SPIDER_DB_ROW *spider_db_oracle_result::current_row() |
799 | { |
800 | DBUG_ENTER("spider_db_oracle_result::current_row" ); |
801 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
802 | DBUG_RETURN((SPIDER_DB_ROW *) row.clone()); |
803 | } |
804 | |
805 | SPIDER_DB_ROW *spider_db_oracle_result::fetch_row() |
806 | { |
807 | sword res; |
808 | DBUG_ENTER("spider_db_oracle_result::fetch_row" ); |
809 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
810 | row.ind = row.ind_first; |
811 | row.val = row.val_first; |
812 | row.rlen = row.rlen_first; |
813 | row.row_size = row.row_size_first; |
814 | row.val_str = row.val_str_first; |
815 | if (fetched) |
816 | { |
817 | /* already fetched */ |
818 | fetched = FALSE; |
819 | } else { |
820 | res = OCIStmtFetch2(stmtp, db_conn->errhp, 1, OCI_FETCH_NEXT, 0, |
821 | OCI_DEFAULT); |
822 | if (res != OCI_SUCCESS) |
823 | { |
824 | store_error_num = spider_db_oracle_get_error(res, db_conn->errhp, 0, |
825 | NULL, NULL, access_charset, NULL); |
826 | DBUG_RETURN(NULL); |
827 | } |
828 | } |
829 | if ((store_error_num = row.fetch())) |
830 | { |
831 | DBUG_RETURN(NULL); |
832 | } |
833 | DBUG_RETURN((SPIDER_DB_ROW *) &row); |
834 | } |
835 | |
836 | SPIDER_DB_ROW *spider_db_oracle_result::fetch_row_from_result_buffer( |
837 | spider_db_result_buffer *spider_res_buf |
838 | ) { |
839 | sword res; |
840 | DBUG_ENTER("spider_db_oracle_result::fetch_row_from_result_buffer" ); |
841 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
842 | row.ind = row.ind_first; |
843 | row.val = row.val_first; |
844 | row.rlen = row.rlen_first; |
845 | row.row_size = row.row_size_first; |
846 | row.val_str = row.val_str_first; |
847 | if (fetched) |
848 | { |
849 | /* already fetched */ |
850 | fetched = FALSE; |
851 | } else { |
852 | res = OCIStmtFetch2(stmtp, db_conn->errhp, 1, OCI_FETCH_NEXT, 0, |
853 | OCI_DEFAULT); |
854 | if (res != OCI_SUCCESS) |
855 | { |
856 | store_error_num = spider_db_oracle_get_error(res, db_conn->errhp, 0, |
857 | NULL, NULL, access_charset, NULL); |
858 | DBUG_RETURN(NULL); |
859 | } |
860 | } |
861 | if ((store_error_num = row.fetch())) |
862 | { |
863 | DBUG_RETURN(NULL); |
864 | } |
865 | DBUG_RETURN((SPIDER_DB_ROW *) &row); |
866 | } |
867 | |
868 | SPIDER_DB_ROW *spider_db_oracle_result::fetch_row_from_tmp_table( |
869 | TABLE *tmp_table |
870 | ) { |
871 | uint i; |
872 | const char *str; |
873 | spider_string tmp_str1, tmp_str2, tmp_str3; |
874 | DBUG_ENTER("spider_db_oracle_result::fetch_row_from_tmp_table" ); |
875 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
876 | tmp_str1.init_calc_mem(175); |
877 | tmp_str2.init_calc_mem(178); |
878 | tmp_str3.init_calc_mem(179); |
879 | tmp_table->field[0]->val_str(tmp_str1.get_str()); |
880 | tmp_table->field[1]->val_str(tmp_str2.get_str()); |
881 | tmp_table->field[2]->val_str(tmp_str3.get_str()); |
882 | tmp_str1.mem_calc(); |
883 | tmp_str2.mem_calc(); |
884 | tmp_str3.mem_calc(); |
885 | row.ind = row.ind_first; |
886 | row.val = row.val_first; |
887 | row.rlen = row.rlen_first; |
888 | row.row_size = row.row_size_first; |
889 | row.val_str = row.val_str_first; |
890 | DBUG_PRINT("info" ,("spider tmp_str1.length()=%u" , tmp_str1.length())); |
891 | DBUG_PRINT("info" ,("spider tmp_str2.length()=%u" , tmp_str2.length())); |
892 | DBUG_PRINT("info" ,("spider tmp_str3.length()=%u" , tmp_str3.length())); |
893 | memcpy(row.ind, tmp_str3.ptr(), tmp_str3.length()); |
894 | memcpy(row.row_size, tmp_str1.ptr(), tmp_str1.length()); |
895 | row.field_count = tmp_str1.length() / sizeof(ulong); |
896 | str = tmp_str2.ptr(); |
897 | for (i = 0; i < row.field_count; i++) |
898 | { |
899 | row.val_str[i].length(0); |
900 | if (row.row_size[i]) |
901 | { |
902 | if (row.val_str[i].reserve(row.row_size[i])) |
903 | { |
904 | store_error_num = HA_ERR_OUT_OF_MEM; |
905 | DBUG_RETURN(NULL); |
906 | } |
907 | row.val_str[i].q_append(str, row.row_size[i]); |
908 | str += row.row_size[i]; |
909 | } |
910 | } |
911 | DBUG_RETURN((SPIDER_DB_ROW *) &row); |
912 | } |
913 | |
914 | int spider_db_oracle_result::fetch_table_status( |
915 | int mode, |
916 | ha_rows &records, |
917 | ulong &mean_rec_length, |
918 | ulonglong &data_file_length, |
919 | ulonglong &max_data_file_length, |
920 | ulonglong &index_file_length, |
921 | ulonglong &auto_increment_value, |
922 | time_t &create_time, |
923 | time_t &update_time, |
924 | time_t &check_time |
925 | ) { |
926 | DBUG_ENTER("spider_db_oracle_result::fetch_table_status" ); |
927 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
928 | /* TODO: develop later */ |
929 | records = 2; |
930 | mean_rec_length = 65535; |
931 | data_file_length = 65535; |
932 | max_data_file_length = 65535; |
933 | index_file_length = 65535; |
934 | /* |
935 | auto_increment_value = 0; |
936 | */ |
937 | create_time = (time_t) 0; |
938 | update_time = (time_t) 0; |
939 | check_time = (time_t) 0; |
940 | DBUG_RETURN(0); |
941 | } |
942 | |
943 | int spider_db_oracle_result::fetch_table_records( |
944 | int mode, |
945 | ha_rows &records |
946 | ) { |
947 | DBUG_ENTER("spider_db_oracle_result::fetch_table_records" ); |
948 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
949 | if (!fetch_row()) |
950 | { |
951 | records = 0; |
952 | } else { |
953 | records = row.val_int(); |
954 | } |
955 | DBUG_RETURN(0); |
956 | } |
957 | |
958 | int spider_db_oracle_result::fetch_table_cardinality( |
959 | int mode, |
960 | TABLE *table, |
961 | longlong *cardinality, |
962 | uchar *cardinality_upd, |
963 | int bitmap_size |
964 | ) { |
965 | DBUG_ENTER("spider_db_oracle_result::fetch_table_cardinality" ); |
966 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
967 | /* TODO: develop later */ |
968 | DBUG_RETURN(0); |
969 | } |
970 | |
971 | int spider_db_oracle_result::fetch_table_mon_status( |
972 | int &status |
973 | ) { |
974 | DBUG_ENTER("spider_db_oracle_result::fetch_table_mon_status" ); |
975 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
976 | /* TODO: develop later */ |
977 | status = SPIDER_LINK_MON_OK; |
978 | DBUG_RETURN(0); |
979 | } |
980 | |
981 | longlong spider_db_oracle_result::num_rows() |
982 | { |
983 | sword res; |
984 | ub4 rowcnt; |
985 | DBUG_ENTER("spider_db_oracle_result::num_rows" ); |
986 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
987 | res = OCIAttrGet(stmtp, OCI_HTYPE_STMT, &rowcnt, 0, |
988 | OCI_ATTR_ROW_COUNT, db_conn->errhp); |
989 | if (res != OCI_SUCCESS) |
990 | { |
991 | spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, |
992 | access_charset, NULL); |
993 | DBUG_RETURN(0); |
994 | } |
995 | DBUG_PRINT("info" ,("spider rowcnt=%u" , rowcnt)); |
996 | DBUG_RETURN((longlong) rowcnt); |
997 | } |
998 | |
999 | uint spider_db_oracle_result::num_fields() |
1000 | { |
1001 | sword res; |
1002 | ub4 parmcnt; |
1003 | DBUG_ENTER("spider_db_oracle_result::num_fields" ); |
1004 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1005 | res = OCIAttrGet(stmtp, OCI_HTYPE_STMT, &parmcnt, 0, |
1006 | OCI_ATTR_PARAM_COUNT, db_conn->errhp); |
1007 | if (res != OCI_SUCCESS) |
1008 | { |
1009 | spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, |
1010 | access_charset, NULL); |
1011 | DBUG_RETURN(0); |
1012 | } |
1013 | DBUG_RETURN((uint) parmcnt); |
1014 | } |
1015 | |
1016 | void spider_db_oracle_result::move_to_pos( |
1017 | longlong pos |
1018 | ) { |
1019 | sword res; |
1020 | DBUG_ENTER("spider_db_oracle_result::move_to_pos" ); |
1021 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1022 | DBUG_PRINT("info" ,("spider pos=%lld" , pos)); |
1023 | res = OCIStmtFetch2(stmtp, db_conn->errhp, 1, OCI_FETCH_ABSOLUTE, pos, |
1024 | OCI_DEFAULT); |
1025 | if (res != OCI_SUCCESS) |
1026 | { |
1027 | spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, |
1028 | access_charset, NULL); |
1029 | } |
1030 | DBUG_VOID_RETURN; |
1031 | } |
1032 | |
1033 | int spider_db_oracle_result::set_column_info() |
1034 | { |
1035 | sword res; |
1036 | uint i; |
1037 | DBUG_ENTER("spider_db_oracle_result::set_column_info" ); |
1038 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1039 | for (i = 0; i < field_count; i++) |
1040 | { |
1041 | res = OCIParamGet(stmtp, OCI_HTYPE_STMT, db_conn->errhp, |
1042 | (dvoid **) &row.colhp[i], i + 1); |
1043 | if (res != OCI_SUCCESS) |
1044 | { |
1045 | DBUG_RETURN(spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, |
1046 | NULL, access_charset, NULL)); |
1047 | } |
1048 | res = OCIAttrGet(row.colhp[i], OCI_DTYPE_PARAM, &row.coltp[i], NULL, |
1049 | OCI_ATTR_DATA_TYPE, db_conn->errhp); |
1050 | if (res != OCI_SUCCESS) |
1051 | { |
1052 | DBUG_RETURN(spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, |
1053 | NULL, access_charset, NULL)); |
1054 | } |
1055 | res = OCIAttrGet(row.colhp[i], OCI_DTYPE_PARAM, &row.colsz[i], NULL, |
1056 | OCI_ATTR_DATA_SIZE, db_conn->errhp); |
1057 | if (res != OCI_SUCCESS) |
1058 | { |
1059 | DBUG_RETURN(spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, |
1060 | NULL, access_charset, NULL)); |
1061 | } |
1062 | } |
1063 | DBUG_RETURN(0); |
1064 | } |
1065 | |
1066 | int spider_db_oracle_result::get_errno() |
1067 | { |
1068 | DBUG_ENTER("spider_db_oracle_result::get_errno" ); |
1069 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1070 | DBUG_PRINT("info" ,("spider store_error_num=%d" , store_error_num)); |
1071 | DBUG_RETURN(store_error_num); |
1072 | } |
1073 | |
1074 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
1075 | int spider_db_oracle_result::fetch_columns_for_discover_table_structure( |
1076 | spider_string *str, |
1077 | CHARSET_INFO *access_charset |
1078 | ) { |
1079 | DBUG_ENTER("spider_db_oracle_result::fetch_columns_for_discover_table_structure" ); |
1080 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1081 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
1082 | } |
1083 | |
1084 | int spider_db_oracle_result::fetch_index_for_discover_table_structure( |
1085 | spider_string *str, |
1086 | CHARSET_INFO *access_charset |
1087 | ) { |
1088 | DBUG_ENTER("spider_db_oracle_result::fetch_index_for_discover_table_structure" ); |
1089 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1090 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
1091 | } |
1092 | |
1093 | int spider_db_oracle_result::fetch_table_for_discover_table_structure( |
1094 | spider_string *str, |
1095 | SPIDER_SHARE *spider_share, |
1096 | CHARSET_INFO *access_charset |
1097 | ) { |
1098 | DBUG_ENTER("spider_db_oracle_result::fetch_table_for_discover_table_structure" ); |
1099 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1100 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
1101 | } |
1102 | #endif |
1103 | |
1104 | spider_db_oracle::spider_db_oracle( |
1105 | SPIDER_CONN *conn |
1106 | ) : spider_db_conn(conn), envhp(NULL), errhp(NULL), srvhp(NULL), svchp(NULL), |
1107 | usrhp(NULL), stmtp(NULL), txnhp(NULL), result(NULL), table_lock_mode(0), |
1108 | lock_table_hash_inited(FALSE), handler_open_array_inited(FALSE) |
1109 | { |
1110 | DBUG_ENTER("spider_db_oracle::spider_db_oracle" ); |
1111 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1112 | DBUG_VOID_RETURN; |
1113 | } |
1114 | |
1115 | spider_db_oracle::~spider_db_oracle() |
1116 | { |
1117 | DBUG_ENTER("spider_db_oracle::~spider_db_oracle" ); |
1118 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1119 | if (handler_open_array_inited) |
1120 | { |
1121 | reset_opened_handler(); |
1122 | spider_free_mem_calc(spider_current_trx, |
1123 | handler_open_array_id, |
1124 | handler_open_array.max_element * |
1125 | handler_open_array.size_of_element); |
1126 | delete_dynamic(&handler_open_array); |
1127 | } |
1128 | if (lock_table_hash_inited) |
1129 | { |
1130 | spider_free_mem_calc(spider_current_trx, |
1131 | lock_table_hash_id, |
1132 | lock_table_hash.array.max_element * |
1133 | lock_table_hash.array.size_of_element); |
1134 | my_hash_free(&lock_table_hash); |
1135 | } |
1136 | disconnect(); |
1137 | DBUG_VOID_RETURN; |
1138 | } |
1139 | |
1140 | int spider_db_oracle::init() |
1141 | { |
1142 | DBUG_ENTER("spider_db_oracle::init" ); |
1143 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1144 | if ( |
1145 | my_hash_init(&lock_table_hash, spd_charset_utf8_bin, 32, 0, 0, |
1146 | (my_hash_get_key) spider_link_get_key, 0, 0) |
1147 | ) { |
1148 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
1149 | } |
1150 | spider_alloc_calc_mem_init(lock_table_hash, 199); |
1151 | spider_alloc_calc_mem(spider_current_trx, |
1152 | lock_table_hash, |
1153 | lock_table_hash.array.max_element * |
1154 | lock_table_hash.array.size_of_element); |
1155 | lock_table_hash_inited = TRUE; |
1156 | |
1157 | if ( |
1158 | SPD_INIT_DYNAMIC_ARRAY2(&handler_open_array, |
1159 | sizeof(SPIDER_LINK_FOR_HASH *), NULL, 16, 16, MYF(MY_WME)) |
1160 | ) { |
1161 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
1162 | } |
1163 | spider_alloc_calc_mem_init(handler_open_array, 164); |
1164 | spider_alloc_calc_mem(spider_current_trx, |
1165 | handler_open_array, |
1166 | handler_open_array.max_element * |
1167 | handler_open_array.size_of_element); |
1168 | handler_open_array_inited = TRUE; |
1169 | DBUG_RETURN(0); |
1170 | } |
1171 | |
1172 | bool spider_db_oracle::is_connected() |
1173 | { |
1174 | DBUG_ENTER("spider_db_oracle::is_connected" ); |
1175 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1176 | DBUG_RETURN(svchp); |
1177 | } |
1178 | |
1179 | void spider_db_oracle::bg_connect() |
1180 | { |
1181 | sword res; |
1182 | DBUG_ENTER("spider_db_oracle::bg_connect" ); |
1183 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1184 | res = OCIEnvNlsCreate(&envhp, OCI_DEFAULT, 0, 0, 0, 0, 0, 0, 0, 0); |
1185 | /* |
1186 | res = OCIEnvCreate(&envhp, OCI_THREADED, 0, 0, 0, 0, 0, 0); |
1187 | */ |
1188 | if (res != OCI_SUCCESS) |
1189 | { |
1190 | DBUG_PRINT("info" ,("spider create environment error" )); |
1191 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1192 | goto error; |
1193 | } |
1194 | DBUG_PRINT("info" ,("spider OCI init envhp=%p" , envhp)); |
1195 | |
1196 | res = OCIHandleAlloc(envhp, (dvoid **) &errhp, OCI_HTYPE_ERROR, 0, 0); |
1197 | if (res != OCI_SUCCESS) |
1198 | { |
1199 | DBUG_PRINT("info" ,("spider create error handler error" )); |
1200 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1201 | bg_disconnect(); |
1202 | goto error; |
1203 | } |
1204 | DBUG_PRINT("info" ,("spider OCI init errhp=%p" , errhp)); |
1205 | |
1206 | res = OCIHandleAlloc(envhp, (dvoid **) &srvhp, OCI_HTYPE_SERVER, 0, 0); |
1207 | if (res != OCI_SUCCESS) |
1208 | { |
1209 | DBUG_PRINT("info" ,("spider create server handler error" )); |
1210 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1211 | bg_disconnect(); |
1212 | goto error; |
1213 | } |
1214 | DBUG_PRINT("info" ,("spider OCI init srvhp=%p" , srvhp)); |
1215 | |
1216 | res = OCIServerAttach(srvhp, errhp, (OraText *) tgt_host, strlen(tgt_host), |
1217 | OCI_DEFAULT); |
1218 | if (res != OCI_SUCCESS) |
1219 | { |
1220 | DBUG_PRINT("info" ,("spider attach server error" )); |
1221 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1222 | bg_disconnect(); |
1223 | goto error; |
1224 | } |
1225 | |
1226 | res = OCIHandleAlloc(envhp, (dvoid **) &svchp, OCI_HTYPE_SVCCTX, 0, 0); |
1227 | if (res != OCI_SUCCESS) |
1228 | { |
1229 | DBUG_PRINT("info" ,("spider create service context error" )); |
1230 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1231 | bg_disconnect(); |
1232 | goto error; |
1233 | } |
1234 | DBUG_PRINT("info" ,("spider OCI init svchp=%p" , svchp)); |
1235 | |
1236 | res = OCIAttrSet(svchp, OCI_HTYPE_SVCCTX, srvhp, 0, OCI_ATTR_SERVER, errhp); |
1237 | if (res != OCI_SUCCESS) |
1238 | { |
1239 | DBUG_PRINT("info" ,("spider set server attr error" )); |
1240 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1241 | bg_disconnect(); |
1242 | goto error; |
1243 | } |
1244 | |
1245 | res = OCIHandleAlloc(envhp, (dvoid **) &usrhp, OCI_HTYPE_SESSION, 0, 0); |
1246 | if (res != OCI_SUCCESS) |
1247 | { |
1248 | DBUG_PRINT("info" ,("spider create session handler error" )); |
1249 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1250 | bg_disconnect(); |
1251 | goto error; |
1252 | } |
1253 | DBUG_PRINT("info" ,("spider OCI init usrhp=%p" , usrhp)); |
1254 | |
1255 | res = OCIAttrSet(usrhp, OCI_HTYPE_SESSION, |
1256 | tgt_username, strlen(tgt_username), OCI_ATTR_USERNAME, errhp); |
1257 | if (res != OCI_SUCCESS) |
1258 | { |
1259 | DBUG_PRINT("info" ,("spider set username attr error" )); |
1260 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1261 | bg_disconnect(); |
1262 | goto error; |
1263 | } |
1264 | |
1265 | res = OCIAttrSet(usrhp, OCI_HTYPE_SESSION, |
1266 | tgt_password, strlen(tgt_password), OCI_ATTR_PASSWORD, errhp); |
1267 | if (res != OCI_SUCCESS) |
1268 | { |
1269 | DBUG_PRINT("info" ,("spider set password attr error" )); |
1270 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1271 | bg_disconnect(); |
1272 | goto error; |
1273 | } |
1274 | |
1275 | res = OCISessionBegin(svchp, errhp, usrhp, OCI_CRED_RDBMS, OCI_DEFAULT); |
1276 | if (res != OCI_SUCCESS) |
1277 | { |
1278 | DBUG_PRINT("info" ,("spider session begin error" )); |
1279 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1280 | bg_disconnect(); |
1281 | goto error; |
1282 | } |
1283 | DBUG_PRINT("info" ,("spider OCISessionBegin" )); |
1284 | |
1285 | // set the session in the context handle |
1286 | res = OCIAttrSet(svchp, OCI_HTYPE_SVCCTX, usrhp, 0, OCI_ATTR_SESSION, errhp); |
1287 | if (res != OCI_SUCCESS) |
1288 | { |
1289 | DBUG_PRINT("info" ,("spider set session attr error" )); |
1290 | stored_error_num = set_error(res, errhp, 0, NULL, NULL); |
1291 | bg_disconnect(); |
1292 | goto error; |
1293 | } |
1294 | |
1295 | if ( |
1296 | (stored_error_num = exec_query(SPIDER_SQL_SET_NLS_DATE_FORMAT_STR, |
1297 | SPIDER_SQL_SET_NLS_DATE_FORMAT_LEN, -1)) || |
1298 | (stored_error_num = exec_query(SPIDER_SQL_SET_NLS_TIME_FORMAT_STR, |
1299 | SPIDER_SQL_SET_NLS_TIME_FORMAT_LEN, -1)) || |
1300 | (stored_error_num = exec_query(SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_STR, |
1301 | SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_LEN, -1)) |
1302 | ) { |
1303 | DBUG_PRINT("info" ,("spider init connection error" )); |
1304 | bg_disconnect(); |
1305 | goto error; |
1306 | } |
1307 | DBUG_VOID_RETURN; |
1308 | |
1309 | error: |
1310 | strmov(stored_error_msg, spider_stmt_da_message(current_thd)); |
1311 | current_thd->clear_error(); |
1312 | DBUG_VOID_RETURN; |
1313 | } |
1314 | |
1315 | int spider_db_oracle::connect( |
1316 | char *tgt_host, |
1317 | char *tgt_username, |
1318 | char *tgt_password, |
1319 | long tgt_port, |
1320 | char *tgt_socket, |
1321 | char *server_name, |
1322 | int connect_retry_count, |
1323 | longlong connect_retry_interval |
1324 | ) { |
1325 | int error_num; |
1326 | DBUG_ENTER("spider_db_oracle::connect" ); |
1327 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1328 | this->tgt_host = tgt_host; |
1329 | this->tgt_username = tgt_username; |
1330 | this->tgt_password = tgt_password; |
1331 | this->tgt_port = tgt_port; |
1332 | this->tgt_socket = tgt_socket; |
1333 | this->server_name = server_name; |
1334 | this->connect_retry_count = connect_retry_count; |
1335 | this->connect_retry_interval = connect_retry_interval; |
1336 | if ((error_num = spider_create_conn_thread(conn))) |
1337 | DBUG_RETURN(error_num); |
1338 | spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_CONNECT, TRUE, NULL, |
1339 | 0, NULL); |
1340 | |
1341 | if (stored_error_num) |
1342 | { |
1343 | my_message(stored_error_num, stored_error_msg, MYF(0)); |
1344 | DBUG_RETURN(stored_error_num); |
1345 | } |
1346 | DBUG_RETURN(0); |
1347 | } |
1348 | |
1349 | int spider_db_oracle::ping( |
1350 | ) { |
1351 | sword res; |
1352 | DBUG_ENTER("spider_db_oracle::ping" ); |
1353 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1354 | res = OCIPing(svchp, errhp, OCI_DEFAULT); |
1355 | if (res != OCI_SUCCESS) |
1356 | { |
1357 | DBUG_PRINT("info" ,("spider ping error %d" , res)); |
1358 | DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); |
1359 | } |
1360 | DBUG_RETURN(0); |
1361 | } |
1362 | |
1363 | void spider_db_oracle::bg_disconnect() |
1364 | { |
1365 | DBUG_ENTER("spider_db_oracle::bg_disconnect" ); |
1366 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1367 | if (result) |
1368 | { |
1369 | delete result; |
1370 | result = NULL; |
1371 | } |
1372 | if (txnhp) |
1373 | { |
1374 | DBUG_PRINT("info" ,("spider OCI free txnhp=%p" , txnhp)); |
1375 | OCIHandleFree(txnhp, OCI_HTYPE_TRANS); |
1376 | txnhp = NULL; |
1377 | } |
1378 | if (stmtp) |
1379 | { |
1380 | DBUG_PRINT("info" ,("spider OCI free stmtp=%p" , stmtp)); |
1381 | OCIHandleFree(stmtp, OCI_HTYPE_STMT); |
1382 | stmtp = NULL; |
1383 | } |
1384 | if (svchp && errhp && usrhp) |
1385 | { |
1386 | DBUG_PRINT("info" ,("spider OCISessionEnd" )); |
1387 | OCISessionEnd(svchp, errhp, usrhp, OCI_DEFAULT); |
1388 | } |
1389 | if (usrhp) |
1390 | { |
1391 | DBUG_PRINT("info" ,("spider OCI free usrhp=%p" , usrhp)); |
1392 | OCIHandleFree(usrhp, OCI_HTYPE_SESSION); |
1393 | usrhp = NULL; |
1394 | } |
1395 | if (svchp) |
1396 | { |
1397 | DBUG_PRINT("info" ,("spider OCI free svchp=%p" , svchp)); |
1398 | OCIHandleFree(svchp, OCI_HTYPE_SVCCTX); |
1399 | svchp = NULL; |
1400 | } |
1401 | if (srvhp) |
1402 | { |
1403 | DBUG_PRINT("info" ,("spider OCI free srvhp=%p" , srvhp)); |
1404 | OCIServerDetach(srvhp, errhp, OCI_DEFAULT); |
1405 | OCIHandleFree(srvhp, OCI_HTYPE_SERVER); |
1406 | srvhp = NULL; |
1407 | } |
1408 | if (errhp) |
1409 | { |
1410 | DBUG_PRINT("info" ,("spider OCI free errhp=%p" , errhp)); |
1411 | OCIHandleFree(errhp, OCI_HTYPE_ERROR); |
1412 | errhp = NULL; |
1413 | } |
1414 | if (envhp) |
1415 | { |
1416 | DBUG_PRINT("info" ,("spider OCI free envhp=%p" , envhp)); |
1417 | OCIHandleFree(envhp, OCI_HTYPE_ENV); |
1418 | envhp = NULL; |
1419 | } |
1420 | DBUG_VOID_RETURN; |
1421 | } |
1422 | |
1423 | void spider_db_oracle::disconnect() |
1424 | { |
1425 | DBUG_ENTER("spider_db_oracle::disconnect" ); |
1426 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1427 | if (!conn->bg_init) |
1428 | DBUG_VOID_RETURN; |
1429 | spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_DISCONNECT, TRUE, NULL, |
1430 | 0, NULL); |
1431 | DBUG_VOID_RETURN; |
1432 | } |
1433 | |
1434 | int spider_db_oracle::set_net_timeout() |
1435 | { |
1436 | DBUG_ENTER("spider_db_oracle::set_net_timeout" ); |
1437 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1438 | /* TODO: develop later */ |
1439 | DBUG_RETURN(0); |
1440 | } |
1441 | |
1442 | int spider_db_oracle::exec_query( |
1443 | const char *query, |
1444 | uint length, |
1445 | int quick_mode |
1446 | ) { |
1447 | sword res; |
1448 | int error_num; |
1449 | DBUG_ENTER("spider_db_oracle::exec_query" ); |
1450 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1451 | if (spider_param_general_log()) |
1452 | { |
1453 | const char *tgt_str = conn->tgt_host; |
1454 | uint32 tgt_len = conn->tgt_host_length; |
1455 | spider_string tmp_query_str(length + conn->tgt_wrapper_length + |
1456 | tgt_len + (SPIDER_SQL_SPACE_LEN * 2)); |
1457 | tmp_query_str.init_calc_mem(232); |
1458 | tmp_query_str.length(0); |
1459 | tmp_query_str.q_append(conn->tgt_wrapper, conn->tgt_wrapper_length); |
1460 | tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
1461 | tmp_query_str.q_append(tgt_str, tgt_len); |
1462 | tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
1463 | tmp_query_str.q_append(query, length); |
1464 | general_log_write(current_thd, COM_QUERY, tmp_query_str.ptr(), |
1465 | tmp_query_str.length()); |
1466 | } |
1467 | stored_error_num = 0; |
1468 | if (table_lock_mode && !conn->in_before_query) |
1469 | { |
1470 | DBUG_PRINT("info" ,("spider table_lock_mode=%d" , table_lock_mode)); |
1471 | table_lock_mode = 0; |
1472 | if ((error_num = exec_query(exec_lock_sql->ptr(), exec_lock_sql->length(), |
1473 | -1))) { |
1474 | DBUG_RETURN(error_num); |
1475 | } |
1476 | } |
1477 | |
1478 | if (length) |
1479 | { |
1480 | if (result) |
1481 | { |
1482 | delete result; |
1483 | result = NULL; |
1484 | } |
1485 | |
1486 | if (!stmtp) |
1487 | { |
1488 | DBUG_PRINT("info" ,("spider create stmt" )); |
1489 | res = OCIHandleAlloc(envhp, (dvoid **) &stmtp, OCI_HTYPE_STMT, 0, 0); |
1490 | if (res != OCI_SUCCESS) |
1491 | { |
1492 | DBUG_PRINT("info" ,("spider create stmt handler error" )); |
1493 | DBUG_RETURN(set_error(res, errhp, 0, NULL, NULL)); |
1494 | } |
1495 | } |
1496 | |
1497 | res = OCIStmtPrepare(stmtp, errhp, (OraText *) query, length, |
1498 | OCI_NTV_SYNTAX, OCI_DEFAULT); |
1499 | if (res != OCI_SUCCESS) |
1500 | { |
1501 | DBUG_PRINT("info" ,("spider stmt prepare error" )); |
1502 | DBUG_RETURN(set_error(res, errhp, 0, NULL, NULL)); |
1503 | } |
1504 | |
1505 | /* |
1506 | if ((result = new spider_db_oracle_result())) |
1507 | { |
1508 | result->db_conn = this; |
1509 | result->stmtp = stmtp; |
1510 | stmtp = NULL; |
1511 | result->field_count = result->num_fields(); |
1512 | result->row.field_count = result->field_count; |
1513 | result->row.db_conn = this; |
1514 | result->row.result = result; |
1515 | if ((error_num = result->row.init())) |
1516 | { |
1517 | delete result; |
1518 | result = NULL; |
1519 | DBUG_RETURN(error_num); |
1520 | } |
1521 | } else { |
1522 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
1523 | } |
1524 | */ |
1525 | |
1526 | /* select statement check */ |
1527 | ub4 iters; |
1528 | if ( |
1529 | !strncasecmp(query, "select " , sizeof("select " ) - 1) || |
1530 | !strncasecmp(query, "(select " , sizeof("(select " ) - 1) |
1531 | ) { |
1532 | iters = 0; |
1533 | } else { |
1534 | iters = 1; |
1535 | } |
1536 | |
1537 | if (quick_mode) |
1538 | { |
1539 | DBUG_PRINT("info" ,("spider use OCI_DEFAULT" )); |
1540 | res = OCIStmtExecute(svchp, stmtp, errhp, iters, 0, NULL, NULL, |
1541 | OCI_DEFAULT); |
1542 | } else { |
1543 | DBUG_PRINT("info" ,("spider use OCI_STMT_SCROLLABLE_READONLY" )); |
1544 | res = OCIStmtExecute(svchp, stmtp, errhp, iters, 0, NULL, NULL, |
1545 | OCI_STMT_SCROLLABLE_READONLY); |
1546 | /* |
1547 | if (res == OCI_SUCCESS) |
1548 | { |
1549 | DBUG_PRINT("info",("spider fetch last for row count")); |
1550 | res = OCIStmtFetch2(result->stmtp, errhp, 1, OCI_FETCH_LAST, 0, |
1551 | OCI_DEFAULT); |
1552 | } |
1553 | if (res == OCI_SUCCESS) |
1554 | { |
1555 | DBUG_PRINT("info",("spider fetch first for row count")); |
1556 | res = OCIStmtFetch2(result->stmtp, errhp, 1, OCI_FETCH_FIRST, 0, |
1557 | OCI_DEFAULT); |
1558 | } |
1559 | */ |
1560 | } |
1561 | if (res == OCI_SUCCESS && iters) |
1562 | { |
1563 | DBUG_PRINT("info" ,("spider get row count" )); |
1564 | ub4 row_count; |
1565 | res = OCIAttrGet(stmtp, OCI_HTYPE_STMT, &row_count, 0, |
1566 | OCI_ATTR_ROW_COUNT, errhp); |
1567 | update_rows = (uint) row_count; |
1568 | DBUG_PRINT("info" ,("spider row_count=%u" , update_rows)); |
1569 | } |
1570 | if (res != OCI_SUCCESS) |
1571 | { |
1572 | DBUG_PRINT("info" ,("spider stmt execute error" )); |
1573 | error_num = set_error(res, errhp, 0, NULL, NULL); |
1574 | if (error_num == HA_ERR_END_OF_FILE) |
1575 | DBUG_RETURN(0); |
1576 | DBUG_RETURN(error_num); |
1577 | } |
1578 | |
1579 | if ((result = new spider_db_oracle_result(this))) |
1580 | { |
1581 | result->db_conn = this; |
1582 | result->stmtp = stmtp; |
1583 | stmtp = NULL; |
1584 | result->field_count = result->num_fields(); |
1585 | result->row.field_count = result->field_count; |
1586 | result->row.db_conn = this; |
1587 | result->row.result = result; |
1588 | result->row.access_charset = conn->access_charset; |
1589 | result->access_charset = conn->access_charset; |
1590 | if ( |
1591 | (error_num = result->row.init()) || |
1592 | (error_num = result->set_column_info()) |
1593 | ) { |
1594 | delete result; |
1595 | result = NULL; |
1596 | DBUG_RETURN(error_num); |
1597 | } |
1598 | result->row.define(); |
1599 | } else { |
1600 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
1601 | } |
1602 | |
1603 | if (!quick_mode && !iters) |
1604 | { |
1605 | if (res == OCI_SUCCESS) |
1606 | { |
1607 | DBUG_PRINT("info" ,("spider fetch last for row count" )); |
1608 | res = OCIStmtFetch2(result->stmtp, errhp, 1, OCI_FETCH_LAST, 0, |
1609 | OCI_DEFAULT); |
1610 | } |
1611 | if (res == OCI_SUCCESS) |
1612 | { |
1613 | DBUG_PRINT("info" ,("spider fetch first for row count" )); |
1614 | res = OCIStmtFetch2(result->stmtp, errhp, 1, OCI_FETCH_FIRST, 0, |
1615 | OCI_DEFAULT); |
1616 | } |
1617 | if (res != OCI_SUCCESS) |
1618 | { |
1619 | DBUG_PRINT("info" ,("spider stmt execute error" )); |
1620 | error_num = set_error(res, errhp, 0, NULL, NULL); |
1621 | if (error_num == HA_ERR_END_OF_FILE) |
1622 | DBUG_RETURN(0); |
1623 | DBUG_RETURN(error_num); |
1624 | } |
1625 | result->fetched = TRUE; |
1626 | } |
1627 | } |
1628 | DBUG_RETURN(0); |
1629 | } |
1630 | |
1631 | int spider_db_oracle::get_errno() |
1632 | { |
1633 | DBUG_ENTER("spider_db_oracle::get_errno" ); |
1634 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1635 | DBUG_PRINT("info" ,("spider stored_error=%d" , stored_error_num)); |
1636 | DBUG_RETURN(stored_error_num); |
1637 | } |
1638 | |
1639 | const char *spider_db_oracle::get_error() |
1640 | { |
1641 | DBUG_ENTER("spider_db_oracle::get_error" ); |
1642 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1643 | DBUG_PRINT("info" ,("spider error=%s" , stored_error)); |
1644 | DBUG_RETURN(stored_error); |
1645 | } |
1646 | |
1647 | bool spider_db_oracle::is_server_gone_error( |
1648 | int error_num |
1649 | ) { |
1650 | DBUG_ENTER("spider_db_oracle::is_server_gone_error" ); |
1651 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1652 | /* TODO: develop later */ |
1653 | DBUG_RETURN(FALSE); |
1654 | } |
1655 | |
1656 | bool spider_db_oracle::is_dup_entry_error( |
1657 | int error_num |
1658 | ) { |
1659 | DBUG_ENTER("spider_db_oracle::is_dup_entry_error" ); |
1660 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1661 | if (error_num == HA_ERR_FOUND_DUPP_KEY) |
1662 | DBUG_RETURN(TRUE); |
1663 | DBUG_RETURN(FALSE); |
1664 | } |
1665 | |
1666 | bool spider_db_oracle::is_xa_nota_error( |
1667 | int error_num |
1668 | ) { |
1669 | DBUG_ENTER("spider_db_oracle::is_xa_nota_error" ); |
1670 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1671 | /* TODO: develop later */ |
1672 | DBUG_RETURN(FALSE); |
1673 | } |
1674 | |
1675 | spider_db_result *spider_db_oracle::store_result( |
1676 | spider_db_result_buffer **spider_res_buf, |
1677 | st_spider_db_request_key *request_key, |
1678 | int *error_num |
1679 | ) { |
1680 | spider_db_oracle_result *tmp_result = result; |
1681 | DBUG_ENTER("spider_db_oracle::store_result" ); |
1682 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1683 | DBUG_ASSERT(!spider_res_buf); |
1684 | if (stored_error_num == HA_ERR_END_OF_FILE) |
1685 | { |
1686 | *error_num = HA_ERR_END_OF_FILE; |
1687 | DBUG_RETURN(NULL); |
1688 | } |
1689 | |
1690 | *error_num = 0; |
1691 | result = NULL; |
1692 | DBUG_RETURN(tmp_result); |
1693 | } |
1694 | |
1695 | spider_db_result *spider_db_oracle::use_result( |
1696 | st_spider_db_request_key *request_key, |
1697 | int *error_num |
1698 | ) { |
1699 | spider_db_oracle_result *tmp_result = result; |
1700 | DBUG_ENTER("spider_db_oracle::use_result" ); |
1701 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1702 | if (stored_error_num == HA_ERR_END_OF_FILE) |
1703 | { |
1704 | *error_num = HA_ERR_END_OF_FILE; |
1705 | DBUG_RETURN(NULL); |
1706 | } |
1707 | |
1708 | *error_num = 0; |
1709 | result = NULL; |
1710 | DBUG_RETURN(tmp_result); |
1711 | } |
1712 | |
1713 | int spider_db_oracle::next_result() |
1714 | { |
1715 | DBUG_ENTER("spider_db_oracle::next_result" ); |
1716 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1717 | /* TODO: develop later */ |
1718 | DBUG_RETURN(-1); |
1719 | } |
1720 | |
1721 | uint spider_db_oracle::affected_rows() |
1722 | { |
1723 | DBUG_ENTER("spider_db_oracle::affected_rows" ); |
1724 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1725 | DBUG_RETURN(update_rows); |
1726 | } |
1727 | |
1728 | ulonglong spider_db_oracle::last_insert_id() |
1729 | { |
1730 | DBUG_ENTER("spider_db_oracle::last_insert_id" ); |
1731 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1732 | DBUG_RETURN(stored_last_insert_id); |
1733 | } |
1734 | |
1735 | int spider_db_oracle::set_character_set( |
1736 | const char *csname |
1737 | ) { |
1738 | DBUG_ENTER("spider_db_oracle::set_character_set" ); |
1739 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1740 | /* TODO: develop later */ |
1741 | DBUG_RETURN(0); |
1742 | } |
1743 | |
1744 | int spider_db_oracle::select_db( |
1745 | const char *dbname |
1746 | ) { |
1747 | DBUG_ENTER("spider_db_oracle::select_db" ); |
1748 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1749 | /* nothing to do for oracle */ |
1750 | DBUG_RETURN(0); |
1751 | } |
1752 | |
1753 | int spider_db_oracle::consistent_snapshot( |
1754 | int *need_mon |
1755 | ) { |
1756 | DBUG_ENTER("spider_db_oracle::consistent_snapshot" ); |
1757 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1758 | /* nothing to do for oracle */ |
1759 | DBUG_RETURN(0); |
1760 | } |
1761 | |
1762 | bool spider_db_oracle::trx_start_in_bulk_sql() |
1763 | { |
1764 | DBUG_ENTER("spider_db_oracle::trx_start_in_bulk_sql" ); |
1765 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1766 | DBUG_RETURN(FALSE); |
1767 | } |
1768 | |
1769 | int spider_db_oracle::start_transaction( |
1770 | int *need_mon |
1771 | ) { |
1772 | DBUG_ENTER("spider_db_oracle::start_transaction" ); |
1773 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1774 | if (conn->in_before_query) |
1775 | { |
1776 | if (conn->queued_semi_trx_isolation) |
1777 | { |
1778 | if (conn->queued_semi_trx_isolation_val != conn->trx_isolation) |
1779 | { |
1780 | /* nothing to do */ |
1781 | DBUG_RETURN(0); |
1782 | } |
1783 | } else if (conn->queued_trx_isolation) |
1784 | { |
1785 | if (conn->queued_trx_isolation_val != conn->trx_isolation) |
1786 | { |
1787 | /* nothing to do */ |
1788 | DBUG_RETURN(0); |
1789 | } |
1790 | } |
1791 | DBUG_RETURN(set_trx_isolation(conn->trx_isolation, need_mon)); |
1792 | } |
1793 | if (spider_db_query( |
1794 | conn, |
1795 | SPIDER_SQL_START_TRANSACTION_STR, |
1796 | SPIDER_SQL_START_TRANSACTION_LEN, |
1797 | -1, |
1798 | need_mon) |
1799 | ) |
1800 | DBUG_RETURN(spider_db_errorno(conn)); |
1801 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
1802 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
1803 | DBUG_RETURN(0); |
1804 | } |
1805 | |
1806 | int spider_db_oracle::commit( |
1807 | int *need_mon |
1808 | ) { |
1809 | sword res; |
1810 | DBUG_ENTER("spider_db_oracle::commit" ); |
1811 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1812 | if (conn->table_locked) |
1813 | { |
1814 | conn->table_locked = FALSE; |
1815 | spider_current_trx->locked_connections--; |
1816 | } |
1817 | res = OCITransCommit(svchp, errhp, OCI_DEFAULT); |
1818 | if (res != OCI_SUCCESS) |
1819 | { |
1820 | *need_mon = set_error(res, errhp, 0, NULL, NULL); |
1821 | DBUG_RETURN(*need_mon); |
1822 | } |
1823 | DBUG_RETURN(0); |
1824 | } |
1825 | |
1826 | int spider_db_oracle::rollback( |
1827 | int *need_mon |
1828 | ) { |
1829 | sword res; |
1830 | DBUG_ENTER("spider_db_oracle::rollback" ); |
1831 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1832 | if (conn->table_locked) |
1833 | { |
1834 | conn->table_locked = FALSE; |
1835 | spider_current_trx->locked_connections--; |
1836 | } |
1837 | if (svchp && errhp) |
1838 | { |
1839 | res = OCITransRollback(svchp, errhp, OCI_DEFAULT); |
1840 | if (res != OCI_SUCCESS) |
1841 | { |
1842 | *need_mon = set_error(res, errhp, 0, NULL, NULL); |
1843 | DBUG_RETURN(*need_mon); |
1844 | } |
1845 | } |
1846 | DBUG_RETURN(0); |
1847 | } |
1848 | |
1849 | bool spider_db_oracle::xa_start_in_bulk_sql() |
1850 | { |
1851 | DBUG_ENTER("spider_db_oracle::xa_start_in_bulk_sql" ); |
1852 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1853 | DBUG_RETURN(FALSE); |
1854 | } |
1855 | |
1856 | int spider_db_oracle::xa_start( |
1857 | XID *xid, |
1858 | int *need_mon |
1859 | ) { |
1860 | sword res; |
1861 | DBUG_ENTER("spider_db_oracle::xa_start" ); |
1862 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1863 | if (txnhp) |
1864 | { |
1865 | OCIHandleFree(txnhp, OCI_HTYPE_TRANS); |
1866 | txnhp = NULL; |
1867 | } |
1868 | OCIHandleAlloc((dvoid *)envhp, (dvoid **)&txnhp, OCI_HTYPE_TRANS, 0, 0); |
1869 | OCIAttrSet((dvoid *)svchp, OCI_HTYPE_SVCCTX, (dvoid *)txnhp, 0, |
1870 | OCI_ATTR_TRANS, errhp); |
1871 | OCIAttrSet((dvoid *)txnhp, OCI_HTYPE_TRANS, (dvoid *)xid, sizeof(XID), |
1872 | OCI_ATTR_XID, errhp); |
1873 | |
1874 | res = OCITransStart(svchp, errhp, 31622400, OCI_TRANS_NEW); |
1875 | if (res != OCI_SUCCESS) |
1876 | { |
1877 | *need_mon = set_error(res, errhp, 0, NULL, NULL); |
1878 | DBUG_RETURN(*need_mon); |
1879 | } |
1880 | DBUG_RETURN(0); |
1881 | } |
1882 | |
1883 | int spider_db_oracle::xa_end( |
1884 | XID *xid, |
1885 | int *need_mon |
1886 | ) { |
1887 | DBUG_ENTER("spider_db_oracle::xa_end" ); |
1888 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1889 | /* nothing to do for oracle */ |
1890 | DBUG_RETURN(0); |
1891 | } |
1892 | |
1893 | int spider_db_oracle::xa_prepare( |
1894 | XID *xid, |
1895 | int *need_mon |
1896 | ) { |
1897 | sword res; |
1898 | DBUG_ENTER("spider_db_oracle::xa_prepare" ); |
1899 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1900 | res = OCITransPrepare(svchp, errhp, OCI_DEFAULT); |
1901 | if (res != OCI_SUCCESS) |
1902 | { |
1903 | *need_mon = set_error(res, errhp, 0, NULL, NULL); |
1904 | DBUG_RETURN(*need_mon); |
1905 | } |
1906 | DBUG_RETURN(0); |
1907 | } |
1908 | |
1909 | int spider_db_oracle::xa_commit( |
1910 | XID *xid, |
1911 | int *need_mon |
1912 | ) { |
1913 | sword res; |
1914 | DBUG_ENTER("spider_db_oracle::xa_commit" ); |
1915 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1916 | if (conn->table_locked) |
1917 | { |
1918 | conn->table_locked = FALSE; |
1919 | spider_current_trx->locked_connections--; |
1920 | } |
1921 | res = OCITransCommit(svchp, errhp, OCI_TRANS_TWOPHASE); |
1922 | if (res != OCI_SUCCESS) |
1923 | { |
1924 | *need_mon = set_error(res, errhp, 0, NULL, NULL); |
1925 | if (txnhp) |
1926 | { |
1927 | OCIHandleFree(txnhp, OCI_HTYPE_TRANS); |
1928 | txnhp = NULL; |
1929 | } |
1930 | DBUG_RETURN(*need_mon); |
1931 | } |
1932 | if (txnhp) |
1933 | { |
1934 | OCIHandleFree(txnhp, OCI_HTYPE_TRANS); |
1935 | txnhp = NULL; |
1936 | } |
1937 | DBUG_RETURN(0); |
1938 | } |
1939 | |
1940 | int spider_db_oracle::xa_rollback( |
1941 | XID *xid, |
1942 | int *need_mon |
1943 | ) { |
1944 | sword res; |
1945 | DBUG_ENTER("spider_db_oracle::xa_rollback" ); |
1946 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1947 | if (svchp && errhp) |
1948 | { |
1949 | res = OCITransRollback(svchp, errhp, OCI_DEFAULT); |
1950 | if (res != OCI_SUCCESS) |
1951 | { |
1952 | *need_mon = set_error(res, errhp, 0, NULL, NULL); |
1953 | if (txnhp) |
1954 | { |
1955 | OCIHandleFree(txnhp, OCI_HTYPE_TRANS); |
1956 | txnhp = NULL; |
1957 | } |
1958 | DBUG_RETURN(*need_mon); |
1959 | } |
1960 | } |
1961 | if (txnhp) |
1962 | { |
1963 | OCIHandleFree(txnhp, OCI_HTYPE_TRANS); |
1964 | txnhp = NULL; |
1965 | } |
1966 | DBUG_RETURN(0); |
1967 | } |
1968 | |
1969 | bool spider_db_oracle::set_trx_isolation_in_bulk_sql() |
1970 | { |
1971 | DBUG_ENTER("spider_db_oracle::set_trx_isolation_in_bulk_sql" ); |
1972 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1973 | DBUG_RETURN(FALSE); |
1974 | } |
1975 | |
1976 | int spider_db_oracle::set_trx_isolation( |
1977 | int trx_isolation, |
1978 | int *need_mon |
1979 | ) { |
1980 | DBUG_ENTER("spider_db_oracle::set_trx_isolation" ); |
1981 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1982 | switch (trx_isolation) |
1983 | { |
1984 | case ISO_READ_UNCOMMITTED: |
1985 | case ISO_READ_COMMITTED: |
1986 | if (conn->in_before_query) |
1987 | { |
1988 | DBUG_RETURN(exec_query(SPIDER_SQL_ISO_READ_COMMITTED_STR, |
1989 | SPIDER_SQL_ISO_READ_COMMITTED_LEN, -1)); |
1990 | } |
1991 | if (spider_db_query( |
1992 | conn, |
1993 | SPIDER_SQL_ISO_READ_COMMITTED_STR, |
1994 | SPIDER_SQL_ISO_READ_COMMITTED_LEN, |
1995 | -1, |
1996 | need_mon) |
1997 | ) |
1998 | DBUG_RETURN(spider_db_errorno(conn)); |
1999 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
2000 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
2001 | break; |
2002 | case ISO_REPEATABLE_READ: |
2003 | case ISO_SERIALIZABLE: |
2004 | if (conn->in_before_query) |
2005 | { |
2006 | DBUG_RETURN(exec_query(SPIDER_SQL_ISO_SERIALIZABLE_STR, |
2007 | SPIDER_SQL_ISO_SERIALIZABLE_LEN, -1)); |
2008 | } |
2009 | if (spider_db_query( |
2010 | conn, |
2011 | SPIDER_SQL_ISO_SERIALIZABLE_STR, |
2012 | SPIDER_SQL_ISO_SERIALIZABLE_LEN, |
2013 | -1, |
2014 | need_mon) |
2015 | ) |
2016 | DBUG_RETURN(spider_db_errorno(conn)); |
2017 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
2018 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
2019 | break; |
2020 | default: |
2021 | DBUG_RETURN(HA_ERR_UNSUPPORTED); |
2022 | } |
2023 | DBUG_RETURN(0); |
2024 | } |
2025 | |
2026 | bool spider_db_oracle::set_autocommit_in_bulk_sql() |
2027 | { |
2028 | DBUG_ENTER("spider_db_oracle::set_autocommit_in_bulk_sql" ); |
2029 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2030 | DBUG_RETURN(FALSE); |
2031 | } |
2032 | |
2033 | int spider_db_oracle::set_autocommit( |
2034 | bool autocommit, |
2035 | int *need_mon |
2036 | ) { |
2037 | DBUG_ENTER("spider_db_oracle::set_autocommit" ); |
2038 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2039 | if (autocommit) |
2040 | { |
2041 | if (conn->in_before_query) |
2042 | { |
2043 | DBUG_RETURN(exec_query(SPIDER_SQL_AUTOCOMMIT_ON_STR, |
2044 | SPIDER_SQL_AUTOCOMMIT_ON_LEN, -1)); |
2045 | } |
2046 | if (spider_db_query( |
2047 | conn, |
2048 | SPIDER_SQL_AUTOCOMMIT_ON_STR, |
2049 | SPIDER_SQL_AUTOCOMMIT_ON_LEN, |
2050 | -1, |
2051 | need_mon) |
2052 | ) |
2053 | DBUG_RETURN(spider_db_errorno(conn)); |
2054 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
2055 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
2056 | } else { |
2057 | if (conn->in_before_query) |
2058 | { |
2059 | DBUG_RETURN(exec_query(SPIDER_SQL_AUTOCOMMIT_OFF_STR, |
2060 | SPIDER_SQL_AUTOCOMMIT_OFF_LEN, -1)); |
2061 | } |
2062 | if (spider_db_query( |
2063 | conn, |
2064 | SPIDER_SQL_AUTOCOMMIT_OFF_STR, |
2065 | SPIDER_SQL_AUTOCOMMIT_OFF_LEN, |
2066 | -1, |
2067 | need_mon) |
2068 | ) |
2069 | DBUG_RETURN(spider_db_errorno(conn)); |
2070 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
2071 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
2072 | } |
2073 | DBUG_RETURN(0); |
2074 | } |
2075 | |
2076 | bool spider_db_oracle::set_sql_log_off_in_bulk_sql() |
2077 | { |
2078 | DBUG_ENTER("spider_db_oracle::set_sql_log_off_in_bulk_sql" ); |
2079 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2080 | DBUG_RETURN(FALSE); |
2081 | } |
2082 | |
2083 | int spider_db_oracle::set_sql_log_off( |
2084 | bool sql_log_off, |
2085 | int *need_mon |
2086 | ) { |
2087 | DBUG_ENTER("spider_db_oracle::set_sql_log_off" ); |
2088 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2089 | /* nothing to do */ |
2090 | DBUG_RETURN(0); |
2091 | } |
2092 | |
2093 | bool spider_db_oracle::set_time_zone_in_bulk_sql() |
2094 | { |
2095 | DBUG_ENTER("spider_db_oracle::set_time_zone_in_bulk_sql" ); |
2096 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2097 | DBUG_RETURN(FALSE); |
2098 | } |
2099 | |
2100 | int spider_db_oracle::set_time_zone( |
2101 | Time_zone *time_zone, |
2102 | int *need_mon |
2103 | ) { |
2104 | DBUG_ENTER("spider_db_oracle::set_time_zone" ); |
2105 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2106 | /* nothing to do */ |
2107 | DBUG_RETURN(0); |
2108 | } |
2109 | |
2110 | int spider_db_oracle::show_master_status( |
2111 | SPIDER_TRX *trx, |
2112 | SPIDER_SHARE *share, |
2113 | int all_link_idx, |
2114 | int *need_mon, |
2115 | TABLE *table, |
2116 | spider_string *str, |
2117 | int mode, |
2118 | SPIDER_DB_RESULT **res1, |
2119 | SPIDER_DB_RESULT **res2 |
2120 | ) { |
2121 | DBUG_ENTER("spider_db_oracle::show_master_status" ); |
2122 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2123 | DBUG_RETURN(0); |
2124 | } |
2125 | |
2126 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
2127 | int spider_db_oracle::append_sql( |
2128 | char *sql, |
2129 | ulong sql_length, |
2130 | st_spider_db_request_key *request_key |
2131 | ) { |
2132 | DBUG_ENTER("spider_db_oracle::append_sql" ); |
2133 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2134 | DBUG_ASSERT(0); |
2135 | DBUG_RETURN(0); |
2136 | } |
2137 | |
2138 | int spider_db_oracle::append_open_handler( |
2139 | uint handler_id, |
2140 | const char *db_name, |
2141 | const char *table_name, |
2142 | const char *index_name, |
2143 | const char *sql, |
2144 | st_spider_db_request_key *request_key |
2145 | ) { |
2146 | DBUG_ENTER("spider_db_oracle::append_sql" ); |
2147 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2148 | DBUG_ASSERT(0); |
2149 | DBUG_RETURN(0); |
2150 | } |
2151 | |
2152 | int spider_db_oracle::append_select( |
2153 | uint handler_id, |
2154 | spider_string *sql, |
2155 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
2156 | int limit, |
2157 | int skip, |
2158 | st_spider_db_request_key *request_key |
2159 | ) { |
2160 | DBUG_ENTER("spider_db_oracle::append_select" ); |
2161 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2162 | DBUG_ASSERT(0); |
2163 | DBUG_RETURN(0); |
2164 | } |
2165 | |
2166 | int spider_db_oracle::append_insert( |
2167 | uint handler_id, |
2168 | SPIDER_DB_HS_STRING_REF_BUFFER *upds, |
2169 | st_spider_db_request_key *request_key |
2170 | ) { |
2171 | DBUG_ENTER("spider_db_oracle::append_insert" ); |
2172 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2173 | DBUG_ASSERT(0); |
2174 | DBUG_RETURN(0); |
2175 | } |
2176 | |
2177 | int spider_db_oracle::append_update( |
2178 | uint handler_id, |
2179 | spider_string *sql, |
2180 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
2181 | SPIDER_DB_HS_STRING_REF_BUFFER *upds, |
2182 | int limit, |
2183 | int skip, |
2184 | bool increment, |
2185 | bool decrement, |
2186 | st_spider_db_request_key *request_key |
2187 | ) { |
2188 | DBUG_ENTER("spider_db_oracle::append_update" ); |
2189 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2190 | DBUG_ASSERT(0); |
2191 | DBUG_RETURN(0); |
2192 | } |
2193 | |
2194 | int spider_db_oracle::append_delete( |
2195 | uint handler_id, |
2196 | spider_string *sql, |
2197 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
2198 | int limit, |
2199 | int skip, |
2200 | st_spider_db_request_key *request_key |
2201 | ) { |
2202 | DBUG_ENTER("spider_db_oracle::append_delete" ); |
2203 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2204 | DBUG_ASSERT(0); |
2205 | DBUG_RETURN(0); |
2206 | } |
2207 | |
2208 | void spider_db_oracle::reset_request_queue() |
2209 | { |
2210 | DBUG_ENTER("spider_db_oracle::reset_request_queue" ); |
2211 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2212 | DBUG_ASSERT(0); |
2213 | DBUG_VOID_RETURN; |
2214 | } |
2215 | #endif |
2216 | |
2217 | size_t spider_db_oracle::escape_string( |
2218 | char *to, |
2219 | const char *from, |
2220 | size_t from_length |
2221 | ) { |
2222 | DBUG_ENTER("spider_db_oracle::escape_string" ); |
2223 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2224 | DBUG_RETURN(util.escape_string(to, from, from_length, conn->access_charset)); |
2225 | } |
2226 | |
2227 | bool spider_db_oracle::have_lock_table_list() |
2228 | { |
2229 | DBUG_ENTER("spider_db_oracle::have_lock_table_list" ); |
2230 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2231 | DBUG_RETURN(lock_table_hash.records); |
2232 | } |
2233 | |
2234 | int spider_db_oracle::append_lock_tables( |
2235 | spider_string *str |
2236 | ) { |
2237 | int error_num; |
2238 | ha_spider *tmp_spider; |
2239 | int lock_type; |
2240 | uint conn_link_idx; |
2241 | int tmp_link_idx; |
2242 | SPIDER_LINK_FOR_HASH *tmp_link_for_hash; |
2243 | const char *db_name; |
2244 | uint db_name_length; |
2245 | CHARSET_INFO *db_name_charset; |
2246 | const char *table_name; |
2247 | uint table_name_length; |
2248 | CHARSET_INFO *table_name_charset; |
2249 | DBUG_ENTER("spider_db_oracle::lock_tables" ); |
2250 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2251 | if ((tmp_link_for_hash = |
2252 | (SPIDER_LINK_FOR_HASH *) my_hash_element(&lock_table_hash, 0))) |
2253 | { |
2254 | if ((error_num = spider_db_oracle_utility.append_lock_table_head(str))) |
2255 | { |
2256 | DBUG_RETURN(error_num); |
2257 | } |
2258 | |
2259 | tmp_spider = tmp_link_for_hash->spider; |
2260 | tmp_link_idx = tmp_link_for_hash->link_idx; |
2261 | switch (tmp_spider->lock_type) |
2262 | { |
2263 | case TL_READ: |
2264 | lock_type = SPIDER_DB_TABLE_LOCK_READ_LOCAL; |
2265 | break; |
2266 | case TL_READ_NO_INSERT: |
2267 | lock_type = SPIDER_DB_TABLE_LOCK_READ; |
2268 | break; |
2269 | case TL_WRITE_LOW_PRIORITY: |
2270 | lock_type = SPIDER_DB_TABLE_LOCK_LOW_PRIORITY_WRITE; |
2271 | break; |
2272 | case TL_WRITE: |
2273 | lock_type = SPIDER_DB_TABLE_LOCK_WRITE; |
2274 | break; |
2275 | default: |
2276 | // no lock |
2277 | DBUG_PRINT("info" ,("spider lock_type=%d" , tmp_spider->lock_type)); |
2278 | DBUG_RETURN(0); |
2279 | } |
2280 | conn_link_idx = tmp_spider->conn_link_idx[tmp_link_idx]; |
2281 | spider_oracle_share *db_share = (spider_oracle_share *) |
2282 | tmp_spider->share->dbton_share[conn->dbton_id]; |
2283 | if (&db_share->db_names_str[conn_link_idx]) |
2284 | { |
2285 | db_name = db_share->db_names_str[conn_link_idx].ptr(); |
2286 | db_name_length = db_share->db_names_str[conn_link_idx].length(); |
2287 | db_name_charset = tmp_spider->share->access_charset; |
2288 | } else { |
2289 | db_name = tmp_spider->share->tgt_dbs[conn_link_idx]; |
2290 | db_name_length = tmp_spider->share->tgt_dbs_lengths[conn_link_idx]; |
2291 | db_name_charset = system_charset_info; |
2292 | } |
2293 | if (&db_share->table_names_str[conn_link_idx]) |
2294 | { |
2295 | table_name = db_share->table_names_str[conn_link_idx].ptr(); |
2296 | table_name_length = db_share->table_names_str[conn_link_idx].length(); |
2297 | table_name_charset = tmp_spider->share->access_charset; |
2298 | } else { |
2299 | table_name = tmp_spider->share->tgt_table_names[conn_link_idx]; |
2300 | table_name_length = |
2301 | tmp_spider->share->tgt_table_names_lengths[conn_link_idx]; |
2302 | table_name_charset = system_charset_info; |
2303 | } |
2304 | if ((error_num = spider_db_oracle_utility. |
2305 | append_lock_table_body( |
2306 | str, |
2307 | db_name, |
2308 | db_name_length, |
2309 | db_name_charset, |
2310 | table_name, |
2311 | table_name_length, |
2312 | table_name_charset, |
2313 | lock_type |
2314 | ) |
2315 | )) { |
2316 | my_hash_reset(&lock_table_hash); |
2317 | DBUG_RETURN(error_num); |
2318 | } |
2319 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
2320 | my_hash_delete_with_hash_value(&lock_table_hash, |
2321 | tmp_link_for_hash->db_table_str_hash_value, (uchar*) tmp_link_for_hash); |
2322 | #else |
2323 | my_hash_delete(&lock_table_hash, (uchar*) tmp_link_for_hash); |
2324 | #endif |
2325 | |
2326 | if ((error_num = spider_db_oracle_utility.append_lock_table_tail(str))) |
2327 | { |
2328 | DBUG_RETURN(error_num); |
2329 | } |
2330 | } |
2331 | DBUG_RETURN(0); |
2332 | } |
2333 | |
2334 | int spider_db_oracle::append_unlock_tables( |
2335 | spider_string *str |
2336 | ) { |
2337 | int error_num; |
2338 | DBUG_ENTER("spider_db_oracle::append_unlock_tables" ); |
2339 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2340 | if ((error_num = spider_db_oracle_utility.append_unlock_table(str))) |
2341 | { |
2342 | DBUG_RETURN(error_num); |
2343 | } |
2344 | DBUG_RETURN(0); |
2345 | } |
2346 | |
2347 | uint spider_db_oracle::get_lock_table_hash_count() |
2348 | { |
2349 | DBUG_ENTER("spider_db_oracle::get_lock_table_hash_count" ); |
2350 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2351 | DBUG_RETURN(lock_table_hash.records); |
2352 | } |
2353 | |
2354 | void spider_db_oracle::reset_lock_table_hash() |
2355 | { |
2356 | DBUG_ENTER("spider_db_oracle::reset_lock_table_hash" ); |
2357 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2358 | my_hash_reset(&lock_table_hash); |
2359 | DBUG_VOID_RETURN; |
2360 | } |
2361 | |
2362 | uint spider_db_oracle::get_opened_handler_count() |
2363 | { |
2364 | DBUG_ENTER("spider_db_oracle::get_opened_handler_count" ); |
2365 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2366 | DBUG_RETURN(handler_open_array.elements); |
2367 | } |
2368 | |
2369 | void spider_db_oracle::reset_opened_handler() |
2370 | { |
2371 | ha_spider *tmp_spider; |
2372 | int tmp_link_idx; |
2373 | SPIDER_LINK_FOR_HASH **tmp_link_for_hash; |
2374 | DBUG_ENTER("spider_db_oracle::reset_opened_handler" ); |
2375 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2376 | while ((tmp_link_for_hash = |
2377 | (SPIDER_LINK_FOR_HASH **) pop_dynamic(&handler_open_array))) |
2378 | { |
2379 | tmp_spider = (*tmp_link_for_hash)->spider; |
2380 | tmp_link_idx = (*tmp_link_for_hash)->link_idx; |
2381 | tmp_spider->clear_handler_opened(tmp_link_idx, conn->conn_kind); |
2382 | } |
2383 | DBUG_VOID_RETURN; |
2384 | } |
2385 | |
2386 | void spider_db_oracle::set_dup_key_idx( |
2387 | ha_spider *spider, |
2388 | int link_idx |
2389 | ) { |
2390 | TABLE *table = spider->get_table(); |
2391 | uint roop_count, pk_idx = table->s->primary_key; |
2392 | int key_name_length; |
2393 | int max_length = 0; |
2394 | char *key_name, *tmp_pos; |
2395 | char buf[SPIDER_ORACLE_ERR_BUF_LEN]; |
2396 | DBUG_ENTER("spider_db_oracle::set_dup_key_idx" ); |
2397 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2398 | DBUG_PRINT("info" ,("spider error_str=%s" , stored_error_msg)); |
2399 | memcpy(buf, spider->share->tgt_dbs[link_idx], |
2400 | spider->share->tgt_dbs_lengths[link_idx]); |
2401 | tmp_pos = buf + spider->share->tgt_dbs_lengths[link_idx]; |
2402 | *tmp_pos = '.'; |
2403 | ++tmp_pos; |
2404 | for (roop_count = 0; roop_count < table->s->keys; roop_count++) |
2405 | { |
2406 | if (roop_count == pk_idx) |
2407 | { |
2408 | DBUG_PRINT("info" ,("spider pk_idx=%u" , roop_count)); |
2409 | int all_link_idx = spider->conn_link_idx[link_idx]; |
2410 | key_name = spider->share->tgt_pk_names[all_link_idx]; |
2411 | key_name_length = spider->share->tgt_pk_names_lengths[all_link_idx]; |
2412 | } else { |
2413 | key_name = table->s->key_info[roop_count].name; |
2414 | key_name_length = strlen(key_name); |
2415 | } |
2416 | memcpy(tmp_pos, key_name, key_name_length + 1); |
2417 | DBUG_PRINT("info" ,("spider key_name=%s" , key_name)); |
2418 | DBUG_PRINT("info" ,("spider full key name=%s" , buf)); |
2419 | if ( |
2420 | max_length < key_name_length && |
2421 | strcasestr(stored_error_msg, buf) |
2422 | ) { |
2423 | max_length = key_name_length; |
2424 | spider->dup_key_idx = roop_count; |
2425 | } |
2426 | } |
2427 | if (max_length == 0) |
2428 | spider->dup_key_idx = (uint) -1; |
2429 | DBUG_PRINT("info" ,("spider dup_key_idx=%d" , spider->dup_key_idx)); |
2430 | DBUG_VOID_RETURN; |
2431 | } |
2432 | |
2433 | bool spider_db_oracle::cmp_request_key_to_snd( |
2434 | st_spider_db_request_key *request_key |
2435 | ) { |
2436 | DBUG_ENTER("spider_db_oracle::cmp_request_key_to_snd" ); |
2437 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2438 | DBUG_RETURN(TRUE); |
2439 | } |
2440 | |
2441 | int spider_db_oracle::set_error( |
2442 | sword res, |
2443 | dvoid *hndlp, |
2444 | int error_num, |
2445 | const char *error1, |
2446 | const char *error2 |
2447 | ) { |
2448 | DBUG_ENTER("spider_db_oracle::set_error" ); |
2449 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2450 | stored_error_num = |
2451 | spider_db_oracle_get_error(res, hndlp, error_num, error1, error2, |
2452 | conn->access_charset, stored_error_msg); |
2453 | if (stored_error_num) |
2454 | stored_error = ER_SPIDER_ORACLE_ERR; |
2455 | else |
2456 | stored_error = "" ; |
2457 | DBUG_RETURN(stored_error_num); |
2458 | } |
2459 | |
2460 | spider_db_oracle_util::spider_db_oracle_util() : spider_db_util() |
2461 | { |
2462 | DBUG_ENTER("spider_db_oracle_util::spider_db_oracle_util" ); |
2463 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2464 | DBUG_VOID_RETURN; |
2465 | } |
2466 | |
2467 | spider_db_oracle_util::~spider_db_oracle_util() |
2468 | { |
2469 | DBUG_ENTER("spider_db_oracle_util::~spider_db_oracle_util" ); |
2470 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2471 | DBUG_VOID_RETURN; |
2472 | } |
2473 | |
2474 | int spider_db_oracle_util::append_name( |
2475 | spider_string *str, |
2476 | const char *name, |
2477 | uint name_length |
2478 | ) { |
2479 | DBUG_ENTER("spider_db_oracle_util::append_name" ); |
2480 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2481 | str->q_append(name, name_length); |
2482 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2483 | DBUG_RETURN(0); |
2484 | } |
2485 | |
2486 | int spider_db_oracle_util::append_name_with_charset( |
2487 | spider_string *str, |
2488 | const char *name, |
2489 | uint name_length, |
2490 | CHARSET_INFO *name_charset |
2491 | ) { |
2492 | DBUG_ENTER("spider_db_oracle_util::append_name_with_charset" ); |
2493 | if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2 + name_length * 2)) |
2494 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2495 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2496 | str->append(name, name_length, name_charset); |
2497 | if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
2498 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2499 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2500 | DBUG_RETURN(0); |
2501 | } |
2502 | |
2503 | bool spider_db_oracle_util::is_name_quote( |
2504 | const char head_code |
2505 | ) { |
2506 | DBUG_ENTER("spider_db_oracle_util::is_name_quote" ); |
2507 | DBUG_RETURN(head_code == *name_quote_str); |
2508 | } |
2509 | |
2510 | int spider_db_oracle_util::append_escaped_name_quote( |
2511 | spider_string *str |
2512 | ) { |
2513 | DBUG_ENTER("spider_db_oracle_util::append_escaped_name_quote" ); |
2514 | if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2)) |
2515 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2516 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2517 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2518 | DBUG_RETURN(0); |
2519 | } |
2520 | |
2521 | int spider_db_oracle_util::append_column_value( |
2522 | ha_spider *spider, |
2523 | spider_string *str, |
2524 | Field *field, |
2525 | const uchar *new_ptr, |
2526 | CHARSET_INFO *access_charset |
2527 | ) { |
2528 | char buf[MAX_FIELD_WIDTH]; |
2529 | spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin); |
2530 | String *ptr; |
2531 | uint length; |
2532 | DBUG_ENTER("spider_db_oracle_util::append_column_value" ); |
2533 | tmp_str.init_calc_mem(181); |
2534 | |
2535 | if (new_ptr) |
2536 | { |
2537 | if ( |
2538 | field->type() == MYSQL_TYPE_BLOB || |
2539 | field->real_type() == MYSQL_TYPE_VARCHAR |
2540 | ) { |
2541 | length = uint2korr(new_ptr); |
2542 | tmp_str.set_quick((char *) new_ptr + HA_KEY_BLOB_LENGTH, length, |
2543 | &my_charset_bin); |
2544 | ptr = tmp_str.get_str(); |
2545 | } else if (field->type() == MYSQL_TYPE_GEOMETRY) |
2546 | { |
2547 | /* |
2548 | uint mlength = SIZEOF_STORED_DOUBLE, lcnt; |
2549 | uchar *dest = (uchar *) buf; |
2550 | const uchar *source; |
2551 | for (lcnt = 0; lcnt < 4; lcnt++) |
2552 | { |
2553 | mlength = SIZEOF_STORED_DOUBLE; |
2554 | source = new_ptr + mlength + SIZEOF_STORED_DOUBLE * lcnt; |
2555 | while (mlength--) |
2556 | *dest++ = *--source; |
2557 | } |
2558 | tmp_str.length(SIZEOF_STORED_DOUBLE * lcnt); |
2559 | */ |
2560 | double xmin, xmax, ymin, ymax; |
2561 | /* |
2562 | float8store(buf,xmin); |
2563 | float8store(buf+8,xmax); |
2564 | float8store(buf+16,ymin); |
2565 | float8store(buf+24,ymax); |
2566 | memcpy(&xmin,new_ptr,sizeof(xmin)); |
2567 | memcpy(&xmax,new_ptr + 8,sizeof(xmax)); |
2568 | memcpy(&ymin,new_ptr + 16,sizeof(ymin)); |
2569 | memcpy(&ymax,new_ptr + 24,sizeof(ymax)); |
2570 | float8get(xmin, buf); |
2571 | float8get(xmax, buf + 8); |
2572 | float8get(ymin, buf + 16); |
2573 | float8get(ymax, buf + 24); |
2574 | DBUG_PRINT("info", ("spider geo is %f %f %f %f", |
2575 | xmin, xmax, ymin, ymax)); |
2576 | DBUG_PRINT("info", ("spider geo is %.14g %.14g %.14g %.14g", |
2577 | xmin, xmax, ymin, ymax)); |
2578 | */ |
2579 | float8get(xmin, new_ptr); |
2580 | float8get(xmax, new_ptr + 8); |
2581 | float8get(ymin, new_ptr + 16); |
2582 | float8get(ymax, new_ptr + 24); |
2583 | DBUG_PRINT("info" , ("spider geo is %f %f %f %f" , |
2584 | xmin, xmax, ymin, ymax)); |
2585 | /* |
2586 | float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 4); |
2587 | float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 5); |
2588 | float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 6); |
2589 | float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 7); |
2590 | DBUG_PRINT("info", ("spider geo is %f %f %f %f", |
2591 | xmin, xmax, ymin, ymax)); |
2592 | float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 8); |
2593 | float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 9); |
2594 | float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 10); |
2595 | float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 11); |
2596 | DBUG_PRINT("info", ("spider geo is %f %f %f %f", |
2597 | xmin, xmax, ymin, ymax)); |
2598 | float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 12); |
2599 | float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 13); |
2600 | float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 14); |
2601 | float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 15); |
2602 | DBUG_PRINT("info", ("spider geo is %f %f %f %f", |
2603 | xmin, xmax, ymin, ymax)); |
2604 | */ |
2605 | /* |
2606 | tmp_str.set_quick((char *) new_ptr, SIZEOF_STORED_DOUBLE * 4, |
2607 | &my_charset_bin); |
2608 | */ |
2609 | tmp_str.length(0); |
2610 | tmp_str.q_append((char *) SPIDER_SQL_LINESTRING_HEAD_STR, |
2611 | SPIDER_SQL_LINESTRING_HEAD_LEN); |
2612 | tmp_str.q_append((char *) new_ptr, SIZEOF_STORED_DOUBLE); |
2613 | tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 2, |
2614 | SIZEOF_STORED_DOUBLE); |
2615 | tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE, |
2616 | SIZEOF_STORED_DOUBLE); |
2617 | tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 3, |
2618 | SIZEOF_STORED_DOUBLE); |
2619 | ptr = tmp_str.get_str(); |
2620 | } else { |
2621 | ptr = field->val_str(tmp_str.get_str(), new_ptr); |
2622 | tmp_str.mem_calc(); |
2623 | } |
2624 | } else { |
2625 | ptr = field->val_str(tmp_str.get_str()); |
2626 | tmp_str.mem_calc(); |
2627 | } |
2628 | DBUG_PRINT("info" , ("spider field->type() is %d" , field->type())); |
2629 | DBUG_PRINT("info" , ("spider ptr->length() is %d" , ptr->length())); |
2630 | /* |
2631 | if ( |
2632 | field->type() == MYSQL_TYPE_BIT || |
2633 | (field->type() >= MYSQL_TYPE_TINY_BLOB && |
2634 | field->type() <= MYSQL_TYPE_BLOB) |
2635 | ) { |
2636 | uchar *hex_ptr = (uchar *) ptr->ptr(), *end_ptr; |
2637 | char *str_ptr; |
2638 | DBUG_PRINT("info", ("spider HEX")); |
2639 | if (str->reserve(SPIDER_SQL_HEX_LEN + ptr->length() * 2)) |
2640 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2641 | str->q_append(SPIDER_SQL_HEX_STR, SPIDER_SQL_HEX_LEN); |
2642 | str_ptr = (char *) str->ptr() + str->length(); |
2643 | for (end_ptr = hex_ptr + ptr->length(); hex_ptr < end_ptr; hex_ptr++) |
2644 | { |
2645 | *str_ptr++ = spider_dig_upper[(*hex_ptr) >> 4]; |
2646 | *str_ptr++ = spider_dig_upper[(*hex_ptr) & 0x0F]; |
2647 | } |
2648 | str->length(str->length() + ptr->length() * 2); |
2649 | } else |
2650 | */ |
2651 | if (field->result_type() == STRING_RESULT) |
2652 | { |
2653 | DBUG_PRINT("info" , ("spider STRING_RESULT" )); |
2654 | if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) |
2655 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2656 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
2657 | if ( |
2658 | field->type() == MYSQL_TYPE_VARCHAR || |
2659 | (field->type() >= MYSQL_TYPE_ENUM && |
2660 | field->type() <= MYSQL_TYPE_GEOMETRY) |
2661 | ) { |
2662 | DBUG_PRINT("info" , ("spider append_escaped" )); |
2663 | char buf2[MAX_FIELD_WIDTH]; |
2664 | spider_string tmp_str2(buf2, MAX_FIELD_WIDTH, access_charset); |
2665 | tmp_str2.init_calc_mem(182); |
2666 | tmp_str2.length(0); |
2667 | if ( |
2668 | tmp_str2.append(ptr->ptr(), ptr->length(), field->charset()) || |
2669 | str->reserve(tmp_str2.length() * 2) || |
2670 | append_escaped_util(str, tmp_str2.get_str()) |
2671 | ) |
2672 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2673 | } else if (str->append(*ptr)) |
2674 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2675 | if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) |
2676 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2677 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
2678 | } else if (field->str_needs_quotes()) |
2679 | { |
2680 | if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 + ptr->length() * 2 + 2)) |
2681 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2682 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
2683 | append_escaped_util(str, ptr); |
2684 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
2685 | } else if (str->append(*ptr)) |
2686 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2687 | DBUG_RETURN(0); |
2688 | } |
2689 | |
2690 | int spider_db_oracle_util::append_from_with_alias( |
2691 | spider_string *str, |
2692 | const char **table_names, |
2693 | uint *table_name_lengths, |
2694 | const char **table_aliases, |
2695 | uint *table_alias_lengths, |
2696 | uint table_count, |
2697 | int *table_name_pos, |
2698 | bool over_write |
2699 | ) { |
2700 | uint roop_count, length = 0; |
2701 | DBUG_ENTER("spider_db_oracle_util::append_from_with_alias" ); |
2702 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2703 | if (!over_write) |
2704 | { |
2705 | for (roop_count = 0; roop_count < table_count; roop_count++) |
2706 | length += table_name_lengths[roop_count] + SPIDER_SQL_SPACE_LEN + |
2707 | table_alias_lengths[roop_count] + SPIDER_SQL_COMMA_LEN; |
2708 | if (str->reserve(SPIDER_SQL_FROM_LEN + length)) |
2709 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2710 | str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
2711 | *table_name_pos = str->length(); |
2712 | } |
2713 | for (roop_count = 0; roop_count < table_count; roop_count++) |
2714 | { |
2715 | str->q_append(table_names[roop_count], table_name_lengths[roop_count]); |
2716 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
2717 | str->q_append(table_aliases[roop_count], table_alias_lengths[roop_count]); |
2718 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
2719 | } |
2720 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
2721 | DBUG_RETURN(0); |
2722 | } |
2723 | |
2724 | int spider_db_oracle_util::append_trx_isolation( |
2725 | spider_string *str, |
2726 | int trx_isolation |
2727 | ) { |
2728 | DBUG_ENTER("spider_db_oracle_util::append_trx_isolation" ); |
2729 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2730 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + |
2731 | SPIDER_SQL_ISO_READ_COMMITTED_LEN)) |
2732 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2733 | if (str->length()) |
2734 | { |
2735 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
2736 | } |
2737 | switch (trx_isolation) |
2738 | { |
2739 | case ISO_READ_UNCOMMITTED: |
2740 | case ISO_READ_COMMITTED: |
2741 | str->q_append(SPIDER_SQL_ISO_READ_COMMITTED_STR, |
2742 | SPIDER_SQL_ISO_READ_COMMITTED_LEN); |
2743 | break; |
2744 | case ISO_REPEATABLE_READ: |
2745 | case ISO_SERIALIZABLE: |
2746 | str->q_append(SPIDER_SQL_ISO_SERIALIZABLE_STR, |
2747 | SPIDER_SQL_ISO_SERIALIZABLE_LEN); |
2748 | break; |
2749 | default: |
2750 | DBUG_RETURN(HA_ERR_UNSUPPORTED); |
2751 | } |
2752 | DBUG_RETURN(0); |
2753 | } |
2754 | |
2755 | int spider_db_oracle_util::append_autocommit( |
2756 | spider_string *str, |
2757 | bool autocommit |
2758 | ) { |
2759 | DBUG_ENTER("spider_db_oracle_util::append_autocommit" ); |
2760 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2761 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_AUTOCOMMIT_OFF_LEN)) |
2762 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2763 | if (str->length()) |
2764 | { |
2765 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
2766 | } |
2767 | if (autocommit) |
2768 | { |
2769 | str->q_append(SPIDER_SQL_AUTOCOMMIT_ON_STR, |
2770 | SPIDER_SQL_AUTOCOMMIT_ON_LEN); |
2771 | } else { |
2772 | str->q_append(SPIDER_SQL_AUTOCOMMIT_OFF_STR, |
2773 | SPIDER_SQL_AUTOCOMMIT_OFF_LEN); |
2774 | } |
2775 | DBUG_RETURN(0); |
2776 | } |
2777 | |
2778 | int spider_db_oracle_util::append_sql_log_off( |
2779 | spider_string *str, |
2780 | bool sql_log_off |
2781 | ) { |
2782 | DBUG_ENTER("spider_db_oracle_util::append_sql_log_off" ); |
2783 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2784 | /* nothing to do */ |
2785 | DBUG_RETURN(0); |
2786 | } |
2787 | |
2788 | int spider_db_oracle_util::append_time_zone( |
2789 | spider_string *str, |
2790 | Time_zone *time_zone |
2791 | ) { |
2792 | DBUG_ENTER("spider_db_oracle_util::append_time_zone" ); |
2793 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2794 | /* nothing to do */ |
2795 | DBUG_RETURN(0); |
2796 | } |
2797 | |
2798 | int spider_db_oracle_util::append_start_transaction( |
2799 | spider_string *str |
2800 | ) { |
2801 | DBUG_ENTER("spider_db_oracle_util::append_start_transaction" ); |
2802 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2803 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + |
2804 | SPIDER_SQL_START_TRANSACTION_LEN)) |
2805 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2806 | if (str->length()) |
2807 | { |
2808 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
2809 | } |
2810 | str->q_append(SPIDER_SQL_START_TRANSACTION_STR, |
2811 | SPIDER_SQL_START_TRANSACTION_LEN); |
2812 | DBUG_RETURN(0); |
2813 | } |
2814 | |
2815 | int spider_db_oracle_util::append_xa_start( |
2816 | spider_string *str, |
2817 | XID *xid |
2818 | ) { |
2819 | DBUG_ENTER("spider_db_oracle_util::append_xa_start" ); |
2820 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2821 | DBUG_ASSERT(0); |
2822 | DBUG_RETURN(0); |
2823 | } |
2824 | |
2825 | int spider_db_oracle_util::append_lock_table_head( |
2826 | spider_string *str |
2827 | ) { |
2828 | DBUG_ENTER("spider_db_oracle_util::append_lock_table_head" ); |
2829 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2830 | DBUG_RETURN(0); |
2831 | } |
2832 | |
2833 | int spider_db_oracle_util::append_lock_table_body( |
2834 | spider_string *str, |
2835 | const char *db_name, |
2836 | uint db_name_length, |
2837 | CHARSET_INFO *db_name_charset, |
2838 | const char *table_name, |
2839 | uint table_name_length, |
2840 | CHARSET_INFO *table_name_charset, |
2841 | int lock_type |
2842 | ) { |
2843 | DBUG_ENTER("spider_db_oracle_util::append_lock_table_body" ); |
2844 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2845 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_LOCK_TABLE_LEN)) |
2846 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2847 | if (str->length()) |
2848 | { |
2849 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
2850 | } |
2851 | str->q_append(SPIDER_SQL_LOCK_TABLE_STR, SPIDER_SQL_LOCK_TABLE_LEN); |
2852 | if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
2853 | { |
2854 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2855 | } |
2856 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2857 | if ( |
2858 | str->append(db_name, db_name_length, db_name_charset) || |
2859 | str->reserve((SPIDER_SQL_NAME_QUOTE_LEN) * 2 + SPIDER_SQL_DOT_LEN) |
2860 | ) { |
2861 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2862 | } |
2863 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2864 | str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); |
2865 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2866 | if ( |
2867 | str->append(table_name, table_name_length, table_name_charset) || |
2868 | str->reserve(SPIDER_SQL_NAME_QUOTE_LEN + |
2869 | spider_db_table_lock_len[lock_type]) |
2870 | ) { |
2871 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2872 | } |
2873 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2874 | str->q_append(spider_db_table_lock_str[lock_type], |
2875 | spider_db_table_lock_len[lock_type]); |
2876 | DBUG_RETURN(0); |
2877 | } |
2878 | |
2879 | int spider_db_oracle_util::append_lock_table_tail( |
2880 | spider_string *str |
2881 | ) { |
2882 | DBUG_ENTER("spider_db_oracle_util::append_lock_table_tail" ); |
2883 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2884 | DBUG_RETURN(0); |
2885 | } |
2886 | |
2887 | int spider_db_oracle_util::append_unlock_table( |
2888 | spider_string *str |
2889 | ) { |
2890 | DBUG_ENTER("spider_db_oracle_util::append_unlock_table" ); |
2891 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2892 | if (str->reserve(SPIDER_SQL_COMMIT_LEN)) |
2893 | { |
2894 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2895 | } |
2896 | str->q_append(SPIDER_SQL_COMMIT_STR, SPIDER_SQL_COMMIT_LEN); |
2897 | DBUG_RETURN(0); |
2898 | } |
2899 | |
2900 | int spider_db_oracle_util::open_item_func( |
2901 | Item_func *item_func, |
2902 | ha_spider *spider, |
2903 | spider_string *str, |
2904 | const char *alias, |
2905 | uint alias_length, |
2906 | bool use_fields, |
2907 | spider_fields *fields |
2908 | ) { |
2909 | uint dbton_id = spider_dbton_oracle.dbton_id; |
2910 | int error_num; |
2911 | Item *item, **item_list = item_func->arguments(); |
2912 | uint roop_count, item_count = item_func->argument_count(), start_item = 0; |
2913 | const char *func_name = SPIDER_SQL_NULL_CHAR_STR, |
2914 | *separete_str = SPIDER_SQL_NULL_CHAR_STR, |
2915 | *last_str = SPIDER_SQL_NULL_CHAR_STR; |
2916 | int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, |
2917 | separete_str_length = SPIDER_SQL_NULL_CHAR_LEN, |
2918 | last_str_length = SPIDER_SQL_NULL_CHAR_LEN; |
2919 | int use_pushdown_udf; |
2920 | bool merge_func = FALSE; |
2921 | DBUG_ENTER("spider_db_oracle_util::open_item_func" ); |
2922 | if (str) |
2923 | { |
2924 | if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) |
2925 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2926 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
2927 | } |
2928 | DBUG_PRINT("info" ,("spider functype = %d" , item_func->functype())); |
2929 | switch (item_func->functype()) |
2930 | { |
2931 | case Item_func::ISNULL_FUNC: |
2932 | last_str = SPIDER_SQL_IS_NULL_STR; |
2933 | last_str_length = SPIDER_SQL_IS_NULL_LEN; |
2934 | break; |
2935 | case Item_func::ISNOTNULL_FUNC: |
2936 | last_str = SPIDER_SQL_IS_NOT_NULL_STR; |
2937 | last_str_length = SPIDER_SQL_IS_NOT_NULL_LEN; |
2938 | break; |
2939 | case Item_func::UNKNOWN_FUNC: |
2940 | func_name = (char*) item_func->func_name(); |
2941 | func_name_length = strlen(func_name); |
2942 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
2943 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
2944 | if (func_name_length == 1 && |
2945 | ( |
2946 | !strncasecmp("+" , func_name, func_name_length) || |
2947 | !strncasecmp("-" , func_name, func_name_length) || |
2948 | !strncasecmp("*" , func_name, func_name_length) || |
2949 | !strncasecmp("/" , func_name, func_name_length) || |
2950 | !strncasecmp("%" , func_name, func_name_length) || |
2951 | !strncasecmp("&" , func_name, func_name_length) || |
2952 | !strncasecmp("|" , func_name, func_name_length) || |
2953 | !strncasecmp("^" , func_name, func_name_length) |
2954 | ) |
2955 | ) { |
2956 | /* no action */ |
2957 | break; |
2958 | } else if (func_name_length == 2 && |
2959 | ( |
2960 | !strncasecmp("<<" , func_name, func_name_length) || |
2961 | !strncasecmp(">>" , func_name, func_name_length) |
2962 | ) |
2963 | ) { |
2964 | /* no action */ |
2965 | break; |
2966 | } else if (func_name_length == 3 && |
2967 | !strncasecmp("div" , func_name, func_name_length) |
2968 | ) { |
2969 | /* no action */ |
2970 | break; |
2971 | } else if (func_name_length == 4) |
2972 | { |
2973 | if ( |
2974 | !strncasecmp("rand" , func_name, func_name_length) && |
2975 | #ifdef SPIDER_Item_args_arg_count_IS_PROTECTED |
2976 | !item_func->argument_count() |
2977 | #else |
2978 | !item_func->arg_count |
2979 | #endif |
2980 | ) { |
2981 | if (str) |
2982 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
2983 | DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, |
2984 | alias, alias_length, dbton_id, use_fields, fields)); |
2985 | } else if ( |
2986 | !strncasecmp("case" , func_name, func_name_length) |
2987 | ) { |
2988 | #ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC |
2989 | Item_func_case *item_func_case = (Item_func_case *) item_func; |
2990 | if (str) |
2991 | { |
2992 | if (str->reserve(SPIDER_SQL_CASE_LEN)) |
2993 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2994 | str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); |
2995 | } |
2996 | if (item_func_case->first_expr_num != -1) |
2997 | { |
2998 | if ((error_num = spider_db_print_item_type( |
2999 | item_list[item_func_case->first_expr_num], spider, str, |
3000 | alias, alias_length, dbton_id, use_fields, fields))) |
3001 | DBUG_RETURN(error_num); |
3002 | } |
3003 | for (roop_count = 0; roop_count < item_func_case->ncases; |
3004 | roop_count += 2) |
3005 | { |
3006 | if (str) |
3007 | { |
3008 | if (str->reserve(SPIDER_SQL_WHEN_LEN)) |
3009 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3010 | str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); |
3011 | } |
3012 | if ((error_num = spider_db_print_item_type( |
3013 | item_list[roop_count], spider, str, |
3014 | alias, alias_length, dbton_id, use_fields, fields))) |
3015 | DBUG_RETURN(error_num); |
3016 | if (str) |
3017 | { |
3018 | if (str->reserve(SPIDER_SQL_THEN_LEN)) |
3019 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3020 | str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); |
3021 | } |
3022 | if ((error_num = spider_db_print_item_type( |
3023 | item_list[roop_count + 1], spider, str, |
3024 | alias, alias_length, dbton_id, use_fields, fields))) |
3025 | DBUG_RETURN(error_num); |
3026 | } |
3027 | if (item_func_case->else_expr_num != -1) |
3028 | { |
3029 | if (str) |
3030 | { |
3031 | if (str->reserve(SPIDER_SQL_ELSE_LEN)) |
3032 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3033 | str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); |
3034 | } |
3035 | if ((error_num = spider_db_print_item_type( |
3036 | item_list[item_func_case->else_expr_num], spider, str, |
3037 | alias, alias_length, dbton_id, use_fields, fields))) |
3038 | DBUG_RETURN(error_num); |
3039 | } |
3040 | if (str) |
3041 | { |
3042 | if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) |
3043 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3044 | str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN); |
3045 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3046 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3047 | } |
3048 | DBUG_RETURN(0); |
3049 | #else |
3050 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3051 | #endif |
3052 | } |
3053 | } else if (func_name_length == 6 && |
3054 | !strncasecmp("istrue" , func_name, func_name_length) |
3055 | ) { |
3056 | last_str = SPIDER_SQL_IS_TRUE_STR; |
3057 | last_str_length = SPIDER_SQL_IS_TRUE_LEN; |
3058 | break; |
3059 | } else if (func_name_length == 7) |
3060 | { |
3061 | if (!strncasecmp("isfalse" , func_name, func_name_length)) |
3062 | { |
3063 | last_str = SPIDER_SQL_IS_FALSE_STR; |
3064 | last_str_length = SPIDER_SQL_IS_FALSE_LEN; |
3065 | break; |
3066 | } else if ( |
3067 | !strncasecmp("sysdate" , func_name, func_name_length) || |
3068 | !strncasecmp("curdate" , func_name, func_name_length) || |
3069 | !strncasecmp("curtime" , func_name, func_name_length) |
3070 | ) { |
3071 | if (str) |
3072 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3073 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
3074 | alias, alias_length, dbton_id, use_fields, fields)); |
3075 | } else if ( |
3076 | !strncasecmp("convert" , func_name, func_name_length) |
3077 | ) { |
3078 | if (str) |
3079 | { |
3080 | if (str->reserve(func_name_length * 2 + SPIDER_SQL_OPEN_PAREN_LEN)) |
3081 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3082 | str->q_append(func_name, func_name_length); |
3083 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, |
3084 | SPIDER_SQL_OPEN_PAREN_LEN); |
3085 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3086 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3087 | } |
3088 | break; |
3089 | } |
3090 | } else if (func_name_length == 8 && |
3091 | ( |
3092 | !strncasecmp("utc_date" , func_name, func_name_length) || |
3093 | !strncasecmp("utc_time" , func_name, func_name_length) |
3094 | ) |
3095 | ) { |
3096 | if (str) |
3097 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3098 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
3099 | alias, alias_length, dbton_id, use_fields, fields)); |
3100 | } else if (func_name_length == 9 && |
3101 | !strncasecmp("isnottrue" , func_name, func_name_length) |
3102 | ) { |
3103 | last_str = SPIDER_SQL_IS_NOT_TRUE_STR; |
3104 | last_str_length = SPIDER_SQL_IS_NOT_TRUE_LEN; |
3105 | break; |
3106 | } else if (func_name_length == 10) |
3107 | { |
3108 | if (!strncasecmp("isnotfalse" , func_name, func_name_length)) |
3109 | { |
3110 | last_str = SPIDER_SQL_IS_NOT_FALSE_STR; |
3111 | last_str_length = SPIDER_SQL_IS_NOT_FALSE_LEN; |
3112 | break; |
3113 | } else if (!strncasecmp("column_get" , func_name, func_name_length)) |
3114 | { |
3115 | if (str) |
3116 | { |
3117 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3118 | if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) |
3119 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3120 | str->q_append(func_name, func_name_length); |
3121 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3122 | } |
3123 | func_name = SPIDER_SQL_COMMA_STR; |
3124 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3125 | separete_str = SPIDER_SQL_COMMA_STR; |
3126 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3127 | break; |
3128 | } |
3129 | } else if (func_name_length == 12) |
3130 | { |
3131 | if (!strncasecmp("cast_as_date" , func_name, func_name_length)) |
3132 | { |
3133 | item = item_list[0]; |
3134 | if (item->type() == Item::FUNC_ITEM) |
3135 | { |
3136 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3137 | Item_func *ifunc = (Item_func *) item; |
3138 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3139 | { |
3140 | const char *child_func_name; |
3141 | int child_func_name_length; |
3142 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3143 | child_func_name = (char*) ifunc->func_name(); |
3144 | child_func_name_length = strlen(child_func_name); |
3145 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3146 | if ( |
3147 | child_func_name_length == 10 && |
3148 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3149 | ) { |
3150 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3151 | merge_func = TRUE; |
3152 | } |
3153 | } |
3154 | } |
3155 | |
3156 | if (str) |
3157 | { |
3158 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3159 | if (!merge_func) |
3160 | { |
3161 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3162 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3163 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3164 | } |
3165 | } |
3166 | last_str = SPIDER_SQL_AS_DATE_STR; |
3167 | last_str_length = SPIDER_SQL_AS_DATE_LEN; |
3168 | break; |
3169 | } else if (!strncasecmp("cast_as_time" , func_name, func_name_length)) |
3170 | { |
3171 | item = item_list[0]; |
3172 | if (item->type() == Item::FUNC_ITEM) |
3173 | { |
3174 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3175 | Item_func *ifunc = (Item_func *) item; |
3176 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3177 | { |
3178 | const char *child_func_name; |
3179 | int child_func_name_length; |
3180 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3181 | child_func_name = (char*) ifunc->func_name(); |
3182 | child_func_name_length = strlen(child_func_name); |
3183 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3184 | if ( |
3185 | child_func_name_length == 10 && |
3186 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3187 | ) { |
3188 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3189 | merge_func = TRUE; |
3190 | } |
3191 | } |
3192 | } |
3193 | |
3194 | if (str) |
3195 | { |
3196 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3197 | if (!merge_func) |
3198 | { |
3199 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3200 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3201 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3202 | } |
3203 | } |
3204 | last_str = SPIDER_SQL_AS_TIME_STR; |
3205 | last_str_length = SPIDER_SQL_AS_TIME_LEN; |
3206 | break; |
3207 | } |
3208 | } else if (func_name_length == 13) |
3209 | { |
3210 | if (!strncasecmp("utc_timestamp" , func_name, func_name_length)) |
3211 | { |
3212 | if (str) |
3213 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3214 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
3215 | alias, alias_length, dbton_id, use_fields, fields)); |
3216 | } else if (!strncasecmp("timestampdiff" , func_name, func_name_length)) |
3217 | { |
3218 | #ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC |
3219 | Item_func_timestamp_diff *item_func_timestamp_diff = |
3220 | (Item_func_timestamp_diff *) item_func; |
3221 | if (str) |
3222 | { |
3223 | const char *interval_str; |
3224 | uint interval_len; |
3225 | switch (item_func_timestamp_diff->int_type) |
3226 | { |
3227 | case INTERVAL_YEAR: |
3228 | interval_str = SPIDER_SQL_YEAR_STR; |
3229 | interval_len = SPIDER_SQL_YEAR_LEN; |
3230 | break; |
3231 | case INTERVAL_QUARTER: |
3232 | interval_str = SPIDER_SQL_QUARTER_STR; |
3233 | interval_len = SPIDER_SQL_QUARTER_LEN; |
3234 | break; |
3235 | case INTERVAL_MONTH: |
3236 | interval_str = SPIDER_SQL_MONTH_STR; |
3237 | interval_len = SPIDER_SQL_MONTH_LEN; |
3238 | break; |
3239 | case INTERVAL_WEEK: |
3240 | interval_str = SPIDER_SQL_WEEK_STR; |
3241 | interval_len = SPIDER_SQL_WEEK_LEN; |
3242 | break; |
3243 | case INTERVAL_DAY: |
3244 | interval_str = SPIDER_SQL_DAY_STR; |
3245 | interval_len = SPIDER_SQL_DAY_LEN; |
3246 | break; |
3247 | case INTERVAL_HOUR: |
3248 | interval_str = SPIDER_SQL_HOUR_STR; |
3249 | interval_len = SPIDER_SQL_HOUR_LEN; |
3250 | break; |
3251 | case INTERVAL_MINUTE: |
3252 | interval_str = SPIDER_SQL_MINUTE_STR; |
3253 | interval_len = SPIDER_SQL_MINUTE_LEN; |
3254 | break; |
3255 | case INTERVAL_SECOND: |
3256 | interval_str = SPIDER_SQL_SECOND_STR; |
3257 | interval_len = SPIDER_SQL_SECOND_LEN; |
3258 | break; |
3259 | case INTERVAL_MICROSECOND: |
3260 | interval_str = SPIDER_SQL_MICROSECOND_STR; |
3261 | interval_len = SPIDER_SQL_MICROSECOND_LEN; |
3262 | break; |
3263 | default: |
3264 | interval_str = "" ; |
3265 | interval_len = 0; |
3266 | break; |
3267 | } |
3268 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3269 | if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN + |
3270 | interval_len + SPIDER_SQL_COMMA_LEN)) |
3271 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3272 | str->q_append(func_name, func_name_length); |
3273 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3274 | str->q_append(interval_str, interval_len); |
3275 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
3276 | } |
3277 | if ((error_num = spider_db_print_item_type(item_list[0], spider, |
3278 | str, alias, alias_length, dbton_id, use_fields, fields))) |
3279 | DBUG_RETURN(error_num); |
3280 | if (str) |
3281 | { |
3282 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
3283 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3284 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
3285 | } |
3286 | if ((error_num = spider_db_print_item_type(item_list[1], spider, |
3287 | str, alias, alias_length, dbton_id, use_fields, fields))) |
3288 | DBUG_RETURN(error_num); |
3289 | if (str) |
3290 | { |
3291 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) |
3292 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3293 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3294 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3295 | } |
3296 | DBUG_RETURN(0); |
3297 | #else |
3298 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3299 | #endif |
3300 | } |
3301 | } else if (func_name_length == 14) |
3302 | { |
3303 | if (!strncasecmp("cast_as_binary" , func_name, func_name_length)) |
3304 | { |
3305 | item = item_list[0]; |
3306 | if (item->type() == Item::FUNC_ITEM) |
3307 | { |
3308 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3309 | Item_func *ifunc = (Item_func *) item; |
3310 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3311 | { |
3312 | const char *child_func_name; |
3313 | int child_func_name_length; |
3314 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3315 | child_func_name = (char*) ifunc->func_name(); |
3316 | child_func_name_length = strlen(child_func_name); |
3317 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3318 | if ( |
3319 | child_func_name_length == 10 && |
3320 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3321 | ) { |
3322 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3323 | merge_func = TRUE; |
3324 | } |
3325 | } |
3326 | } |
3327 | |
3328 | if (str) |
3329 | { |
3330 | char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; |
3331 | spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); |
3332 | tmp_str.init_calc_mem(123); |
3333 | tmp_str.length(0); |
3334 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3335 | if (!merge_func) |
3336 | { |
3337 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3338 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3339 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3340 | } |
3341 | #if MYSQL_VERSION_ID < 50500 |
3342 | item_func->print(tmp_str.get_str(), QT_IS); |
3343 | #else |
3344 | item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); |
3345 | #endif |
3346 | tmp_str.mem_calc(); |
3347 | if (tmp_str.reserve(1)) |
3348 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3349 | tmp_ptr = tmp_str.c_ptr_quick(); |
3350 | DBUG_PRINT("info" ,("spider tmp_ptr = %s" , tmp_ptr)); |
3351 | while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_BINARY_STR))) |
3352 | tmp_ptr = tmp_ptr2 + 1; |
3353 | last_str = tmp_ptr - 1; |
3354 | last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; |
3355 | } |
3356 | break; |
3357 | } else if (!strncasecmp("cast_as_signed" , func_name, func_name_length)) |
3358 | { |
3359 | item = item_list[0]; |
3360 | if (item->type() == Item::FUNC_ITEM) |
3361 | { |
3362 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3363 | Item_func *ifunc = (Item_func *) item; |
3364 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3365 | { |
3366 | const char *child_func_name; |
3367 | int child_func_name_length; |
3368 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3369 | child_func_name = (char*) ifunc->func_name(); |
3370 | child_func_name_length = strlen(child_func_name); |
3371 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3372 | if ( |
3373 | child_func_name_length == 10 && |
3374 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3375 | ) { |
3376 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3377 | merge_func = TRUE; |
3378 | } |
3379 | } |
3380 | } |
3381 | |
3382 | if (str) |
3383 | { |
3384 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3385 | if (!merge_func) |
3386 | { |
3387 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3388 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3389 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3390 | } |
3391 | } |
3392 | last_str = SPIDER_SQL_AS_SIGNED_STR; |
3393 | last_str_length = SPIDER_SQL_AS_SIGNED_LEN; |
3394 | break; |
3395 | } |
3396 | } else if (func_name_length == 16) |
3397 | { |
3398 | if (!strncasecmp("cast_as_unsigned" , func_name, func_name_length)) |
3399 | { |
3400 | item = item_list[0]; |
3401 | if (item->type() == Item::FUNC_ITEM) |
3402 | { |
3403 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3404 | Item_func *ifunc = (Item_func *) item; |
3405 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3406 | { |
3407 | const char *child_func_name; |
3408 | int child_func_name_length; |
3409 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3410 | child_func_name = (char*) ifunc->func_name(); |
3411 | child_func_name_length = strlen(child_func_name); |
3412 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3413 | if ( |
3414 | child_func_name_length == 10 && |
3415 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3416 | ) { |
3417 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3418 | merge_func = TRUE; |
3419 | } |
3420 | } |
3421 | } |
3422 | |
3423 | if (str) |
3424 | { |
3425 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3426 | if (!merge_func) |
3427 | { |
3428 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3429 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3430 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3431 | } |
3432 | } |
3433 | last_str = SPIDER_SQL_AS_UNSIGNED_STR; |
3434 | last_str_length = SPIDER_SQL_AS_UNSIGNED_LEN; |
3435 | break; |
3436 | } else if (!strncasecmp("decimal_typecast" , func_name, |
3437 | func_name_length)) |
3438 | { |
3439 | item = item_list[0]; |
3440 | if (item->type() == Item::FUNC_ITEM) |
3441 | { |
3442 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3443 | Item_func *ifunc = (Item_func *) item; |
3444 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3445 | { |
3446 | const char *child_func_name; |
3447 | int child_func_name_length; |
3448 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3449 | child_func_name = (char*) ifunc->func_name(); |
3450 | child_func_name_length = strlen(child_func_name); |
3451 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3452 | if ( |
3453 | child_func_name_length == 10 && |
3454 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3455 | ) { |
3456 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3457 | merge_func = TRUE; |
3458 | } |
3459 | } |
3460 | } |
3461 | |
3462 | if (str) |
3463 | { |
3464 | char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; |
3465 | spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); |
3466 | tmp_str.init_calc_mem(124); |
3467 | tmp_str.length(0); |
3468 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3469 | if (!merge_func) |
3470 | { |
3471 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3472 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3473 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3474 | } |
3475 | #if MYSQL_VERSION_ID < 50500 |
3476 | item_func->print(tmp_str.get_str(), QT_IS); |
3477 | #else |
3478 | item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); |
3479 | #endif |
3480 | tmp_str.mem_calc(); |
3481 | if (tmp_str.reserve(1)) |
3482 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3483 | tmp_ptr = tmp_str.c_ptr_quick(); |
3484 | DBUG_PRINT("info" ,("spider tmp_ptr = %s" , tmp_ptr)); |
3485 | while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_DECIMAL_STR))) |
3486 | tmp_ptr = tmp_ptr2 + 1; |
3487 | last_str = tmp_ptr - 1; |
3488 | last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; |
3489 | } |
3490 | break; |
3491 | } else if (!strncasecmp("cast_as_datetime" , func_name, |
3492 | func_name_length)) |
3493 | { |
3494 | item = item_list[0]; |
3495 | if (item->type() == Item::FUNC_ITEM) |
3496 | { |
3497 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3498 | Item_func *ifunc = (Item_func *) item; |
3499 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3500 | { |
3501 | const char *child_func_name; |
3502 | int child_func_name_length; |
3503 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3504 | child_func_name = (char*) ifunc->func_name(); |
3505 | child_func_name_length = strlen(child_func_name); |
3506 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3507 | if ( |
3508 | child_func_name_length == 10 && |
3509 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3510 | ) { |
3511 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3512 | merge_func = TRUE; |
3513 | } |
3514 | } |
3515 | } |
3516 | |
3517 | if (str) |
3518 | { |
3519 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3520 | if (!merge_func) |
3521 | { |
3522 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3523 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3524 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3525 | } |
3526 | } |
3527 | last_str = SPIDER_SQL_AS_DATETIME_STR; |
3528 | last_str_length = SPIDER_SQL_AS_DATETIME_LEN; |
3529 | break; |
3530 | } |
3531 | } else if (func_name_length == 17) |
3532 | { |
3533 | if (!strncasecmp("date_add_interval" , func_name, func_name_length)) |
3534 | { |
3535 | Item_date_add_interval *item_date_add_interval = |
3536 | (Item_date_add_interval *) item_func; |
3537 | switch (item_date_add_interval->int_type) |
3538 | { |
3539 | case INTERVAL_YEAR: |
3540 | case INTERVAL_QUARTER: |
3541 | case INTERVAL_MONTH: |
3542 | if (str) |
3543 | { |
3544 | if (str->reserve(SPIDER_SQL_ADD_MONTHS_LEN + |
3545 | SPIDER_SQL_OPEN_PAREN_LEN)) |
3546 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3547 | str->q_append(SPIDER_SQL_ADD_MONTHS_STR, |
3548 | SPIDER_SQL_ADD_MONTHS_LEN); |
3549 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, |
3550 | SPIDER_SQL_OPEN_PAREN_LEN); |
3551 | } |
3552 | if ((error_num = spider_db_print_item_type(item_list[0], spider, |
3553 | str, alias, alias_length, dbton_id, use_fields, fields))) |
3554 | DBUG_RETURN(error_num); |
3555 | if (str) |
3556 | { |
3557 | if (item_date_add_interval->date_sub_interval) |
3558 | { |
3559 | if (str->reserve(SPIDER_SQL_COMMA_LEN + |
3560 | SPIDER_SQL_MINUS_LEN)) |
3561 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3562 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
3563 | str->q_append(SPIDER_SQL_MINUS_STR, SPIDER_SQL_MINUS_LEN); |
3564 | } else { |
3565 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
3566 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3567 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
3568 | } |
3569 | } |
3570 | if ((error_num = spider_db_print_item_type(item_list[1], spider, |
3571 | str, alias, alias_length, dbton_id, use_fields, fields))) |
3572 | DBUG_RETURN(error_num); |
3573 | if (str) |
3574 | { |
3575 | if (item_date_add_interval->int_type == INTERVAL_YEAR) |
3576 | { |
3577 | func_name = " * 12" ; |
3578 | func_name_length = sizeof(" * 12" ) - 1; |
3579 | if (str->reserve(func_name_length + |
3580 | (SPIDER_SQL_CLOSE_PAREN_LEN * 2))) |
3581 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3582 | str->q_append(func_name, func_name_length); |
3583 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3584 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3585 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3586 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3587 | } else if (item_date_add_interval->int_type == |
3588 | INTERVAL_QUARTER) |
3589 | { |
3590 | func_name = " * 3" ; |
3591 | func_name_length = sizeof(" * 3" ) - 1; |
3592 | if (str->reserve(func_name_length + |
3593 | (SPIDER_SQL_CLOSE_PAREN_LEN * 2))) |
3594 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3595 | str->q_append(func_name, func_name_length); |
3596 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3597 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3598 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3599 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3600 | } else { |
3601 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN * 2)) |
3602 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3603 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3604 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3605 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3606 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3607 | } |
3608 | } |
3609 | break; |
3610 | case INTERVAL_WEEK: |
3611 | case INTERVAL_DAY: |
3612 | case INTERVAL_HOUR: |
3613 | case INTERVAL_MINUTE: |
3614 | case INTERVAL_SECOND: |
3615 | case INTERVAL_MICROSECOND: |
3616 | if ((error_num = spider_db_print_item_type(item_list[0], spider, |
3617 | str, alias, alias_length, dbton_id, use_fields, fields))) |
3618 | DBUG_RETURN(error_num); |
3619 | if (str) |
3620 | { |
3621 | if (item_date_add_interval->date_sub_interval) |
3622 | { |
3623 | if (str->reserve(SPIDER_SQL_MINUS_LEN)) |
3624 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3625 | str->q_append(SPIDER_SQL_MINUS_STR, SPIDER_SQL_MINUS_LEN); |
3626 | } else { |
3627 | if (str->reserve(SPIDER_SQL_PLUS_LEN)) |
3628 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3629 | str->q_append(SPIDER_SQL_PLUS_STR, SPIDER_SQL_PLUS_LEN); |
3630 | } |
3631 | } |
3632 | if ((error_num = spider_db_print_item_type(item_list[1], spider, |
3633 | str, alias, alias_length, dbton_id, use_fields, fields))) |
3634 | DBUG_RETURN(error_num); |
3635 | if (str) |
3636 | { |
3637 | if (item_date_add_interval->int_type == INTERVAL_WEEK) |
3638 | { |
3639 | func_name = " * 7" ; |
3640 | func_name_length = sizeof(" * 7" ) - 1; |
3641 | if (str->reserve(func_name_length + |
3642 | (SPIDER_SQL_CLOSE_PAREN_LEN))) |
3643 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3644 | str->q_append(func_name, func_name_length); |
3645 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3646 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3647 | } else if (item_date_add_interval->int_type == INTERVAL_HOUR) |
3648 | { |
3649 | func_name = " / 24" ; |
3650 | func_name_length = sizeof(" / 24" ) - 1; |
3651 | if (str->reserve(func_name_length + |
3652 | (SPIDER_SQL_CLOSE_PAREN_LEN))) |
3653 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3654 | str->q_append(func_name, func_name_length); |
3655 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3656 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3657 | } else if (item_date_add_interval->int_type == INTERVAL_MINUTE) |
3658 | { |
3659 | func_name = " / 1440" ; |
3660 | func_name_length = sizeof(" / 1440" ) - 1; |
3661 | if (str->reserve(func_name_length + |
3662 | (SPIDER_SQL_CLOSE_PAREN_LEN))) |
3663 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3664 | str->q_append(func_name, func_name_length); |
3665 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3666 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3667 | } else if (item_date_add_interval->int_type == INTERVAL_SECOND) |
3668 | { |
3669 | func_name = " / 86400" ; |
3670 | func_name_length = sizeof(" / 86400" ) - 1; |
3671 | if (str->reserve(func_name_length + |
3672 | (SPIDER_SQL_CLOSE_PAREN_LEN))) |
3673 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3674 | str->q_append(func_name, func_name_length); |
3675 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3676 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3677 | } else if (item_date_add_interval->int_type == |
3678 | INTERVAL_MICROSECOND) |
3679 | { |
3680 | func_name = " / 86400000000" ; |
3681 | func_name_length = sizeof(" / 86400000000" ) - 1; |
3682 | if (str->reserve(func_name_length + |
3683 | (SPIDER_SQL_CLOSE_PAREN_LEN))) |
3684 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3685 | str->q_append(func_name, func_name_length); |
3686 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3687 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3688 | } else { |
3689 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) |
3690 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3691 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3692 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3693 | } |
3694 | } |
3695 | break; |
3696 | default: |
3697 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3698 | } |
3699 | DBUG_RETURN(0); |
3700 | break; |
3701 | } |
3702 | } |
3703 | if (str) |
3704 | { |
3705 | if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) |
3706 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3707 | str->q_append(func_name, func_name_length); |
3708 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3709 | } |
3710 | func_name = SPIDER_SQL_COMMA_STR; |
3711 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3712 | separete_str = SPIDER_SQL_COMMA_STR; |
3713 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3714 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3715 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3716 | break; |
3717 | case Item_func::NOW_FUNC: |
3718 | if (str) |
3719 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3720 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
3721 | alias, alias_length, dbton_id, use_fields, fields)); |
3722 | case Item_func::CHAR_TYPECAST_FUNC: |
3723 | DBUG_PRINT("info" ,("spider CHAR_TYPECAST_FUNC" )); |
3724 | { |
3725 | item = item_list[0]; |
3726 | if (item->type() == Item::FUNC_ITEM) |
3727 | { |
3728 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3729 | Item_func *ifunc = (Item_func *) item; |
3730 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3731 | { |
3732 | const char *child_func_name; |
3733 | int child_func_name_length; |
3734 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3735 | child_func_name = (char*) ifunc->func_name(); |
3736 | child_func_name_length = strlen(child_func_name); |
3737 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3738 | if ( |
3739 | child_func_name_length == 10 && |
3740 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3741 | ) { |
3742 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3743 | merge_func = TRUE; |
3744 | } |
3745 | } |
3746 | } |
3747 | |
3748 | if (str) |
3749 | { |
3750 | char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; |
3751 | spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); |
3752 | tmp_str.init_calc_mem(125); |
3753 | tmp_str.length(0); |
3754 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3755 | if (!merge_func) |
3756 | { |
3757 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3758 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3759 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3760 | } |
3761 | #if MYSQL_VERSION_ID < 50500 |
3762 | item_func->print(tmp_str.get_str(), QT_IS); |
3763 | #else |
3764 | item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); |
3765 | #endif |
3766 | tmp_str.mem_calc(); |
3767 | if (tmp_str.reserve(1)) |
3768 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3769 | tmp_ptr = tmp_str.c_ptr_quick(); |
3770 | DBUG_PRINT("info" ,("spider tmp_ptr = %s" , tmp_ptr)); |
3771 | while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_CHAR_STR))) |
3772 | tmp_ptr = tmp_ptr2 + 1; |
3773 | last_str = tmp_ptr - 1; |
3774 | last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; |
3775 | } |
3776 | } |
3777 | break; |
3778 | case Item_func::NOT_FUNC: |
3779 | DBUG_PRINT("info" ,("spider NOT_FUNC" )); |
3780 | if (item_list[0]->type() == Item::COND_ITEM) |
3781 | { |
3782 | DBUG_PRINT("info" ,("spider item_list[0] is COND_ITEM" )); |
3783 | Item_cond *item_cond = (Item_cond *) item_list[0]; |
3784 | if (item_cond->functype() == Item_func::COND_AND_FUNC) |
3785 | { |
3786 | DBUG_PRINT("info" ,("spider item_cond is COND_AND_FUNC" )); |
3787 | List_iterator_fast<Item> lif(*(item_cond->argument_list())); |
3788 | bool has_expr_cache_item = FALSE; |
3789 | bool has_isnotnull_func = FALSE; |
3790 | bool has_other_item = FALSE; |
3791 | while((item = lif++)) |
3792 | { |
3793 | #ifdef SPIDER_HAS_EXPR_CACHE_ITEM |
3794 | if ( |
3795 | item->type() == Item::EXPR_CACHE_ITEM |
3796 | ) { |
3797 | DBUG_PRINT("info" ,("spider EXPR_CACHE_ITEM" )); |
3798 | has_expr_cache_item = TRUE; |
3799 | } else |
3800 | #endif |
3801 | if ( |
3802 | item->type() == Item::FUNC_ITEM && |
3803 | ((Item_func *) item)->functype() == Item_func::ISNOTNULL_FUNC |
3804 | ) { |
3805 | DBUG_PRINT("info" ,("spider ISNOTNULL_FUNC" )); |
3806 | has_isnotnull_func = TRUE; |
3807 | } else { |
3808 | DBUG_PRINT("info" ,("spider has other item" )); |
3809 | DBUG_PRINT("info" ,("spider COND type=%d" , item->type())); |
3810 | has_other_item = TRUE; |
3811 | } |
3812 | } |
3813 | if (has_expr_cache_item && has_isnotnull_func && !has_other_item) |
3814 | { |
3815 | DBUG_PRINT("info" ,("spider NOT EXISTS skip" )); |
3816 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3817 | } |
3818 | } |
3819 | } |
3820 | if (str) |
3821 | { |
3822 | func_name = (char*) item_func->func_name(); |
3823 | func_name_length = strlen(func_name); |
3824 | if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN)) |
3825 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3826 | str->q_append(func_name, func_name_length); |
3827 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
3828 | } |
3829 | break; |
3830 | case Item_func::NEG_FUNC: |
3831 | if (str) |
3832 | { |
3833 | func_name = (char*) item_func->func_name(); |
3834 | func_name_length = strlen(func_name); |
3835 | if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN)) |
3836 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3837 | str->q_append(func_name, func_name_length); |
3838 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
3839 | } |
3840 | break; |
3841 | case Item_func::IN_FUNC: |
3842 | if (((Item_func_opt_neg *) item_func)->negated) |
3843 | { |
3844 | func_name = SPIDER_SQL_NOT_IN_STR; |
3845 | func_name_length = SPIDER_SQL_NOT_IN_LEN; |
3846 | separete_str = SPIDER_SQL_COMMA_STR; |
3847 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3848 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3849 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3850 | } else { |
3851 | func_name = SPIDER_SQL_IN_STR; |
3852 | func_name_length = SPIDER_SQL_IN_LEN; |
3853 | separete_str = SPIDER_SQL_COMMA_STR; |
3854 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3855 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3856 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3857 | } |
3858 | break; |
3859 | case Item_func::BETWEEN: |
3860 | if (((Item_func_opt_neg *) item_func)->negated) |
3861 | { |
3862 | func_name = SPIDER_SQL_NOT_BETWEEN_STR; |
3863 | func_name_length = SPIDER_SQL_NOT_BETWEEN_LEN; |
3864 | separete_str = SPIDER_SQL_AND_STR; |
3865 | separete_str_length = SPIDER_SQL_AND_LEN; |
3866 | } else { |
3867 | func_name = (char*) item_func->func_name(); |
3868 | func_name_length = strlen(func_name); |
3869 | separete_str = SPIDER_SQL_AND_STR; |
3870 | separete_str_length = SPIDER_SQL_AND_LEN; |
3871 | } |
3872 | break; |
3873 | case Item_func::UDF_FUNC: |
3874 | use_pushdown_udf = spider_param_use_pushdown_udf(spider->trx->thd, |
3875 | spider->share->use_pushdown_udf); |
3876 | if (!use_pushdown_udf) |
3877 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3878 | if (str) |
3879 | { |
3880 | func_name = (char*) item_func->func_name(); |
3881 | func_name_length = strlen(func_name); |
3882 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
3883 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
3884 | if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) |
3885 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3886 | str->q_append(func_name, func_name_length); |
3887 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3888 | } |
3889 | func_name = SPIDER_SQL_COMMA_STR; |
3890 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3891 | separete_str = SPIDER_SQL_COMMA_STR; |
3892 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3893 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3894 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3895 | break; |
3896 | #ifdef MARIADB_BASE_VERSION |
3897 | case Item_func::XOR_FUNC: |
3898 | #else |
3899 | case Item_func::COND_XOR_FUNC: |
3900 | #endif |
3901 | if (str) |
3902 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3903 | DBUG_RETURN( |
3904 | spider_db_open_item_cond((Item_cond *) item_func, spider, str, |
3905 | alias, alias_length, dbton_id, use_fields, fields)); |
3906 | case Item_func::TRIG_COND_FUNC: |
3907 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3908 | case Item_func::GUSERVAR_FUNC: |
3909 | if (str) |
3910 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3911 | if (item_func->result_type() == STRING_RESULT) |
3912 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
3913 | alias, alias_length, dbton_id, use_fields, fields)); |
3914 | else |
3915 | DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, |
3916 | alias, alias_length, dbton_id, use_fields, fields)); |
3917 | case Item_func::FT_FUNC: |
3918 | if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) |
3919 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3920 | start_item = 1; |
3921 | if (str) |
3922 | { |
3923 | if (str->reserve(SPIDER_SQL_MATCH_LEN)) |
3924 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3925 | str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); |
3926 | } |
3927 | separete_str = SPIDER_SQL_COMMA_STR; |
3928 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3929 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3930 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3931 | break; |
3932 | case Item_func::SP_EQUALS_FUNC: |
3933 | if (str) |
3934 | { |
3935 | func_name = SPIDER_SQL_MBR_EQUAL_STR; |
3936 | func_name_length = SPIDER_SQL_MBR_EQUAL_LEN; |
3937 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
3938 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
3939 | if (str->reserve(func_name_length)) |
3940 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3941 | str->q_append(func_name, func_name_length); |
3942 | } |
3943 | func_name = SPIDER_SQL_COMMA_STR; |
3944 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3945 | separete_str = SPIDER_SQL_COMMA_STR; |
3946 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3947 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3948 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3949 | break; |
3950 | case Item_func::SP_DISJOINT_FUNC: |
3951 | case Item_func::SP_INTERSECTS_FUNC: |
3952 | case Item_func::SP_TOUCHES_FUNC: |
3953 | case Item_func::SP_CROSSES_FUNC: |
3954 | case Item_func::SP_WITHIN_FUNC: |
3955 | case Item_func::SP_CONTAINS_FUNC: |
3956 | case Item_func::SP_OVERLAPS_FUNC: |
3957 | if (str) |
3958 | { |
3959 | func_name = (char*) item_func->func_name(); |
3960 | func_name_length = strlen(func_name); |
3961 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
3962 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
3963 | if (str->reserve( |
3964 | #ifndef SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR |
3965 | SPIDER_SQL_MBR_LEN + |
3966 | #endif |
3967 | func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) |
3968 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3969 | #ifndef SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR |
3970 | str->q_append(SPIDER_SQL_MBR_STR, SPIDER_SQL_MBR_LEN); |
3971 | #endif |
3972 | str->q_append(func_name, func_name_length); |
3973 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3974 | } |
3975 | func_name = SPIDER_SQL_COMMA_STR; |
3976 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3977 | separete_str = SPIDER_SQL_COMMA_STR; |
3978 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3979 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3980 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3981 | break; |
3982 | case Item_func::EQ_FUNC: |
3983 | case Item_func::EQUAL_FUNC: |
3984 | case Item_func::NE_FUNC: |
3985 | case Item_func::LT_FUNC: |
3986 | case Item_func::LE_FUNC: |
3987 | case Item_func::GE_FUNC: |
3988 | case Item_func::GT_FUNC: |
3989 | case Item_func::LIKE_FUNC: |
3990 | if (str) |
3991 | { |
3992 | func_name = (char*) item_func->func_name(); |
3993 | func_name_length = strlen(func_name); |
3994 | } |
3995 | break; |
3996 | default: |
3997 | THD *thd = spider->trx->thd; |
3998 | SPIDER_SHARE *share = spider->share; |
3999 | if (spider_param_skip_default_condition(thd, |
4000 | share->skip_default_condition)) |
4001 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
4002 | if (str) |
4003 | { |
4004 | func_name = (char*) item_func->func_name(); |
4005 | func_name_length = strlen(func_name); |
4006 | } |
4007 | break; |
4008 | } |
4009 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
4010 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
4011 | DBUG_PRINT("info" ,("spider separete_str = %s" , separete_str)); |
4012 | DBUG_PRINT("info" ,("spider separete_str_length = %d" , separete_str_length)); |
4013 | DBUG_PRINT("info" ,("spider last_str = %s" , last_str)); |
4014 | DBUG_PRINT("info" ,("spider last_str_length = %d" , last_str_length)); |
4015 | if (item_count) |
4016 | { |
4017 | item_count--; |
4018 | for (roop_count = start_item; roop_count < item_count; roop_count++) |
4019 | { |
4020 | item = item_list[roop_count]; |
4021 | if ((error_num = spider_db_print_item_type(item, spider, str, |
4022 | alias, alias_length, dbton_id, use_fields, fields))) |
4023 | DBUG_RETURN(error_num); |
4024 | if (roop_count == 1) |
4025 | { |
4026 | func_name = separete_str; |
4027 | func_name_length = separete_str_length; |
4028 | } |
4029 | if (str) |
4030 | { |
4031 | if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN * 2)) |
4032 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4033 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
4034 | str->q_append(func_name, func_name_length); |
4035 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
4036 | } |
4037 | } |
4038 | item = item_list[roop_count]; |
4039 | if ((error_num = spider_db_print_item_type(item, spider, str, |
4040 | alias, alias_length, dbton_id, use_fields, fields))) |
4041 | DBUG_RETURN(error_num); |
4042 | } |
4043 | if (item_func->functype() == Item_func::FT_FUNC) |
4044 | { |
4045 | Item_func_match *item_func_match = (Item_func_match *)item_func; |
4046 | if (str) |
4047 | { |
4048 | if (str->reserve(SPIDER_SQL_AGAINST_LEN)) |
4049 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4050 | str->q_append(SPIDER_SQL_AGAINST_STR, SPIDER_SQL_AGAINST_LEN); |
4051 | } |
4052 | item = item_list[0]; |
4053 | if ((error_num = spider_db_print_item_type(item, spider, str, |
4054 | alias, alias_length, dbton_id, use_fields, fields))) |
4055 | DBUG_RETURN(error_num); |
4056 | if (str) |
4057 | { |
4058 | if (str->reserve( |
4059 | ((item_func_match->flags & FT_BOOL) ? |
4060 | SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + |
4061 | ((item_func_match->flags & FT_EXPAND) ? |
4062 | SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) |
4063 | )) |
4064 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4065 | if (item_func_match->flags & FT_BOOL) |
4066 | str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, |
4067 | SPIDER_SQL_IN_BOOLEAN_MODE_LEN); |
4068 | if (item_func_match->flags & FT_EXPAND) |
4069 | str->q_append(SPIDER_SQL_WITH_QUERY_EXPANSION_STR, |
4070 | SPIDER_SQL_WITH_QUERY_EXPANSION_LEN); |
4071 | } |
4072 | } else if (item_func->functype() == Item_func::UNKNOWN_FUNC) |
4073 | { |
4074 | if ( |
4075 | func_name_length == 7 && |
4076 | !strncasecmp("convert" , func_name, func_name_length) |
4077 | ) { |
4078 | if (str) |
4079 | { |
4080 | Item_func_conv_charset *item_func_conv_charset = |
4081 | (Item_func_conv_charset *)item_func; |
4082 | CHARSET_INFO *conv_charset = |
4083 | item_func_conv_charset->SPIDER_Item_func_conv_charset_conv_charset; |
4084 | uint cset_length = strlen(conv_charset->csname); |
4085 | if (str->reserve(SPIDER_SQL_USING_LEN + cset_length)) |
4086 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4087 | str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN); |
4088 | str->q_append(conv_charset->csname, cset_length); |
4089 | } |
4090 | } |
4091 | } |
4092 | if (str) |
4093 | { |
4094 | if (merge_func) |
4095 | str->length(str->length() - SPIDER_SQL_CLOSE_PAREN_LEN); |
4096 | if (str->reserve(last_str_length + SPIDER_SQL_CLOSE_PAREN_LEN)) |
4097 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4098 | str->q_append(last_str, last_str_length); |
4099 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
4100 | } |
4101 | DBUG_RETURN(0); |
4102 | } |
4103 | |
4104 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
4105 | int spider_db_oracle_util::open_item_sum_func( |
4106 | Item_sum *item_sum, |
4107 | ha_spider *spider, |
4108 | spider_string *str, |
4109 | const char *alias, |
4110 | uint alias_length, |
4111 | bool use_fields, |
4112 | spider_fields *fields |
4113 | ) { |
4114 | uint dbton_id = spider_dbton_oracle.dbton_id; |
4115 | uint roop_count, item_count = item_sum->get_arg_count(); |
4116 | int error_num; |
4117 | DBUG_ENTER("spider_db_oracle_util::open_item_sum_func" ); |
4118 | DBUG_PRINT("info" ,("spider Sumfunctype = %d" , item_sum->sum_func())); |
4119 | switch (item_sum->sum_func()) |
4120 | { |
4121 | case Item_sum::COUNT_FUNC: |
4122 | case Item_sum::SUM_FUNC: |
4123 | case Item_sum::MIN_FUNC: |
4124 | case Item_sum::MAX_FUNC: |
4125 | { |
4126 | const char *func_name = item_sum->func_name(); |
4127 | uint func_name_length = strlen(func_name); |
4128 | Item *item, **args = item_sum->get_args(); |
4129 | if (str) |
4130 | { |
4131 | if (str->reserve(func_name_length)) |
4132 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4133 | str->q_append(func_name, func_name_length); |
4134 | } |
4135 | if (item_count) |
4136 | { |
4137 | item_count--; |
4138 | for (roop_count = 0; roop_count < item_count; roop_count++) |
4139 | { |
4140 | item = args[roop_count]; |
4141 | if ((error_num = spider_db_print_item_type(item, spider, str, |
4142 | alias, alias_length, dbton_id, use_fields, fields))) |
4143 | DBUG_RETURN(error_num); |
4144 | if (str) |
4145 | { |
4146 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
4147 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4148 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
4149 | } |
4150 | } |
4151 | item = args[roop_count]; |
4152 | if ((error_num = spider_db_print_item_type(item, spider, str, |
4153 | alias, alias_length, dbton_id, use_fields, fields))) |
4154 | DBUG_RETURN(error_num); |
4155 | } |
4156 | if (str) |
4157 | { |
4158 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) |
4159 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4160 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
4161 | SPIDER_SQL_CLOSE_PAREN_LEN); |
4162 | } |
4163 | } |
4164 | break; |
4165 | case Item_sum::COUNT_DISTINCT_FUNC: |
4166 | case Item_sum::SUM_DISTINCT_FUNC: |
4167 | case Item_sum::AVG_FUNC: |
4168 | case Item_sum::AVG_DISTINCT_FUNC: |
4169 | case Item_sum::STD_FUNC: |
4170 | case Item_sum::VARIANCE_FUNC: |
4171 | case Item_sum::SUM_BIT_FUNC: |
4172 | case Item_sum::UDF_SUM_FUNC: |
4173 | case Item_sum::GROUP_CONCAT_FUNC: |
4174 | default: |
4175 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
4176 | } |
4177 | DBUG_RETURN(0); |
4178 | } |
4179 | #endif |
4180 | |
4181 | size_t spider_db_oracle_util::escape_string( |
4182 | char *to, |
4183 | const char *from, |
4184 | size_t from_length, |
4185 | CHARSET_INFO *access_charset |
4186 | ) { |
4187 | DBUG_ENTER("spider_db_oracle::escape_string" ); |
4188 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4189 | DBUG_RETURN(escape_quotes_for_mysql(access_charset, to, 0, |
4190 | from, from_length)); |
4191 | } |
4192 | |
4193 | int spider_db_oracle_util::append_escaped_util( |
4194 | spider_string *to, |
4195 | String *from |
4196 | ) { |
4197 | size_t copy_length; |
4198 | DBUG_ENTER("spider_db_oracle_util::append_escaped_util" ); |
4199 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4200 | DBUG_PRINT("info" ,("spider to=%s" , to->c_ptr_safe())); |
4201 | DBUG_PRINT("info" ,("spider from=%s" , from->c_ptr_safe())); |
4202 | copy_length = escape_string((char *) to->ptr() + to->length(), from->ptr(), |
4203 | from->length(), to->charset()); |
4204 | DBUG_PRINT("info" ,("spider copy_length=%zu" , copy_length)); |
4205 | to->length(to->length() + copy_length); |
4206 | to->mem_calc(); |
4207 | DBUG_RETURN(0); |
4208 | } |
4209 | |
4210 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
4211 | int spider_db_oracle_util::append_from_and_tables( |
4212 | spider_fields *fields, |
4213 | spider_string *str |
4214 | ) { |
4215 | SPIDER_TABLE_HOLDER *table_holder; |
4216 | int error_num; |
4217 | uint dbton_id = spider_dbton_oracle.dbton_id, from_length; |
4218 | spider_oracle_share *db_share; |
4219 | spider_oracle_handler *dbton_hdl; |
4220 | ha_spider *spider; |
4221 | DBUG_ENTER("spider_db_oracle_util::append_from_and_tables" ); |
4222 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4223 | |
4224 | /* calculate from size */ |
4225 | from_length = SPIDER_SQL_FROM_LEN; |
4226 | fields->set_pos_to_first_table_holder(); |
4227 | while ((table_holder = fields->get_next_table_holder())) |
4228 | { |
4229 | spider = table_holder->spider; |
4230 | db_share = (spider_oracle_share *) |
4231 | spider->share->dbton_share[dbton_id]; |
4232 | from_length += |
4233 | db_share->db_nm_max_length + |
4234 | SPIDER_SQL_DOT_LEN + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + |
4235 | db_share->table_nm_max_length + |
4236 | SPIDER_SQL_SPACE_LEN + SPIDER_SQL_COMMA_LEN + |
4237 | table_holder->alias->length() - SPIDER_SQL_DOT_LEN; |
4238 | } |
4239 | |
4240 | if (str->reserve(from_length)) |
4241 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4242 | str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
4243 | |
4244 | fields->set_pos_to_first_table_holder(); |
4245 | while ((table_holder = fields->get_next_table_holder())) |
4246 | { |
4247 | spider = table_holder->spider; |
4248 | db_share = (spider_oracle_share *) |
4249 | spider->share->dbton_share[dbton_id]; |
4250 | dbton_hdl = (spider_oracle_handler *) spider->dbton_handler[dbton_id]; |
4251 | dbton_hdl->table_name_pos = str->length(); |
4252 | if ((error_num = db_share->append_table_name_with_adjusting(str, |
4253 | spider->conn_link_idx[dbton_hdl->first_link_idx]))) |
4254 | { |
4255 | DBUG_RETURN(error_num); |
4256 | } |
4257 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
4258 | str->q_append(table_holder->alias->ptr(), |
4259 | table_holder->alias->length() - SPIDER_SQL_DOT_LEN); |
4260 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
4261 | } |
4262 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
4263 | DBUG_RETURN(0); |
4264 | } |
4265 | |
4266 | int spider_db_oracle_util::reappend_tables( |
4267 | spider_fields *fields, |
4268 | SPIDER_LINK_IDX_CHAIN *link_idx_chain, |
4269 | spider_string *str |
4270 | ) { |
4271 | int error_num; |
4272 | uint dbton_id = spider_dbton_oracle.dbton_id, length; |
4273 | ha_spider *spider; |
4274 | spider_oracle_share *db_share; |
4275 | spider_oracle_handler *dbton_hdl; |
4276 | SPIDER_TABLE_HOLDER *table_holder; |
4277 | SPIDER_LINK_IDX_HOLDER *link_idx_holder; |
4278 | DBUG_ENTER("spider_db_oracle_util::reappend_tables" ); |
4279 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4280 | length = str->length(); |
4281 | fields->set_pos_to_first_table_on_link_idx_chain(link_idx_chain); |
4282 | fields->set_pos_to_first_table_holder(); |
4283 | while ((table_holder = fields->get_next_table_holder())) |
4284 | { |
4285 | link_idx_holder = fields->get_next_table_on_link_idx_chain(link_idx_chain); |
4286 | spider = table_holder->spider; |
4287 | db_share = (spider_oracle_share *) |
4288 | spider->share->dbton_share[dbton_id]; |
4289 | if (!db_share->same_db_table_name) |
4290 | { |
4291 | dbton_hdl = (spider_oracle_handler *) spider->dbton_handler[dbton_id]; |
4292 | str->length(dbton_hdl->table_name_pos); |
4293 | if ((error_num = db_share->append_table_name_with_adjusting(str, |
4294 | spider->conn_link_idx[link_idx_holder->link_idx]))) |
4295 | { |
4296 | DBUG_RETURN(error_num); |
4297 | } |
4298 | } |
4299 | } |
4300 | str->length(length); |
4301 | DBUG_RETURN(0); |
4302 | } |
4303 | |
4304 | int spider_db_oracle_util::append_where( |
4305 | spider_string *str |
4306 | ) { |
4307 | DBUG_ENTER("spider_db_oracle_util::append_where" ); |
4308 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4309 | if (str->reserve(SPIDER_SQL_WHERE_LEN)) |
4310 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4311 | str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); |
4312 | DBUG_RETURN(0); |
4313 | } |
4314 | |
4315 | int spider_db_oracle_util::append_having( |
4316 | spider_string *str |
4317 | ) { |
4318 | DBUG_ENTER("spider_db_oracle_util::append_having" ); |
4319 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4320 | if (str->reserve(SPIDER_SQL_HAVING_LEN)) |
4321 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4322 | str->q_append(SPIDER_SQL_HAVING_STR, SPIDER_SQL_HAVING_LEN); |
4323 | DBUG_RETURN(0); |
4324 | } |
4325 | #endif |
4326 | |
4327 | spider_oracle_share::spider_oracle_share( |
4328 | st_spider_share *share |
4329 | ) : spider_db_share( |
4330 | share |
4331 | ), |
4332 | table_select(NULL), |
4333 | table_select_pos(0), |
4334 | key_select(NULL), |
4335 | key_select_pos(NULL), |
4336 | key_hint(NULL), |
4337 | show_table_status(NULL), |
4338 | show_records(NULL), |
4339 | show_autoinc(NULL), |
4340 | show_last_insert_id(NULL), |
4341 | show_index(NULL), |
4342 | table_names_str(NULL), |
4343 | db_names_str(NULL), |
4344 | db_table_str(NULL), |
4345 | nextval_str(NULL), |
4346 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
4347 | db_table_str_hash_value(NULL), |
4348 | #endif |
4349 | table_nm_max_length(0), |
4350 | db_nm_max_length(0), |
4351 | nextval_max_length(0), |
4352 | column_name_str(NULL), |
4353 | same_db_table_name(TRUE), |
4354 | first_all_link_idx(-1) |
4355 | { |
4356 | DBUG_ENTER("spider_oracle_share::spider_oracle_share" ); |
4357 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4358 | spider_alloc_calc_mem_init(mem_calc, 220); |
4359 | spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); |
4360 | DBUG_VOID_RETURN; |
4361 | } |
4362 | |
4363 | spider_oracle_share::~spider_oracle_share() |
4364 | { |
4365 | DBUG_ENTER("spider_oracle_share::~spider_oracle_share" ); |
4366 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4367 | if (table_select) |
4368 | delete [] table_select; |
4369 | if (key_select) |
4370 | delete [] key_select; |
4371 | if (key_hint) |
4372 | delete [] key_hint; |
4373 | free_show_table_status(); |
4374 | free_show_records(); |
4375 | free_show_autoinc(); |
4376 | free_show_last_insert_id(); |
4377 | free_show_index(); |
4378 | free_column_name_str(); |
4379 | free_table_names_str(); |
4380 | if (key_select_pos) |
4381 | { |
4382 | spider_free(spider_current_trx, key_select_pos, MYF(0)); |
4383 | } |
4384 | spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); |
4385 | DBUG_VOID_RETURN; |
4386 | } |
4387 | |
4388 | int spider_oracle_share::init() |
4389 | { |
4390 | int error_num; |
4391 | uint roop_count; |
4392 | TABLE_SHARE *table_share = spider_share->table_share; |
4393 | uint keys = table_share ? table_share->keys : 0; |
4394 | DBUG_ENTER("spider_oracle_share::init" ); |
4395 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4396 | if (!(key_select_pos = (int *) |
4397 | spider_bulk_alloc_mem(spider_current_trx, 221, |
4398 | __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), |
4399 | &key_select_pos, |
4400 | sizeof(int) * keys, |
4401 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
4402 | &db_table_str_hash_value, |
4403 | sizeof(my_hash_value_type) * spider_share->all_link_count, |
4404 | #endif |
4405 | NullS)) |
4406 | ) { |
4407 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4408 | } |
4409 | |
4410 | if (keys > 0 && |
4411 | !(key_hint = new spider_string[keys]) |
4412 | ) { |
4413 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4414 | } |
4415 | for (roop_count = 0; roop_count < keys; roop_count++) |
4416 | { |
4417 | key_hint[roop_count].init_calc_mem(190); |
4418 | key_hint[roop_count].set_charset(spider_share->access_charset); |
4419 | } |
4420 | DBUG_PRINT("info" ,("spider key_hint=%p" , key_hint)); |
4421 | |
4422 | if ( |
4423 | !(table_select = new spider_string[1]) || |
4424 | (keys > 0 && |
4425 | !(key_select = new spider_string[keys]) |
4426 | ) || |
4427 | (error_num = create_table_names_str()) || |
4428 | (table_share && |
4429 | ( |
4430 | (error_num = create_column_name_str()) || |
4431 | (error_num = convert_key_hint_str()) || |
4432 | (error_num = append_show_table_status()) || |
4433 | (error_num = append_show_records()) || |
4434 | (error_num = append_show_autoinc()) || |
4435 | (error_num = append_show_last_insert_id()) || |
4436 | (error_num = append_show_index()) |
4437 | ) |
4438 | ) |
4439 | ) { |
4440 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4441 | } |
4442 | |
4443 | table_select->init_calc_mem(191); |
4444 | if (table_share && (error_num = append_table_select())) |
4445 | DBUG_RETURN(error_num); |
4446 | |
4447 | for (roop_count = 0; roop_count < keys; roop_count++) |
4448 | { |
4449 | key_select[roop_count].init_calc_mem(192); |
4450 | if ((error_num = append_key_select(roop_count))) |
4451 | DBUG_RETURN(error_num); |
4452 | } |
4453 | |
4454 | DBUG_RETURN(error_num); |
4455 | } |
4456 | |
4457 | uint spider_oracle_share::get_column_name_length( |
4458 | uint field_index |
4459 | ) { |
4460 | DBUG_ENTER("spider_oracle_share::get_column_name_length" ); |
4461 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4462 | DBUG_RETURN(column_name_str[field_index].length()); |
4463 | } |
4464 | |
4465 | int spider_oracle_share::append_column_name( |
4466 | spider_string *str, |
4467 | uint field_index |
4468 | ) { |
4469 | int error_num; |
4470 | DBUG_ENTER("spider_oracle_share::append_column_name" ); |
4471 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4472 | error_num = spider_db_oracle_utility.append_name(str, |
4473 | column_name_str[field_index].ptr(), column_name_str[field_index].length()); |
4474 | DBUG_RETURN(error_num); |
4475 | } |
4476 | |
4477 | int spider_oracle_share::append_column_name_with_alias( |
4478 | spider_string *str, |
4479 | uint field_index, |
4480 | const char *alias, |
4481 | uint alias_length |
4482 | ) { |
4483 | DBUG_ENTER("spider_oracle_share::append_column_name_with_alias" ); |
4484 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4485 | if (str->reserve( |
4486 | alias_length + |
4487 | column_name_str[field_index].length() + |
4488 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) |
4489 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4490 | str->q_append(alias, alias_length); |
4491 | append_column_name(str, field_index); |
4492 | DBUG_RETURN(0); |
4493 | } |
4494 | |
4495 | int spider_oracle_share::append_table_name( |
4496 | spider_string *str, |
4497 | int all_link_idx |
4498 | ) { |
4499 | const char *db_nm = db_names_str[all_link_idx].ptr(); |
4500 | uint db_nm_len = db_names_str[all_link_idx].length(); |
4501 | const char *table_nm = table_names_str[all_link_idx].ptr(); |
4502 | uint table_nm_len = table_names_str[all_link_idx].length(); |
4503 | DBUG_ENTER("spider_oracle_share::append_table_name" ); |
4504 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4505 | if (str->reserve(db_nm_len + SPIDER_SQL_DOT_LEN + table_nm_len + |
4506 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) |
4507 | { |
4508 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4509 | } |
4510 | spider_db_oracle_utility.append_name(str, db_nm, db_nm_len); |
4511 | str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); |
4512 | spider_db_oracle_utility.append_name(str, table_nm, table_nm_len); |
4513 | DBUG_RETURN(0); |
4514 | } |
4515 | |
4516 | int spider_oracle_share::append_table_name_with_adjusting( |
4517 | spider_string *str, |
4518 | int all_link_idx |
4519 | ) { |
4520 | const char *db_nm = db_names_str[all_link_idx].ptr(); |
4521 | uint db_nm_len = db_names_str[all_link_idx].length(); |
4522 | uint db_nm_max_len = db_nm_max_length; |
4523 | const char *table_nm = table_names_str[all_link_idx].ptr(); |
4524 | uint table_nm_len = table_names_str[all_link_idx].length(); |
4525 | uint table_nm_max_len = table_nm_max_length; |
4526 | DBUG_ENTER("spider_oracle_share::append_table_name_with_adjusting" ); |
4527 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4528 | spider_db_oracle_utility.append_name(str, db_nm, db_nm_len); |
4529 | str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); |
4530 | spider_db_oracle_utility.append_name(str, table_nm, table_nm_len); |
4531 | uint length = |
4532 | db_nm_max_len - db_nm_len + |
4533 | table_nm_max_len - table_nm_len; |
4534 | memset((char *) str->ptr() + str->length(), ' ', length); |
4535 | str->length(str->length() + length); |
4536 | DBUG_RETURN(0); |
4537 | } |
4538 | |
4539 | int spider_oracle_share::append_from_with_adjusted_table_name( |
4540 | spider_string *str, |
4541 | int *table_name_pos |
4542 | ) { |
4543 | const char *db_nm = db_names_str[0].ptr(); |
4544 | uint db_nm_len = db_names_str[0].length(); |
4545 | uint db_nm_max_len = db_nm_max_length; |
4546 | const char *table_nm = table_names_str[0].ptr(); |
4547 | uint table_nm_len = table_names_str[0].length(); |
4548 | uint table_nm_max_len = table_nm_max_length; |
4549 | DBUG_ENTER("spider_oracle_share::append_from_with_adjusted_table_name" ); |
4550 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4551 | if (str->reserve(SPIDER_SQL_FROM_LEN + db_nm_max_length + |
4552 | SPIDER_SQL_DOT_LEN + table_nm_max_length + |
4553 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) |
4554 | { |
4555 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4556 | } |
4557 | str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
4558 | *table_name_pos = str->length(); |
4559 | spider_db_oracle_utility.append_name(str, db_nm, db_nm_len); |
4560 | str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); |
4561 | spider_db_oracle_utility.append_name(str, table_nm, table_nm_len); |
4562 | uint length = |
4563 | db_nm_max_len - db_nm_len + |
4564 | table_nm_max_len - table_nm_len; |
4565 | memset((char *) str->ptr() + str->length(), ' ', length); |
4566 | str->length(str->length() + length); |
4567 | DBUG_RETURN(0); |
4568 | } |
4569 | |
4570 | int spider_oracle_share::create_table_names_str() |
4571 | { |
4572 | int error_num, roop_count; |
4573 | uint table_nm_len, db_nm_len; |
4574 | spider_string *str, *first_tbl_nm_str, *first_db_nm_str, *first_db_tbl_str; |
4575 | char *first_tbl_nm, *first_db_nm; |
4576 | uint dbton_id = spider_dbton_oracle.dbton_id; |
4577 | DBUG_ENTER("spider_oracle_share::create_table_names_str" ); |
4578 | table_names_str = NULL; |
4579 | db_names_str = NULL; |
4580 | db_table_str = NULL; |
4581 | if ( |
4582 | !(table_names_str = new spider_string[spider_share->all_link_count]) || |
4583 | !(db_names_str = new spider_string[spider_share->all_link_count]) || |
4584 | !(db_table_str = new spider_string[spider_share->all_link_count]) |
4585 | ) { |
4586 | error_num = HA_ERR_OUT_OF_MEM; |
4587 | goto error; |
4588 | } |
4589 | |
4590 | same_db_table_name = TRUE; |
4591 | first_tbl_nm = spider_share->tgt_table_names[0]; |
4592 | first_db_nm = spider_share->tgt_dbs[0]; |
4593 | table_nm_len = spider_share->tgt_table_names_lengths[0]; |
4594 | db_nm_len = spider_share->tgt_dbs_lengths[0]; |
4595 | first_tbl_nm_str = &table_names_str[0]; |
4596 | first_db_nm_str = &db_names_str[0]; |
4597 | first_db_tbl_str = &db_table_str[0]; |
4598 | for (roop_count = 0; roop_count < (int) spider_share->all_link_count; |
4599 | roop_count++) |
4600 | { |
4601 | table_names_str[roop_count].init_calc_mem(193); |
4602 | db_names_str[roop_count].init_calc_mem(194); |
4603 | db_table_str[roop_count].init_calc_mem(195); |
4604 | if (spider_share->sql_dbton_ids[roop_count] != dbton_id) |
4605 | continue; |
4606 | if (first_all_link_idx == -1) |
4607 | first_all_link_idx = roop_count; |
4608 | |
4609 | str = &table_names_str[roop_count]; |
4610 | if ( |
4611 | roop_count != 0 && |
4612 | same_db_table_name && |
4613 | spider_share->tgt_table_names_lengths[roop_count] == table_nm_len && |
4614 | !memcmp(first_tbl_nm, spider_share->tgt_table_names[roop_count], |
4615 | table_nm_len) |
4616 | ) { |
4617 | if (str->copy(*first_tbl_nm_str)) |
4618 | { |
4619 | error_num = HA_ERR_OUT_OF_MEM; |
4620 | goto error; |
4621 | } |
4622 | } else { |
4623 | str->set_charset(spider_share->access_charset); |
4624 | if ((error_num = spider_db_append_name_with_quote_str(str, |
4625 | spider_share->tgt_table_names[roop_count], dbton_id))) |
4626 | goto error; |
4627 | if (roop_count) |
4628 | { |
4629 | same_db_table_name = FALSE; |
4630 | DBUG_PRINT("info" , ("spider found different table name %s" , |
4631 | spider_share->tgt_table_names[roop_count])); |
4632 | if (str->length() > table_nm_max_length) |
4633 | table_nm_max_length = str->length(); |
4634 | } else |
4635 | table_nm_max_length = str->length(); |
4636 | } |
4637 | |
4638 | str = &db_names_str[roop_count]; |
4639 | if ( |
4640 | roop_count != 0 && |
4641 | same_db_table_name && |
4642 | spider_share->tgt_dbs_lengths[roop_count] == db_nm_len && |
4643 | !memcmp(first_db_nm, spider_share->tgt_dbs[roop_count], |
4644 | db_nm_len) |
4645 | ) { |
4646 | if (str->copy(*first_db_nm_str)) |
4647 | { |
4648 | error_num = HA_ERR_OUT_OF_MEM; |
4649 | goto error; |
4650 | } |
4651 | } else { |
4652 | str->set_charset(spider_share->access_charset); |
4653 | if ((error_num = spider_db_append_name_with_quote_str(str, |
4654 | spider_share->tgt_dbs[roop_count], dbton_id))) |
4655 | goto error; |
4656 | if (roop_count) |
4657 | { |
4658 | same_db_table_name = FALSE; |
4659 | DBUG_PRINT("info" , ("spider found different db name %s" , |
4660 | spider_share->tgt_dbs[roop_count])); |
4661 | if (str->length() > db_nm_max_length) |
4662 | db_nm_max_length = str->length(); |
4663 | } else |
4664 | db_nm_max_length = str->length(); |
4665 | } |
4666 | |
4667 | str = &db_table_str[roop_count]; |
4668 | if ( |
4669 | roop_count != 0 && |
4670 | same_db_table_name |
4671 | ) { |
4672 | if (str->copy(*first_db_tbl_str)) |
4673 | { |
4674 | error_num = HA_ERR_OUT_OF_MEM; |
4675 | goto error; |
4676 | } |
4677 | } else { |
4678 | str->set_charset(spider_share->access_charset); |
4679 | if ((error_num = append_table_name(str, roop_count))) |
4680 | goto error; |
4681 | } |
4682 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
4683 | db_table_str_hash_value[roop_count] = my_calc_hash( |
4684 | &spider_open_connections, (uchar*) str->ptr(), str->length()); |
4685 | #endif |
4686 | } |
4687 | DBUG_RETURN(0); |
4688 | |
4689 | error: |
4690 | if (db_table_str) |
4691 | { |
4692 | delete [] db_table_str; |
4693 | db_table_str = NULL; |
4694 | } |
4695 | if (db_names_str) |
4696 | { |
4697 | delete [] db_names_str; |
4698 | db_names_str = NULL; |
4699 | } |
4700 | if (table_names_str) |
4701 | { |
4702 | delete [] table_names_str; |
4703 | table_names_str = NULL; |
4704 | } |
4705 | DBUG_RETURN(error_num); |
4706 | } |
4707 | |
4708 | void spider_oracle_share::free_table_names_str() |
4709 | { |
4710 | DBUG_ENTER("spider_oracle_share::free_table_names_str" ); |
4711 | if (db_table_str) |
4712 | { |
4713 | delete [] db_table_str; |
4714 | db_table_str = NULL; |
4715 | } |
4716 | if (db_names_str) |
4717 | { |
4718 | delete [] db_names_str; |
4719 | db_names_str = NULL; |
4720 | } |
4721 | if (table_names_str) |
4722 | { |
4723 | delete [] table_names_str; |
4724 | table_names_str = NULL; |
4725 | } |
4726 | DBUG_VOID_RETURN; |
4727 | } |
4728 | |
4729 | int spider_oracle_share::create_column_name_str() |
4730 | { |
4731 | spider_string *str; |
4732 | int error_num; |
4733 | Field **field; |
4734 | TABLE_SHARE *table_share = spider_share->table_share; |
4735 | uint dbton_id = spider_dbton_oracle.dbton_id; |
4736 | DBUG_ENTER("spider_oracle_share::create_column_name_str" ); |
4737 | if ( |
4738 | table_share->fields && |
4739 | !(column_name_str = new spider_string[table_share->fields]) |
4740 | ) |
4741 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4742 | for (field = table_share->field, str = column_name_str; |
4743 | *field; field++, str++) |
4744 | { |
4745 | str->init_calc_mem(196); |
4746 | str->set_charset(spider_share->access_charset); |
4747 | if ((error_num = spider_db_append_name_with_quote_str(str, |
4748 | (char *) (*field)->field_name.str, dbton_id))) |
4749 | goto error; |
4750 | } |
4751 | DBUG_RETURN(0); |
4752 | |
4753 | error: |
4754 | if (column_name_str) |
4755 | { |
4756 | delete [] column_name_str; |
4757 | column_name_str = NULL; |
4758 | } |
4759 | DBUG_RETURN(error_num); |
4760 | } |
4761 | |
4762 | void spider_oracle_share::free_column_name_str() |
4763 | { |
4764 | DBUG_ENTER("spider_oracle_share::free_column_name_str" ); |
4765 | if (column_name_str) |
4766 | { |
4767 | delete [] column_name_str; |
4768 | column_name_str = NULL; |
4769 | } |
4770 | DBUG_VOID_RETURN; |
4771 | } |
4772 | |
4773 | int spider_oracle_share::convert_key_hint_str() |
4774 | { |
4775 | spider_string *tmp_key_hint; |
4776 | int roop_count; |
4777 | TABLE_SHARE *table_share = spider_share->table_share; |
4778 | DBUG_ENTER("spider_oracle_share::convert_key_hint_str" ); |
4779 | if (spider_share->access_charset->cset != system_charset_info->cset) |
4780 | { |
4781 | /* need convertion */ |
4782 | for (roop_count = 0, tmp_key_hint = key_hint; |
4783 | roop_count < (int) table_share->keys; roop_count++, tmp_key_hint++) |
4784 | { |
4785 | tmp_key_hint->length(0); |
4786 | if (tmp_key_hint->append(spider_share->key_hint->ptr(), |
4787 | spider_share->key_hint->length(), system_charset_info)) |
4788 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4789 | } |
4790 | } else { |
4791 | for (roop_count = 0, tmp_key_hint = key_hint; |
4792 | roop_count < (int) table_share->keys; roop_count++, tmp_key_hint++) |
4793 | { |
4794 | if (tmp_key_hint->copy(spider_share->key_hint[roop_count])) |
4795 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4796 | } |
4797 | } |
4798 | DBUG_RETURN(0); |
4799 | } |
4800 | |
4801 | int spider_oracle_share::append_show_table_status() |
4802 | { |
4803 | int roop_count; |
4804 | spider_string *str; |
4805 | uint dbton_id = spider_dbton_oracle.dbton_id; |
4806 | DBUG_ENTER("spider_oracle_append_show_table_status" ); |
4807 | if (!(show_table_status = |
4808 | new spider_string[2 * spider_share->all_link_count])) |
4809 | goto error; |
4810 | |
4811 | for (roop_count = 0; roop_count < (int) spider_share->all_link_count; |
4812 | roop_count++) |
4813 | { |
4814 | show_table_status[0 + (2 * roop_count)].init_calc_mem(197); |
4815 | show_table_status[1 + (2 * roop_count)].init_calc_mem(207); |
4816 | if (spider_share->sql_dbton_ids[roop_count] != dbton_id) |
4817 | continue; |
4818 | |
4819 | if ( |
4820 | show_table_status[0 + (2 * roop_count)].reserve( |
4821 | SPIDER_SQL_SHOW_TABLE_STATUS_LEN + |
4822 | db_names_str[roop_count].length() + |
4823 | SPIDER_SQL_LIKE_LEN + table_names_str[roop_count].length() + |
4824 | ((SPIDER_SQL_NAME_QUOTE_LEN) * 2) + |
4825 | ((SPIDER_SQL_VALUE_QUOTE_LEN) * 2)) || |
4826 | show_table_status[1 + (2 * roop_count)].reserve( |
4827 | SPIDER_SQL_SELECT_TABLES_STATUS_LEN + |
4828 | db_names_str[roop_count].length() + |
4829 | SPIDER_SQL_AND_LEN + SPIDER_SQL_TABLE_NAME_LEN + SPIDER_SQL_EQUAL_LEN + |
4830 | table_names_str[roop_count].length() + |
4831 | ((SPIDER_SQL_VALUE_QUOTE_LEN) * 4)) |
4832 | ) |
4833 | goto error; |
4834 | str = &show_table_status[0 + (2 * roop_count)]; |
4835 | str->q_append( |
4836 | SPIDER_SQL_SHOW_TABLE_STATUS_STR, SPIDER_SQL_SHOW_TABLE_STATUS_LEN); |
4837 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
4838 | str->q_append(db_names_str[roop_count].ptr(), |
4839 | db_names_str[roop_count].length()); |
4840 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
4841 | str->q_append(SPIDER_SQL_LIKE_STR, SPIDER_SQL_LIKE_LEN); |
4842 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
4843 | str->q_append(table_names_str[roop_count].ptr(), |
4844 | table_names_str[roop_count].length()); |
4845 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
4846 | str = &show_table_status[1 + (2 * roop_count)]; |
4847 | str->q_append( |
4848 | SPIDER_SQL_SELECT_TABLES_STATUS_STR, |
4849 | SPIDER_SQL_SELECT_TABLES_STATUS_LEN); |
4850 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
4851 | str->q_append(db_names_str[roop_count].ptr(), |
4852 | db_names_str[roop_count].length()); |
4853 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
4854 | str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
4855 | str->q_append(SPIDER_SQL_TABLE_NAME_STR, SPIDER_SQL_TABLE_NAME_LEN); |
4856 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
4857 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
4858 | str->q_append(table_names_str[roop_count].ptr(), |
4859 | table_names_str[roop_count].length()); |
4860 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
4861 | } |
4862 | DBUG_RETURN(0); |
4863 | |
4864 | error: |
4865 | if (show_table_status) |
4866 | { |
4867 | delete [] show_table_status; |
4868 | show_table_status = NULL; |
4869 | } |
4870 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4871 | } |
4872 | |
4873 | void spider_oracle_share::free_show_table_status() |
4874 | { |
4875 | DBUG_ENTER("spider_oracle_free_show_table_status" ); |
4876 | if (show_table_status) |
4877 | { |
4878 | delete [] show_table_status; |
4879 | show_table_status = NULL; |
4880 | } |
4881 | DBUG_VOID_RETURN; |
4882 | } |
4883 | |
4884 | int spider_oracle_share::append_show_records() |
4885 | { |
4886 | int roop_count; |
4887 | spider_string *str; |
4888 | uint dbton_id = spider_dbton_oracle.dbton_id; |
4889 | DBUG_ENTER("spider_oracle_share::append_show_records" ); |
4890 | if (!(show_records = new spider_string[spider_share->all_link_count])) |
4891 | goto error; |
4892 | |
4893 | for (roop_count = 0; roop_count < (int) spider_share->all_link_count; |
4894 | roop_count++) |
4895 | { |
4896 | show_records[roop_count].init_calc_mem(208); |
4897 | if (spider_share->sql_dbton_ids[roop_count] != dbton_id) |
4898 | continue; |
4899 | |
4900 | if ( |
4901 | show_records[roop_count].reserve( |
4902 | SPIDER_SQL_SHOW_RECORDS_LEN + |
4903 | db_names_str[roop_count].length() + |
4904 | SPIDER_SQL_DOT_LEN + |
4905 | table_names_str[roop_count].length() + |
4906 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4) |
4907 | ) |
4908 | goto error; |
4909 | str = &show_records[roop_count]; |
4910 | str->q_append(SPIDER_SQL_SHOW_RECORDS_STR, SPIDER_SQL_SHOW_RECORDS_LEN); |
4911 | append_table_name(str, roop_count); |
4912 | } |
4913 | DBUG_RETURN(0); |
4914 | |
4915 | error: |
4916 | if (show_records) |
4917 | { |
4918 | delete [] show_records; |
4919 | show_records = NULL; |
4920 | } |
4921 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4922 | } |
4923 | |
4924 | void spider_oracle_share::free_show_records() |
4925 | { |
4926 | DBUG_ENTER("spider_oracle_share::free_show_records" ); |
4927 | if (show_records) |
4928 | { |
4929 | delete [] show_records; |
4930 | show_records = NULL; |
4931 | } |
4932 | DBUG_VOID_RETURN; |
4933 | } |
4934 | |
4935 | int spider_oracle_share::append_show_autoinc() |
4936 | { |
4937 | uint roop_count, field_length; |
4938 | spider_string *str; |
4939 | uint dbton_id = spider_dbton_oracle.dbton_id; |
4940 | Field **found_next_number_field = |
4941 | spider_share->table_share->found_next_number_field; |
4942 | DBUG_ENTER("spider_oracle_share::append_show_autoinc" ); |
4943 | if (!found_next_number_field) |
4944 | DBUG_RETURN(0); |
4945 | |
4946 | if (!(show_autoinc = new spider_string[spider_share->all_link_count])) |
4947 | goto error; |
4948 | |
4949 | field_length = |
4950 | column_name_str[(*found_next_number_field)->field_index].length(); |
4951 | for (roop_count = 0; roop_count < spider_share->all_link_count; |
4952 | roop_count++) |
4953 | { |
4954 | show_autoinc[roop_count].init_calc_mem(224); |
4955 | if (spider_share->sql_dbton_ids[roop_count] != dbton_id) |
4956 | continue; |
4957 | |
4958 | if ( |
4959 | show_autoinc[roop_count].reserve( |
4960 | SPIDER_SQL_SELECT_LEN + |
4961 | SPIDER_SQL_MAX_LEN + |
4962 | SPIDER_SQL_OPEN_PAREN_LEN + |
4963 | field_length + |
4964 | SPIDER_SQL_CLOSE_PAREN_LEN + |
4965 | SPIDER_SQL_FROM_LEN + |
4966 | db_names_str[roop_count].length() + |
4967 | SPIDER_SQL_DOT_LEN + |
4968 | table_names_str[roop_count].length() + |
4969 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 6) |
4970 | ) |
4971 | goto error; |
4972 | str = &show_autoinc[roop_count]; |
4973 | str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); |
4974 | str->q_append(SPIDER_SQL_MAX_STR, SPIDER_SQL_MAX_LEN); |
4975 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
4976 | append_column_name(str, (*found_next_number_field)->field_index); |
4977 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
4978 | str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
4979 | append_table_name(str, roop_count); |
4980 | } |
4981 | DBUG_RETURN(0); |
4982 | |
4983 | error: |
4984 | if (show_autoinc) |
4985 | { |
4986 | delete [] show_autoinc; |
4987 | show_autoinc = NULL; |
4988 | } |
4989 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4990 | } |
4991 | |
4992 | void spider_oracle_share::free_show_autoinc() |
4993 | { |
4994 | DBUG_ENTER("spider_oracle_share::free_show_autoinc" ); |
4995 | if (show_autoinc) |
4996 | { |
4997 | delete [] show_autoinc; |
4998 | show_autoinc = NULL; |
4999 | } |
5000 | DBUG_VOID_RETURN; |
5001 | } |
5002 | |
5003 | int spider_oracle_share::append_show_last_insert_id() |
5004 | { |
5005 | uint roop_count; |
5006 | spider_string *str; |
5007 | uint dbton_id = spider_dbton_oracle.dbton_id; |
5008 | Field **found_next_number_field = |
5009 | spider_share->table_share->found_next_number_field; |
5010 | uint seq_nm_max_length = 0; |
5011 | DBUG_ENTER("spider_oracle_share::append_show_last_insert_id" ); |
5012 | if (!found_next_number_field) |
5013 | DBUG_RETURN(0); |
5014 | |
5015 | if ( |
5016 | !(show_last_insert_id = new spider_string[spider_share->all_link_count]) || |
5017 | !(nextval_str = new spider_string[spider_share->all_link_count]) |
5018 | ) |
5019 | goto error; |
5020 | |
5021 | for (roop_count = 0; roop_count < spider_share->all_link_count; |
5022 | roop_count++) |
5023 | { |
5024 | show_last_insert_id[roop_count].init_calc_mem(225); |
5025 | nextval_str[roop_count].init_calc_mem(226); |
5026 | if (spider_share->sql_dbton_ids[roop_count] != dbton_id) |
5027 | continue; |
5028 | |
5029 | if ( |
5030 | show_last_insert_id[roop_count].reserve( |
5031 | SPIDER_SQL_SELECT_LEN + |
5032 | spider_share->tgt_sequence_names_lengths[roop_count] + |
5033 | SPIDER_SQL_CURRVAL_LEN + |
5034 | SPIDER_SQL_FROM_DUAL_LEN + |
5035 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2) |
5036 | ) |
5037 | goto error; |
5038 | str = &show_last_insert_id[roop_count]; |
5039 | str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); |
5040 | spider_db_oracle_utility.append_name(str, |
5041 | spider_share->tgt_sequence_names[roop_count], |
5042 | spider_share->tgt_sequence_names_lengths[roop_count]); |
5043 | str->q_append(SPIDER_SQL_CURRVAL_STR, SPIDER_SQL_CURRVAL_LEN); |
5044 | str->q_append(SPIDER_SQL_FROM_DUAL_STR, SPIDER_SQL_FROM_DUAL_LEN); |
5045 | |
5046 | if (seq_nm_max_length < |
5047 | spider_share->tgt_sequence_names_lengths[roop_count]) |
5048 | { |
5049 | seq_nm_max_length = |
5050 | spider_share->tgt_sequence_names_lengths[roop_count]; |
5051 | } |
5052 | } |
5053 | for (roop_count = 0; roop_count < spider_share->all_link_count; |
5054 | roop_count++) |
5055 | { |
5056 | if (spider_share->sql_dbton_ids[roop_count] != dbton_id) |
5057 | continue; |
5058 | |
5059 | if ( |
5060 | nextval_str[roop_count].reserve( |
5061 | seq_nm_max_length + |
5062 | SPIDER_SQL_NEXTVAL_LEN + |
5063 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2) |
5064 | ) |
5065 | goto error; |
5066 | str = &nextval_str[roop_count]; |
5067 | spider_db_oracle_utility.append_name(str, |
5068 | spider_share->tgt_sequence_names[roop_count], |
5069 | spider_share->tgt_sequence_names_lengths[roop_count]); |
5070 | str->q_append(SPIDER_SQL_NEXTVAL_STR, SPIDER_SQL_NEXTVAL_LEN); |
5071 | uint length = |
5072 | seq_nm_max_length - spider_share->tgt_sequence_names_lengths[roop_count]; |
5073 | memset((char *) str->ptr() + str->length(), ' ', length); |
5074 | str->length(str->length() + length); |
5075 | nextval_max_length = str->length(); |
5076 | } |
5077 | DBUG_RETURN(0); |
5078 | |
5079 | error: |
5080 | if (show_last_insert_id) |
5081 | { |
5082 | delete [] show_last_insert_id; |
5083 | show_last_insert_id = NULL; |
5084 | } |
5085 | if (nextval_str) |
5086 | { |
5087 | delete [] nextval_str; |
5088 | nextval_str = NULL; |
5089 | } |
5090 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5091 | } |
5092 | |
5093 | void spider_oracle_share::free_show_last_insert_id() |
5094 | { |
5095 | DBUG_ENTER("spider_oracle_share::free_show_last_insert_id" ); |
5096 | if (show_last_insert_id) |
5097 | { |
5098 | delete [] show_last_insert_id; |
5099 | show_last_insert_id = NULL; |
5100 | } |
5101 | if (nextval_str) |
5102 | { |
5103 | delete [] nextval_str; |
5104 | nextval_str = NULL; |
5105 | } |
5106 | DBUG_VOID_RETURN; |
5107 | } |
5108 | |
5109 | int spider_oracle_share::append_show_index() |
5110 | { |
5111 | int roop_count; |
5112 | spider_string *str; |
5113 | uint dbton_id = spider_dbton_oracle.dbton_id; |
5114 | DBUG_ENTER("spider_oracle_share::append_show_index" ); |
5115 | if (!(show_index = new spider_string[2 * spider_share->all_link_count])) |
5116 | goto error; |
5117 | |
5118 | for (roop_count = 0; roop_count < (int) spider_share->all_link_count; |
5119 | roop_count++) |
5120 | { |
5121 | show_index[0 + (2 * roop_count)].init_calc_mem(209); |
5122 | show_index[1 + (2 * roop_count)].init_calc_mem(210); |
5123 | if (spider_share->sql_dbton_ids[roop_count] != dbton_id) |
5124 | continue; |
5125 | |
5126 | if ( |
5127 | show_index[0 + (2 * roop_count)].reserve( |
5128 | SPIDER_SQL_SHOW_INDEX_LEN + db_names_str[roop_count].length() + |
5129 | SPIDER_SQL_DOT_LEN + |
5130 | table_names_str[roop_count].length() + |
5131 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4) || |
5132 | show_index[1 + (2 * roop_count)].reserve( |
5133 | SPIDER_SQL_SELECT_STATISTICS_LEN + |
5134 | db_names_str[roop_count].length() + |
5135 | SPIDER_SQL_AND_LEN + SPIDER_SQL_TABLE_NAME_LEN + SPIDER_SQL_EQUAL_LEN + |
5136 | table_names_str[roop_count].length() + |
5137 | ((SPIDER_SQL_VALUE_QUOTE_LEN) * 4) + |
5138 | SPIDER_SQL_GROUP_LEN + SPIDER_SQL_COLUMN_NAME_LEN) |
5139 | ) |
5140 | goto error; |
5141 | str = &show_index[0 + (2 * roop_count)]; |
5142 | str->q_append( |
5143 | SPIDER_SQL_SHOW_INDEX_STR, SPIDER_SQL_SHOW_INDEX_LEN); |
5144 | append_table_name(str, roop_count); |
5145 | str = &show_index[1 + (2 * roop_count)]; |
5146 | str->q_append( |
5147 | SPIDER_SQL_SELECT_STATISTICS_STR, SPIDER_SQL_SELECT_STATISTICS_LEN); |
5148 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
5149 | str->q_append(db_names_str[roop_count].ptr(), |
5150 | db_names_str[roop_count].length()); |
5151 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
5152 | str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
5153 | str->q_append(SPIDER_SQL_TABLE_NAME_STR, SPIDER_SQL_TABLE_NAME_LEN); |
5154 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
5155 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
5156 | str->q_append(table_names_str[roop_count].ptr(), |
5157 | table_names_str[roop_count].length()); |
5158 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
5159 | str->q_append(SPIDER_SQL_GROUP_STR, SPIDER_SQL_GROUP_LEN); |
5160 | str->q_append(SPIDER_SQL_COLUMN_NAME_STR, SPIDER_SQL_COLUMN_NAME_LEN); |
5161 | } |
5162 | DBUG_RETURN(0); |
5163 | |
5164 | error: |
5165 | if (show_index) |
5166 | { |
5167 | delete [] show_index; |
5168 | show_index = NULL; |
5169 | } |
5170 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5171 | } |
5172 | |
5173 | void spider_oracle_share::free_show_index() |
5174 | { |
5175 | DBUG_ENTER("spider_oracle_share::free_show_index" ); |
5176 | if (show_index) |
5177 | { |
5178 | delete [] show_index; |
5179 | show_index = NULL; |
5180 | } |
5181 | DBUG_VOID_RETURN; |
5182 | } |
5183 | |
5184 | int spider_oracle_share::append_table_select() |
5185 | { |
5186 | Field **field; |
5187 | uint field_length; |
5188 | spider_string *str = table_select; |
5189 | TABLE_SHARE *table_share = spider_share->table_share; |
5190 | DBUG_ENTER("spider_oracle_share::append_table_select" ); |
5191 | for (field = table_share->field; *field; field++) |
5192 | { |
5193 | field_length = column_name_str[(*field)->field_index].length(); |
5194 | if (str->reserve(field_length + |
5195 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
5196 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5197 | append_column_name(str, (*field)->field_index); |
5198 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5199 | } |
5200 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
5201 | DBUG_RETURN(append_from_with_adjusted_table_name(str, &table_select_pos)); |
5202 | } |
5203 | |
5204 | int spider_oracle_share::append_key_select( |
5205 | uint idx |
5206 | ) { |
5207 | KEY_PART_INFO *key_part; |
5208 | Field *field; |
5209 | uint part_num; |
5210 | uint field_length; |
5211 | spider_string *str = &key_select[idx]; |
5212 | TABLE_SHARE *table_share = spider_share->table_share; |
5213 | const KEY *key_info = &table_share->key_info[idx]; |
5214 | DBUG_ENTER("spider_oracle_share::append_key_select" ); |
5215 | for (key_part = key_info->key_part, part_num = 0; |
5216 | part_num < spider_user_defined_key_parts(key_info); key_part++, part_num++) |
5217 | { |
5218 | field = key_part->field; |
5219 | field_length = column_name_str[field->field_index].length(); |
5220 | if (str->reserve(field_length + |
5221 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
5222 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5223 | append_column_name(str, field->field_index); |
5224 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5225 | } |
5226 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
5227 | DBUG_RETURN(append_from_with_adjusted_table_name(str, &key_select_pos[idx])); |
5228 | } |
5229 | |
5230 | bool spider_oracle_share::need_change_db_table_name() |
5231 | { |
5232 | DBUG_ENTER("spider_oracle_share::need_change_db_table_name" ); |
5233 | DBUG_RETURN(!same_db_table_name); |
5234 | } |
5235 | |
5236 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
5237 | int spider_oracle_share::discover_table_structure( |
5238 | SPIDER_TRX *trx, |
5239 | SPIDER_SHARE *spider_share, |
5240 | spider_string *str |
5241 | ) { |
5242 | DBUG_ENTER("spider_oracle_share::discover_table_structure" ); |
5243 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5244 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
5245 | } |
5246 | #endif |
5247 | |
5248 | spider_oracle_handler::spider_oracle_handler( |
5249 | ha_spider *spider, |
5250 | spider_oracle_share *db_share |
5251 | ) : spider_db_handler( |
5252 | spider, |
5253 | db_share |
5254 | ), |
5255 | where_pos(0), |
5256 | order_pos(0), |
5257 | limit_pos(0), |
5258 | table_name_pos(0), |
5259 | update_set_pos(0), |
5260 | ha_read_pos(0), |
5261 | ha_next_pos(0), |
5262 | ha_where_pos(0), |
5263 | ha_limit_pos(0), |
5264 | ha_table_name_pos(0), |
5265 | insert_pos(0), |
5266 | insert_table_name_pos(0), |
5267 | upd_tmp_tbl(NULL), |
5268 | tmp_sql_pos1(0), |
5269 | tmp_sql_pos2(0), |
5270 | tmp_sql_pos3(0), |
5271 | tmp_sql_pos4(0), |
5272 | tmp_sql_pos5(0), |
5273 | table_lock_mode(0), |
5274 | reading_from_bulk_tmp_table(FALSE), |
5275 | filled_up(FALSE), |
5276 | select_rownum_appended(FALSE), |
5277 | update_rownum_appended(FALSE), |
5278 | union_table_name_pos_first(NULL), |
5279 | union_table_name_pos_current(NULL), |
5280 | oracle_share(db_share), |
5281 | link_for_hash(NULL) |
5282 | { |
5283 | DBUG_ENTER("spider_oracle_handler::spider_oracle_handler" ); |
5284 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5285 | spider_alloc_calc_mem_init(mem_calc, 222); |
5286 | spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); |
5287 | DBUG_VOID_RETURN; |
5288 | } |
5289 | |
5290 | spider_oracle_handler::~spider_oracle_handler() |
5291 | { |
5292 | DBUG_ENTER("spider_oracle_handler::~spider_oracle_handler" ); |
5293 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5294 | while (union_table_name_pos_first) |
5295 | { |
5296 | SPIDER_INT_HLD *tmp_pos = union_table_name_pos_first; |
5297 | union_table_name_pos_first = tmp_pos->next; |
5298 | spider_free(spider_current_trx, tmp_pos, MYF(0)); |
5299 | } |
5300 | if (link_for_hash) |
5301 | { |
5302 | spider_free(spider_current_trx, link_for_hash, MYF(0)); |
5303 | } |
5304 | spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); |
5305 | DBUG_VOID_RETURN; |
5306 | } |
5307 | |
5308 | int spider_oracle_handler::init() |
5309 | { |
5310 | uint roop_count; |
5311 | THD *thd = spider->trx->thd; |
5312 | st_spider_share *share = spider->share; |
5313 | int init_sql_alloc_size = |
5314 | spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); |
5315 | TABLE *table = spider->get_table(); |
5316 | DBUG_ENTER("spider_oracle_handler::init" ); |
5317 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5318 | sql.init_calc_mem(67); |
5319 | sql_part.init_calc_mem(68); |
5320 | sql_part2.init_calc_mem(69); |
5321 | ha_sql.init_calc_mem(70); |
5322 | insert_sql.init_calc_mem(72); |
5323 | update_sql.init_calc_mem(73); |
5324 | tmp_sql.init_calc_mem(74); |
5325 | dup_update_sql.init_calc_mem(167); |
5326 | if ( |
5327 | (sql.real_alloc(init_sql_alloc_size)) || |
5328 | (insert_sql.real_alloc(init_sql_alloc_size)) || |
5329 | (update_sql.real_alloc(init_sql_alloc_size)) || |
5330 | (tmp_sql.real_alloc(init_sql_alloc_size)) |
5331 | ) { |
5332 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5333 | } |
5334 | sql.set_charset(share->access_charset); |
5335 | sql_part.set_charset(share->access_charset); |
5336 | ha_sql.set_charset(share->access_charset); |
5337 | insert_sql.set_charset(share->access_charset); |
5338 | update_sql.set_charset(share->access_charset); |
5339 | tmp_sql.set_charset(share->access_charset); |
5340 | upd_tmp_tbl_prm.init(); |
5341 | upd_tmp_tbl_prm.field_count = 1; |
5342 | if (!(link_for_hash = (SPIDER_LINK_FOR_HASH *) |
5343 | spider_bulk_alloc_mem(spider_current_trx, 223, |
5344 | __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), |
5345 | &link_for_hash, |
5346 | sizeof(SPIDER_LINK_FOR_HASH) * share->link_count, |
5347 | &minimum_select_bitmap, |
5348 | table ? sizeof(uchar) * no_bytes_in_map(table->read_set) : 0, |
5349 | NullS)) |
5350 | ) { |
5351 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5352 | } |
5353 | for (roop_count = 0; roop_count < share->link_count; roop_count++) |
5354 | { |
5355 | link_for_hash[roop_count].spider = spider; |
5356 | link_for_hash[roop_count].link_idx = roop_count; |
5357 | link_for_hash[roop_count].db_table_str = |
5358 | &oracle_share->db_table_str[roop_count]; |
5359 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
5360 | link_for_hash[roop_count].db_table_str_hash_value = |
5361 | oracle_share->db_table_str_hash_value[roop_count]; |
5362 | #endif |
5363 | } |
5364 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
5365 | hs_upds.init(); |
5366 | #endif |
5367 | DBUG_RETURN(0); |
5368 | } |
5369 | |
5370 | int spider_oracle_handler::append_index_hint( |
5371 | spider_string *str, |
5372 | int link_idx, |
5373 | ulong sql_type |
5374 | ) |
5375 | { |
5376 | DBUG_ENTER("spider_oracle_handler::append_index_hint" ); |
5377 | DBUG_RETURN(0); |
5378 | } |
5379 | |
5380 | int spider_oracle_handler::append_table_name_with_adjusting( |
5381 | spider_string *str, |
5382 | int link_idx, |
5383 | ulong sql_type |
5384 | ) { |
5385 | int error_num = 0; |
5386 | DBUG_ENTER("spider_oracle_handler::append_table_name_with_adjusting" ); |
5387 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5388 | if (sql_type == SPIDER_SQL_TYPE_HANDLER) |
5389 | { |
5390 | str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); |
5391 | } else { |
5392 | error_num = oracle_share->append_table_name_with_adjusting(str, |
5393 | spider->conn_link_idx[link_idx]); |
5394 | } |
5395 | DBUG_RETURN(error_num); |
5396 | } |
5397 | |
5398 | int spider_oracle_handler::append_key_column_types( |
5399 | const key_range *start_key, |
5400 | spider_string *str |
5401 | ) { |
5402 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
5403 | KEY *key_info = result_list->key_info; |
5404 | uint key_name_length, key_count; |
5405 | key_part_map full_key_part_map = |
5406 | make_prev_keypart_map(spider_user_defined_key_parts(key_info)); |
5407 | key_part_map start_key_part_map; |
5408 | KEY_PART_INFO *key_part; |
5409 | Field *field; |
5410 | char tmp_buf[MAX_FIELD_WIDTH]; |
5411 | spider_string tmp_str(tmp_buf, sizeof(tmp_buf), system_charset_info); |
5412 | DBUG_ENTER("spider_oracle_handler::append_key_column_types" ); |
5413 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5414 | tmp_str.init_calc_mem(227); |
5415 | |
5416 | start_key_part_map = start_key->keypart_map & full_key_part_map; |
5417 | DBUG_PRINT("info" , ("spider spider_user_defined_key_parts=%u" , |
5418 | spider_user_defined_key_parts(key_info))); |
5419 | DBUG_PRINT("info" , ("spider full_key_part_map=%lu" , full_key_part_map)); |
5420 | DBUG_PRINT("info" , ("spider start_key_part_map=%lu" , start_key_part_map)); |
5421 | |
5422 | if (!start_key_part_map) |
5423 | DBUG_RETURN(0); |
5424 | |
5425 | for ( |
5426 | key_part = key_info->key_part, |
5427 | key_count = 0; |
5428 | start_key_part_map; |
5429 | start_key_part_map >>= 1, |
5430 | key_part++, |
5431 | key_count++ |
5432 | ) { |
5433 | field = key_part->field; |
5434 | key_name_length = my_sprintf(tmp_buf, (tmp_buf, "c%u" , key_count)); |
5435 | if (str->reserve(key_name_length + SPIDER_SQL_SPACE_LEN)) |
5436 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5437 | str->q_append(tmp_buf, key_name_length); |
5438 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
5439 | |
5440 | if (tmp_str.ptr() != tmp_buf) |
5441 | tmp_str.set(tmp_buf, sizeof(tmp_buf), system_charset_info); |
5442 | else |
5443 | tmp_str.set_charset(system_charset_info); |
5444 | field->sql_type(*tmp_str.get_str()); |
5445 | tmp_str.mem_calc(); |
5446 | str->append(tmp_str); |
5447 | |
5448 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
5449 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5450 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5451 | } |
5452 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
5453 | |
5454 | DBUG_RETURN(0); |
5455 | } |
5456 | |
5457 | int spider_oracle_handler::append_key_join_columns_for_bka( |
5458 | const key_range *start_key, |
5459 | spider_string *str, |
5460 | const char **table_aliases, |
5461 | uint *table_alias_lengths |
5462 | ) { |
5463 | KEY *key_info = spider->result_list.key_info; |
5464 | uint length, key_name_length, key_count; |
5465 | key_part_map full_key_part_map = |
5466 | make_prev_keypart_map(spider_user_defined_key_parts(key_info)); |
5467 | key_part_map start_key_part_map; |
5468 | KEY_PART_INFO *key_part; |
5469 | Field *field; |
5470 | char tmp_buf[MAX_FIELD_WIDTH]; |
5471 | bool start_where = ((int) str->length() == where_pos); |
5472 | DBUG_ENTER("spider_oracle_handler::append_key_join_columns_for_bka" ); |
5473 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5474 | start_key_part_map = start_key->keypart_map & full_key_part_map; |
5475 | DBUG_PRINT("info" , ("spider spider_user_defined_key_parts=%u" , |
5476 | spider_user_defined_key_parts(key_info))); |
5477 | DBUG_PRINT("info" , ("spider full_key_part_map=%lu" , full_key_part_map)); |
5478 | DBUG_PRINT("info" , ("spider start_key_part_map=%lu" , start_key_part_map)); |
5479 | |
5480 | if (!start_key_part_map) |
5481 | DBUG_RETURN(0); |
5482 | |
5483 | if (start_where) |
5484 | { |
5485 | if (str->reserve(SPIDER_SQL_WHERE_LEN)) |
5486 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5487 | str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); |
5488 | } else { |
5489 | if (str->reserve(SPIDER_SQL_AND_LEN)) |
5490 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5491 | str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
5492 | } |
5493 | |
5494 | for ( |
5495 | key_part = key_info->key_part, |
5496 | key_count = 0; |
5497 | start_key_part_map; |
5498 | start_key_part_map >>= 1, |
5499 | key_part++, |
5500 | key_count++ |
5501 | ) { |
5502 | field = key_part->field; |
5503 | key_name_length = |
5504 | oracle_share->column_name_str[field->field_index].length(); |
5505 | length = my_sprintf(tmp_buf, (tmp_buf, "c%u" , key_count)); |
5506 | if (str->reserve(length + table_alias_lengths[0] + key_name_length + |
5507 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
5508 | table_alias_lengths[1] + SPIDER_SQL_PF_EQUAL_LEN + SPIDER_SQL_AND_LEN)) |
5509 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5510 | str->q_append(table_aliases[0], table_alias_lengths[0]); |
5511 | str->q_append(tmp_buf, length); |
5512 | str->q_append(SPIDER_SQL_PF_EQUAL_STR, SPIDER_SQL_PF_EQUAL_LEN); |
5513 | str->q_append(table_aliases[1], table_alias_lengths[1]); |
5514 | oracle_share->append_column_name(str, field->field_index); |
5515 | str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
5516 | } |
5517 | str->length(str->length() - SPIDER_SQL_AND_LEN); |
5518 | DBUG_RETURN(0); |
5519 | } |
5520 | |
5521 | int spider_oracle_handler::append_tmp_table_and_sql_for_bka( |
5522 | const key_range *start_key |
5523 | ) { |
5524 | int error_num; |
5525 | DBUG_ENTER("spider_oracle_handler::append_tmp_table_and_sql_for_bka" ); |
5526 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5527 | char tmp_table_name[MAX_FIELD_WIDTH * 2], |
5528 | tgt_table_name[MAX_FIELD_WIDTH * 2]; |
5529 | int tmp_table_name_length; |
5530 | spider_string tgt_table_name_str(tgt_table_name, MAX_FIELD_WIDTH * 2, |
5531 | oracle_share->db_names_str[0].charset()); |
5532 | const char *table_names[2], *table_aliases[2], *table_dot_aliases[2]; |
5533 | uint table_name_lengths[2], table_alias_lengths[2], |
5534 | table_dot_alias_lengths[2]; |
5535 | tgt_table_name_str.init_calc_mem(200); |
5536 | tgt_table_name_str.length(0); |
5537 | create_tmp_bka_table_name(tmp_table_name, &tmp_table_name_length, |
5538 | first_link_idx); |
5539 | if ((error_num = append_table_name_with_adjusting(&tgt_table_name_str, |
5540 | first_link_idx, SPIDER_SQL_TYPE_SELECT_SQL))) |
5541 | { |
5542 | DBUG_RETURN(error_num); |
5543 | } |
5544 | table_names[0] = tmp_table_name; |
5545 | table_names[1] = tgt_table_name_str.c_ptr_safe(); |
5546 | table_name_lengths[0] = tmp_table_name_length; |
5547 | table_name_lengths[1] = tgt_table_name_str.length(); |
5548 | table_aliases[0] = SPIDER_SQL_A_STR; |
5549 | table_aliases[1] = SPIDER_SQL_B_STR; |
5550 | table_alias_lengths[0] = SPIDER_SQL_A_LEN; |
5551 | table_alias_lengths[1] = SPIDER_SQL_B_LEN; |
5552 | table_dot_aliases[0] = SPIDER_SQL_A_DOT_STR; |
5553 | table_dot_aliases[1] = SPIDER_SQL_B_DOT_STR; |
5554 | table_dot_alias_lengths[0] = SPIDER_SQL_A_DOT_LEN; |
5555 | table_dot_alias_lengths[1] = SPIDER_SQL_B_DOT_LEN; |
5556 | if ( |
5557 | (error_num = append_drop_tmp_bka_table( |
5558 | &tmp_sql, tmp_table_name, tmp_table_name_length, |
5559 | &tmp_sql_pos1, &tmp_sql_pos5, TRUE)) || |
5560 | (error_num = append_create_tmp_bka_table( |
5561 | start_key, |
5562 | &tmp_sql, tmp_table_name, |
5563 | tmp_table_name_length, |
5564 | &tmp_sql_pos2, spider->share->table_share->table_charset)) || |
5565 | (error_num = append_insert_tmp_bka_table( |
5566 | start_key, |
5567 | &tmp_sql, tmp_table_name, |
5568 | tmp_table_name_length, &tmp_sql_pos3)) |
5569 | ) |
5570 | DBUG_RETURN(error_num); |
5571 | tmp_sql_pos4 = tmp_sql.length(); |
5572 | if ((error_num = spider_db_append_select(spider))) |
5573 | DBUG_RETURN(error_num); |
5574 | if (sql.reserve(SPIDER_SQL_A_DOT_LEN + SPIDER_SQL_ID_LEN + |
5575 | SPIDER_SQL_COMMA_LEN)) |
5576 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5577 | sql.q_append(SPIDER_SQL_A_DOT_STR, SPIDER_SQL_A_DOT_LEN); |
5578 | sql.q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); |
5579 | sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5580 | if ( |
5581 | (error_num = append_select_columns_with_alias(&sql, |
5582 | SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) || |
5583 | (error_num = spider_db_oracle_utility.append_from_with_alias(&sql, |
5584 | table_names, table_name_lengths, |
5585 | table_aliases, table_alias_lengths, 2, |
5586 | &table_name_pos, FALSE)) |
5587 | ) |
5588 | DBUG_RETURN(error_num); |
5589 | if ( |
5590 | oracle_share->key_hint && |
5591 | (error_num = spider_db_append_hint_after_table(spider, |
5592 | &sql, &oracle_share->key_hint[spider->active_index])) |
5593 | ) |
5594 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5595 | where_pos = sql.length(); |
5596 | if ( |
5597 | (error_num = append_key_join_columns_for_bka( |
5598 | start_key, &sql, |
5599 | table_dot_aliases, table_dot_alias_lengths)) || |
5600 | (error_num = append_condition_part( |
5601 | SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN, |
5602 | SPIDER_SQL_TYPE_SELECT_SQL, FALSE)) |
5603 | ) |
5604 | DBUG_RETURN(error_num); |
5605 | if (spider->result_list.direct_order_limit) |
5606 | { |
5607 | if ((error_num = append_key_order_for_direct_order_limit_with_alias(&sql, |
5608 | SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) |
5609 | DBUG_RETURN(error_num); |
5610 | } |
5611 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
5612 | else if (spider->result_list.direct_aggregate) |
5613 | { |
5614 | if ((error_num = |
5615 | append_group_by(&sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) |
5616 | DBUG_RETURN(error_num); |
5617 | } |
5618 | #endif |
5619 | |
5620 | DBUG_RETURN(0); |
5621 | } |
5622 | |
5623 | int spider_oracle_handler::reuse_tmp_table_and_sql_for_bka() |
5624 | { |
5625 | DBUG_ENTER("spider_oracle_handler::reuse_tmp_table_and_sql_for_bka" ); |
5626 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5627 | tmp_sql.length(tmp_sql_pos4); |
5628 | sql.length(limit_pos); |
5629 | ha_sql.length(ha_limit_pos); |
5630 | DBUG_RETURN(0); |
5631 | } |
5632 | |
5633 | void spider_oracle_handler::create_tmp_bka_table_name( |
5634 | char *tmp_table_name, |
5635 | int *tmp_table_name_length, |
5636 | int link_idx |
5637 | ) { |
5638 | uint adjust_length, length; |
5639 | DBUG_ENTER("spider_oracle_handler::create_tmp_bka_table_name" ); |
5640 | if (spider_param_bka_table_name_type(current_thd, |
5641 | oracle_share->spider_share-> |
5642 | bka_table_name_types[spider->conn_link_idx[link_idx]]) == 1) |
5643 | { |
5644 | adjust_length = |
5645 | oracle_share->db_nm_max_length - |
5646 | oracle_share->db_names_str[spider->conn_link_idx[link_idx]].length() + |
5647 | oracle_share->table_nm_max_length - |
5648 | oracle_share->table_names_str[spider->conn_link_idx[link_idx]].length(); |
5649 | *tmp_table_name_length = oracle_share->db_nm_max_length + |
5650 | oracle_share->table_nm_max_length; |
5651 | memset(tmp_table_name, ' ', adjust_length); |
5652 | tmp_table_name += adjust_length; |
5653 | memcpy(tmp_table_name, oracle_share->db_names_str[link_idx].c_ptr(), |
5654 | oracle_share->db_names_str[link_idx].length()); |
5655 | tmp_table_name += oracle_share->db_names_str[link_idx].length(); |
5656 | length = my_sprintf(tmp_table_name, (tmp_table_name, |
5657 | "%s%s%p%s" , SPIDER_SQL_DOT_STR, SPIDER_SQL_TMP_BKA_STR, spider, |
5658 | SPIDER_SQL_UNDERSCORE_STR)); |
5659 | *tmp_table_name_length += length; |
5660 | tmp_table_name += length; |
5661 | memcpy(tmp_table_name, |
5662 | oracle_share->table_names_str[spider->conn_link_idx[link_idx]].c_ptr(), |
5663 | oracle_share->table_names_str[spider->conn_link_idx[link_idx]].length()); |
5664 | } else { |
5665 | adjust_length = |
5666 | oracle_share->db_nm_max_length - |
5667 | oracle_share->db_names_str[spider->conn_link_idx[link_idx]].length(); |
5668 | *tmp_table_name_length = oracle_share->db_nm_max_length; |
5669 | memset(tmp_table_name, ' ', adjust_length); |
5670 | tmp_table_name += adjust_length; |
5671 | memcpy(tmp_table_name, oracle_share->db_names_str[link_idx].c_ptr(), |
5672 | oracle_share->db_names_str[link_idx].length()); |
5673 | tmp_table_name += oracle_share->db_names_str[link_idx].length(); |
5674 | length = my_sprintf(tmp_table_name, (tmp_table_name, |
5675 | "%s%s%p" , SPIDER_SQL_DOT_STR, SPIDER_SQL_TMP_BKA_STR, spider)); |
5676 | *tmp_table_name_length += length; |
5677 | } |
5678 | DBUG_VOID_RETURN; |
5679 | } |
5680 | |
5681 | int spider_oracle_handler::append_create_tmp_bka_table( |
5682 | const key_range *start_key, |
5683 | spider_string *str, |
5684 | char *tmp_table_name, |
5685 | int tmp_table_name_length, |
5686 | int *db_name_pos, |
5687 | CHARSET_INFO *table_charset |
5688 | ) { |
5689 | int error_num; |
5690 | SPIDER_SHARE *share = spider->share; |
5691 | THD *thd = spider->trx->thd; |
5692 | char *bka_engine = spider_param_bka_engine(thd, share->bka_engine); |
5693 | uint bka_engine_length = strlen(bka_engine), |
5694 | cset_length = strlen(table_charset->csname); |
5695 | DBUG_ENTER("spider_oracle_handler::append_create_tmp_bka_table" ); |
5696 | if (str->reserve(SPIDER_SQL_CREATE_TMP_LEN + tmp_table_name_length + |
5697 | SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_ID_LEN + SPIDER_SQL_ID_TYPE_LEN + |
5698 | SPIDER_SQL_COMMA_LEN)) |
5699 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5700 | str->q_append(SPIDER_SQL_CREATE_TMP_STR, SPIDER_SQL_CREATE_TMP_LEN); |
5701 | *db_name_pos = str->length(); |
5702 | str->q_append(tmp_table_name, tmp_table_name_length); |
5703 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
5704 | str->q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); |
5705 | str->q_append(SPIDER_SQL_ID_TYPE_STR, SPIDER_SQL_ID_TYPE_LEN); |
5706 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5707 | if ((error_num = append_key_column_types(start_key, str))) |
5708 | DBUG_RETURN(error_num); |
5709 | if (str->reserve(SPIDER_SQL_ENGINE_LEN + bka_engine_length + |
5710 | SPIDER_SQL_DEF_CHARSET_LEN + cset_length + SPIDER_SQL_SEMICOLON_LEN)) |
5711 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5712 | str->q_append(SPIDER_SQL_ENGINE_STR, SPIDER_SQL_ENGINE_LEN); |
5713 | str->q_append(bka_engine, bka_engine_length); |
5714 | str->q_append(SPIDER_SQL_DEF_CHARSET_STR, SPIDER_SQL_DEF_CHARSET_LEN); |
5715 | str->q_append(table_charset->csname, cset_length); |
5716 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
5717 | DBUG_RETURN(0); |
5718 | } |
5719 | |
5720 | int spider_oracle_handler::append_drop_tmp_bka_table( |
5721 | spider_string *str, |
5722 | char *tmp_table_name, |
5723 | int tmp_table_name_length, |
5724 | int *db_name_pos, |
5725 | int *drop_table_end_pos, |
5726 | bool with_semicolon |
5727 | ) { |
5728 | DBUG_ENTER("spider_oracle_handler::append_drop_tmp_bka_table" ); |
5729 | if (str->reserve(SPIDER_SQL_DROP_TMP_LEN + tmp_table_name_length + |
5730 | (with_semicolon ? SPIDER_SQL_SEMICOLON_LEN : 0))) |
5731 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5732 | str->q_append(SPIDER_SQL_DROP_TMP_STR, SPIDER_SQL_DROP_TMP_LEN); |
5733 | *db_name_pos = str->length(); |
5734 | str->q_append(tmp_table_name, tmp_table_name_length); |
5735 | *drop_table_end_pos = str->length(); |
5736 | if (with_semicolon) |
5737 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
5738 | DBUG_RETURN(0); |
5739 | } |
5740 | |
5741 | int spider_oracle_handler::append_insert_tmp_bka_table( |
5742 | const key_range *start_key, |
5743 | spider_string *str, |
5744 | char *tmp_table_name, |
5745 | int tmp_table_name_length, |
5746 | int *db_name_pos |
5747 | ) { |
5748 | int error_num; |
5749 | DBUG_ENTER("spider_oracle_handler::append_insert_tmp_bka_table" ); |
5750 | if (str->reserve(SPIDER_SQL_INSERT_LEN + SPIDER_SQL_INTO_LEN + |
5751 | tmp_table_name_length + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_ID_LEN + |
5752 | SPIDER_SQL_COMMA_LEN)) |
5753 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5754 | str->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); |
5755 | str->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); |
5756 | *db_name_pos = str->length(); |
5757 | str->q_append(tmp_table_name, tmp_table_name_length); |
5758 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
5759 | str->q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); |
5760 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5761 | if ((error_num = spider_db_append_key_columns(start_key, spider, str))) |
5762 | DBUG_RETURN(error_num); |
5763 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_VALUES_LEN + |
5764 | SPIDER_SQL_OPEN_PAREN_LEN)) |
5765 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5766 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
5767 | str->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); |
5768 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
5769 | DBUG_RETURN(0); |
5770 | } |
5771 | |
5772 | int spider_oracle_handler::append_union_table_and_sql_for_bka( |
5773 | const key_range *start_key |
5774 | ) { |
5775 | int error_num; |
5776 | DBUG_ENTER("spider_oracle_handler::append_union_table_and_sql_for_bka" ); |
5777 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5778 | char tgt_table_name[MAX_FIELD_WIDTH * 2]; |
5779 | spider_string tgt_table_name_str(tgt_table_name, MAX_FIELD_WIDTH * 2, |
5780 | oracle_share->db_names_str[0].charset()); |
5781 | const char *table_names[2], *table_aliases[2], *table_dot_aliases[2]; |
5782 | uint table_name_lengths[2], table_alias_lengths[2], |
5783 | table_dot_alias_lengths[2]; |
5784 | tgt_table_name_str.init_calc_mem(234); |
5785 | tgt_table_name_str.length(0); |
5786 | if ((error_num = append_table_name_with_adjusting(&tgt_table_name_str, |
5787 | first_link_idx, SPIDER_SQL_TYPE_SELECT_SQL))) |
5788 | { |
5789 | DBUG_RETURN(error_num); |
5790 | } |
5791 | table_names[0] = "" ; |
5792 | table_names[1] = tgt_table_name_str.c_ptr_safe(); |
5793 | table_name_lengths[0] = 0; |
5794 | table_name_lengths[1] = tgt_table_name_str.length(); |
5795 | table_aliases[0] = SPIDER_SQL_A_STR; |
5796 | table_aliases[1] = SPIDER_SQL_B_STR; |
5797 | table_alias_lengths[0] = SPIDER_SQL_A_LEN; |
5798 | table_alias_lengths[1] = SPIDER_SQL_B_LEN; |
5799 | table_dot_aliases[0] = SPIDER_SQL_A_DOT_STR; |
5800 | table_dot_aliases[1] = SPIDER_SQL_B_DOT_STR; |
5801 | table_dot_alias_lengths[0] = SPIDER_SQL_A_DOT_LEN; |
5802 | table_dot_alias_lengths[1] = SPIDER_SQL_B_DOT_LEN; |
5803 | |
5804 | if ((error_num = spider_db_append_select(spider))) |
5805 | DBUG_RETURN(error_num); |
5806 | if (sql.reserve(SPIDER_SQL_A_DOT_LEN + SPIDER_SQL_ID_LEN + |
5807 | SPIDER_SQL_COMMA_LEN)) |
5808 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5809 | sql.q_append(SPIDER_SQL_A_DOT_STR, SPIDER_SQL_A_DOT_LEN); |
5810 | sql.q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); |
5811 | sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5812 | if ((error_num = append_select_columns_with_alias(&sql, |
5813 | SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) |
5814 | DBUG_RETURN(error_num); |
5815 | if (sql.reserve(SPIDER_SQL_FROM_LEN + (SPIDER_SQL_OPEN_PAREN_LEN * 2))) |
5816 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5817 | sql.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
5818 | sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
5819 | sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
5820 | tmp_sql_pos1 = sql.length(); |
5821 | |
5822 | if ( |
5823 | (error_num = spider_db_oracle_utility.append_from_with_alias(&tmp_sql, |
5824 | table_names, table_name_lengths, |
5825 | table_aliases, table_alias_lengths, 2, |
5826 | &table_name_pos, FALSE)) |
5827 | ) |
5828 | DBUG_RETURN(error_num); |
5829 | if ( |
5830 | oracle_share->key_hint && |
5831 | (error_num = spider_db_append_hint_after_table(spider, |
5832 | &tmp_sql, &oracle_share->key_hint[spider->active_index])) |
5833 | ) |
5834 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5835 | where_pos = tmp_sql.length(); |
5836 | if ( |
5837 | (error_num = append_key_join_columns_for_bka( |
5838 | start_key, &tmp_sql, |
5839 | table_dot_aliases, table_dot_alias_lengths)) || |
5840 | (error_num = append_condition_part( |
5841 | SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN, |
5842 | SPIDER_SQL_TYPE_TMP_SQL, FALSE)) |
5843 | ) |
5844 | DBUG_RETURN(error_num); |
5845 | if (spider->result_list.direct_order_limit) |
5846 | { |
5847 | if ((error_num = append_key_order_for_direct_order_limit_with_alias( |
5848 | &tmp_sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) |
5849 | DBUG_RETURN(error_num); |
5850 | } |
5851 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
5852 | else if (spider->result_list.direct_aggregate) |
5853 | { |
5854 | if ((error_num = |
5855 | append_group_by(&tmp_sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) |
5856 | DBUG_RETURN(error_num); |
5857 | } |
5858 | #endif |
5859 | |
5860 | DBUG_RETURN(0); |
5861 | } |
5862 | |
5863 | int spider_oracle_handler::reuse_union_table_and_sql_for_bka() |
5864 | { |
5865 | DBUG_ENTER("spider_oracle_handler::reuse_union_table_and_sql_for_bka" ); |
5866 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5867 | sql.length(tmp_sql_pos1); |
5868 | DBUG_RETURN(0); |
5869 | } |
5870 | |
5871 | int spider_oracle_handler::append_insert_for_recovery( |
5872 | ulong sql_type, |
5873 | int link_idx |
5874 | ) { |
5875 | const TABLE *table = spider->get_table(); |
5876 | SPIDER_SHARE *share = spider->share; |
5877 | Field **field; |
5878 | uint field_name_length = 0; |
5879 | bool add_value = FALSE; |
5880 | spider_string *insert_sql; |
5881 | DBUG_ENTER("spider_oracle_handler::append_insert_for_recovery" ); |
5882 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5883 | if (sql_type == SPIDER_SQL_TYPE_INSERT_SQL) |
5884 | { |
5885 | insert_sql = &spider->result_list.insert_sqls[link_idx]; |
5886 | insert_sql->length(0); |
5887 | } else { |
5888 | insert_sql = &spider->result_list.update_sqls[link_idx]; |
5889 | } |
5890 | if (insert_sql->reserve( |
5891 | SPIDER_SQL_INSERT_LEN + SPIDER_SQL_SQL_IGNORE_LEN + |
5892 | SPIDER_SQL_INTO_LEN + oracle_share->db_nm_max_length + |
5893 | SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + |
5894 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) |
5895 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5896 | insert_sql->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); |
5897 | insert_sql->q_append(SPIDER_SQL_SQL_IGNORE_STR, SPIDER_SQL_SQL_IGNORE_LEN); |
5898 | insert_sql->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); |
5899 | oracle_share->append_table_name(insert_sql, spider->conn_link_idx[link_idx]); |
5900 | insert_sql->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
5901 | for (field = table->field; *field; field++) |
5902 | { |
5903 | field_name_length = |
5904 | oracle_share->column_name_str[(*field)->field_index].length(); |
5905 | if (insert_sql->reserve(field_name_length + |
5906 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
5907 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5908 | oracle_share->append_column_name(insert_sql, (*field)->field_index); |
5909 | insert_sql->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5910 | } |
5911 | if (field_name_length) |
5912 | insert_sql->length(insert_sql->length() - SPIDER_SQL_COMMA_LEN); |
5913 | if (insert_sql->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_VALUES_LEN + |
5914 | SPIDER_SQL_OPEN_PAREN_LEN)) |
5915 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5916 | insert_sql->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
5917 | insert_sql->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); |
5918 | insert_sql->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
5919 | for (field = table->field; *field; field++) |
5920 | { |
5921 | add_value = TRUE; |
5922 | if ((*field)->is_null()) |
5923 | { |
5924 | if (insert_sql->reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) |
5925 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5926 | insert_sql->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); |
5927 | } else { |
5928 | if ( |
5929 | spider_db_oracle_utility. |
5930 | append_column_value(spider, insert_sql, *field, NULL, |
5931 | share->access_charset) || |
5932 | insert_sql->reserve(SPIDER_SQL_COMMA_LEN) |
5933 | ) |
5934 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5935 | } |
5936 | insert_sql->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
5937 | } |
5938 | if (add_value) |
5939 | insert_sql->length(insert_sql->length() - SPIDER_SQL_COMMA_LEN); |
5940 | if (insert_sql->reserve(SPIDER_SQL_CLOSE_PAREN_LEN, SPIDER_SQL_COMMA_LEN)) |
5941 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5942 | insert_sql->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
5943 | if (sql_type == SPIDER_SQL_TYPE_INSERT_SQL) |
5944 | { |
5945 | exec_insert_sql = insert_sql; |
5946 | } |
5947 | DBUG_RETURN(0); |
5948 | } |
5949 | |
5950 | int spider_oracle_handler::append_update( |
5951 | const TABLE *table, |
5952 | my_ptrdiff_t ptr_diff |
5953 | ) { |
5954 | int error_num; |
5955 | spider_string *str = &update_sql; |
5956 | DBUG_ENTER("spider_oracle_handler::append_update" ); |
5957 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5958 | if (str->length() > 0) |
5959 | { |
5960 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) |
5961 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5962 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
5963 | } |
5964 | |
5965 | if ( |
5966 | (error_num = append_update(str, 0)) || |
5967 | (error_num = append_update_set(str)) || |
5968 | (error_num = append_update_where(str, table, ptr_diff)) |
5969 | ) |
5970 | DBUG_RETURN(error_num); |
5971 | filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); |
5972 | DBUG_RETURN(0); |
5973 | } |
5974 | |
5975 | int spider_oracle_handler::append_update( |
5976 | const TABLE *table, |
5977 | my_ptrdiff_t ptr_diff, |
5978 | int link_idx |
5979 | ) { |
5980 | int error_num; |
5981 | SPIDER_SHARE *share = spider->share; |
5982 | spider_string *str = &spider->result_list.update_sqls[link_idx]; |
5983 | DBUG_ENTER("spider_oracle_handler::append_update" ); |
5984 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5985 | if (str->length() > 0) |
5986 | { |
5987 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) |
5988 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5989 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
5990 | } |
5991 | |
5992 | if ( |
5993 | (error_num = append_update(str, link_idx)) || |
5994 | (error_num = append_update_set(str)) || |
5995 | (error_num = append_update_where(str, table, ptr_diff)) |
5996 | ) |
5997 | DBUG_RETURN(error_num); |
5998 | |
5999 | if ( |
6000 | spider->pk_update && |
6001 | share->link_statuses[link_idx] == SPIDER_LINK_STATUS_RECOVERY |
6002 | ) { |
6003 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) |
6004 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6005 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
6006 | if ((error_num = append_insert_for_recovery( |
6007 | SPIDER_SQL_TYPE_UPDATE_SQL, link_idx))) |
6008 | DBUG_RETURN(error_num); |
6009 | } |
6010 | |
6011 | if (!filled_up) |
6012 | filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); |
6013 | DBUG_RETURN(0); |
6014 | } |
6015 | |
6016 | int spider_oracle_handler::append_delete( |
6017 | const TABLE *table, |
6018 | my_ptrdiff_t ptr_diff |
6019 | ) { |
6020 | int error_num; |
6021 | spider_string *str = &update_sql; |
6022 | DBUG_ENTER("spider_oracle_handler::append_delete" ); |
6023 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6024 | if (str->length() > 0) |
6025 | { |
6026 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) |
6027 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6028 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
6029 | } |
6030 | |
6031 | if ( |
6032 | (error_num = append_delete(str)) || |
6033 | (error_num = append_from(str, SPIDER_SQL_TYPE_DELETE_SQL, |
6034 | first_link_idx)) || |
6035 | (error_num = append_update_where(str, table, ptr_diff)) |
6036 | ) |
6037 | DBUG_RETURN(error_num); |
6038 | filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); |
6039 | DBUG_RETURN(0); |
6040 | } |
6041 | |
6042 | int spider_oracle_handler::append_delete( |
6043 | const TABLE *table, |
6044 | my_ptrdiff_t ptr_diff, |
6045 | int link_idx |
6046 | ) { |
6047 | int error_num; |
6048 | spider_string *str = &spider->result_list.update_sqls[link_idx]; |
6049 | DBUG_ENTER("spider_oracle_handler::append_delete" ); |
6050 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6051 | if (str->length() > 0) |
6052 | { |
6053 | if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) |
6054 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6055 | str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); |
6056 | } |
6057 | |
6058 | if ( |
6059 | (error_num = append_delete(str)) || |
6060 | (error_num = append_from(str, SPIDER_SQL_TYPE_DELETE_SQL, link_idx)) || |
6061 | (error_num = append_update_where(str, table, ptr_diff)) |
6062 | ) |
6063 | DBUG_RETURN(error_num); |
6064 | if (!filled_up) |
6065 | filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); |
6066 | DBUG_RETURN(0); |
6067 | } |
6068 | |
6069 | int spider_oracle_handler::append_insert_part() |
6070 | { |
6071 | int error_num; |
6072 | DBUG_ENTER("spider_oracle_handler::append_insert_part" ); |
6073 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6074 | error_num = append_insert(&insert_sql, 0); |
6075 | DBUG_RETURN(error_num); |
6076 | } |
6077 | |
6078 | int spider_oracle_handler::append_insert( |
6079 | spider_string *str, |
6080 | int link_idx |
6081 | ) { |
6082 | DBUG_ENTER("spider_oracle_handler::append_insert" ); |
6083 | if (str->reserve(SPIDER_SQL_INSERT_LEN)) |
6084 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6085 | str->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); |
6086 | DBUG_RETURN(0); |
6087 | } |
6088 | |
6089 | int spider_oracle_handler::append_update_part() |
6090 | { |
6091 | int error_num; |
6092 | DBUG_ENTER("spider_oracle_handler::append_update_part" ); |
6093 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6094 | error_num = append_update(&update_sql, 0); |
6095 | DBUG_RETURN(error_num); |
6096 | } |
6097 | |
6098 | int spider_oracle_handler::append_update( |
6099 | spider_string *str, |
6100 | int link_idx |
6101 | ) { |
6102 | DBUG_ENTER("spider_oracle_handler::append_update" ); |
6103 | if (str->reserve(SPIDER_SQL_UPDATE_LEN)) |
6104 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6105 | str->q_append(SPIDER_SQL_UPDATE_STR, SPIDER_SQL_UPDATE_LEN); |
6106 | if (str->reserve(oracle_share->db_nm_max_length + |
6107 | SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + |
6108 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) |
6109 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6110 | table_name_pos = str->length(); |
6111 | append_table_name_with_adjusting(str, link_idx, SPIDER_SQL_TYPE_UPDATE_SQL); |
6112 | DBUG_RETURN(0); |
6113 | } |
6114 | |
6115 | int spider_oracle_handler::append_delete_part() |
6116 | { |
6117 | int error_num; |
6118 | DBUG_ENTER("spider_oracle_handler::append_delete_part" ); |
6119 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6120 | error_num = append_delete(&update_sql); |
6121 | DBUG_RETURN(error_num); |
6122 | } |
6123 | |
6124 | int spider_oracle_handler::append_delete( |
6125 | spider_string *str |
6126 | ) { |
6127 | DBUG_ENTER("spider_oracle_handler::append_delete" ); |
6128 | if (str->reserve(SPIDER_SQL_DELETE_LEN)) |
6129 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6130 | str->q_append(SPIDER_SQL_DELETE_STR, SPIDER_SQL_DELETE_LEN); |
6131 | str->length(str->length() - 1); |
6132 | DBUG_RETURN(0); |
6133 | } |
6134 | |
6135 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
6136 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
6137 | int spider_oracle_handler::append_increment_update_set_part() |
6138 | { |
6139 | int error_num; |
6140 | DBUG_ENTER("spider_oracle_handler::append_increment_update_set_part" ); |
6141 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6142 | error_num = append_increment_update_set(&update_sql); |
6143 | DBUG_RETURN(error_num); |
6144 | } |
6145 | |
6146 | int spider_oracle_handler::append_increment_update_set( |
6147 | spider_string *str |
6148 | ) { |
6149 | uint field_name_length; |
6150 | uint roop_count; |
6151 | Field *field; |
6152 | DBUG_ENTER("spider_oracle_handler::append_increment_update_set" ); |
6153 | if (str->reserve(SPIDER_SQL_SET_LEN)) |
6154 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6155 | str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); |
6156 | const SPIDER_HS_STRING_REF *value = hs_upds.ptr(); |
6157 | for (roop_count = 0; roop_count < hs_upds.size(); |
6158 | roop_count++) |
6159 | { |
6160 | DBUG_PRINT("info" ,("spider value_size[%u]=%zu" , roop_count, |
6161 | value[roop_count].size())); |
6162 | #ifndef DBUG_OFF |
6163 | char print_buf[MAX_FIELD_WIDTH]; |
6164 | if (value[roop_count].size() < MAX_FIELD_WIDTH) |
6165 | { |
6166 | memcpy(print_buf, value[roop_count].begin(), value[roop_count].size()); |
6167 | print_buf[value[roop_count].size()] = '\0'; |
6168 | DBUG_PRINT("info" ,("spider value[%u]=%s" , roop_count, print_buf)); |
6169 | } |
6170 | #endif |
6171 | if ( |
6172 | value[roop_count].size() == 1 && |
6173 | *(value[roop_count].begin()) == '0' |
6174 | ) |
6175 | continue; |
6176 | |
6177 | Field *top_table_field = |
6178 | spider->get_top_table_field(spider->hs_pushed_ret_fields[roop_count]); |
6179 | if (!(field = spider->field_exchange(top_table_field))) |
6180 | continue; |
6181 | field_name_length = |
6182 | oracle_share->column_name_str[field->field_index].length(); |
6183 | |
6184 | if (str->reserve(field_name_length * 2 + /* SPIDER_SQL_NAME_QUOTE_LEN */ |
6185 | 4 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_HS_INCREMENT_LEN + |
6186 | SPIDER_SQL_COMMA_LEN + value[roop_count].size())) |
6187 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6188 | |
6189 | oracle_share->append_column_name(str, field->field_index); |
6190 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
6191 | oracle_share->append_column_name(str, field->field_index); |
6192 | if (spider->hs_increment) |
6193 | str->q_append(SPIDER_SQL_HS_INCREMENT_STR, |
6194 | SPIDER_SQL_HS_INCREMENT_LEN); |
6195 | else |
6196 | str->q_append(SPIDER_SQL_HS_DECREMENT_STR, |
6197 | SPIDER_SQL_HS_DECREMENT_LEN); |
6198 | str->q_append(value[roop_count].begin(), value[roop_count].size()); |
6199 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6200 | } |
6201 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
6202 | DBUG_RETURN(0); |
6203 | } |
6204 | #endif |
6205 | #endif |
6206 | |
6207 | int spider_oracle_handler::append_update_set_part() |
6208 | { |
6209 | int error_num; |
6210 | DBUG_ENTER("spider_oracle_handler::append_update_set_part" ); |
6211 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6212 | update_set_pos = update_sql.length(); |
6213 | error_num = append_update_set(&update_sql); |
6214 | where_pos = update_sql.length(); |
6215 | DBUG_RETURN(error_num); |
6216 | } |
6217 | |
6218 | int spider_oracle_handler::append_update_set( |
6219 | spider_string *str |
6220 | ) { |
6221 | uint field_name_length; |
6222 | SPIDER_SHARE *share = spider->share; |
6223 | TABLE *table = spider->get_table(); |
6224 | Field **fields; |
6225 | DBUG_ENTER("spider_oracle_handler::append_update_set" ); |
6226 | if (str->reserve(SPIDER_SQL_SET_LEN)) |
6227 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6228 | str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); |
6229 | for (fields = table->field; *fields; fields++) |
6230 | { |
6231 | if (bitmap_is_set(table->write_set, (*fields)->field_index)) |
6232 | { |
6233 | field_name_length = |
6234 | oracle_share->column_name_str[(*fields)->field_index].length(); |
6235 | if ((*fields)->is_null()) |
6236 | { |
6237 | if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ |
6238 | 2 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_NULL_LEN + |
6239 | SPIDER_SQL_COMMA_LEN)) |
6240 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6241 | oracle_share->append_column_name(str, (*fields)->field_index); |
6242 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
6243 | str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); |
6244 | } else { |
6245 | if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ |
6246 | 2 + SPIDER_SQL_EQUAL_LEN)) |
6247 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6248 | oracle_share->append_column_name(str, (*fields)->field_index); |
6249 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
6250 | #ifndef DBUG_OFF |
6251 | my_bitmap_map *tmp_map = dbug_tmp_use_all_columns(table, |
6252 | table->read_set); |
6253 | #endif |
6254 | if ( |
6255 | spider_db_oracle_utility. |
6256 | append_column_value(spider, str, *fields, NULL, |
6257 | share->access_charset) || |
6258 | str->reserve(SPIDER_SQL_COMMA_LEN) |
6259 | ) { |
6260 | #ifndef DBUG_OFF |
6261 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
6262 | #endif |
6263 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6264 | } |
6265 | #ifndef DBUG_OFF |
6266 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
6267 | #endif |
6268 | } |
6269 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6270 | } |
6271 | } |
6272 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
6273 | DBUG_RETURN(0); |
6274 | } |
6275 | |
6276 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
6277 | int spider_oracle_handler::append_direct_update_set_part() |
6278 | { |
6279 | int error_num; |
6280 | DBUG_ENTER("spider_oracle_handler::append_direct_update_set_part" ); |
6281 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6282 | update_set_pos = update_sql.length(); |
6283 | error_num = append_direct_update_set(&update_sql); |
6284 | where_pos = update_sql.length(); |
6285 | DBUG_RETURN(error_num); |
6286 | } |
6287 | |
6288 | int spider_oracle_handler::append_direct_update_set( |
6289 | spider_string *str |
6290 | ) { |
6291 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
6292 | uint field_name_length; |
6293 | SPIDER_SHARE *share = spider->share; |
6294 | #ifndef DBUG_OFF |
6295 | TABLE *table = spider->get_table(); |
6296 | #endif |
6297 | #endif |
6298 | DBUG_ENTER("spider_oracle_handler::append_direct_update_set" ); |
6299 | if ( |
6300 | spider->direct_update_kinds == SPIDER_SQL_KIND_SQL && |
6301 | spider->direct_update_fields |
6302 | ) { |
6303 | if (str->reserve(SPIDER_SQL_SET_LEN)) |
6304 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6305 | str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); |
6306 | DBUG_RETURN(append_update_columns(str, NULL, 0)); |
6307 | } |
6308 | |
6309 | if ( |
6310 | (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) |
6311 | ) { |
6312 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
6313 | size_t roop_count; |
6314 | Field *field; |
6315 | if (str->reserve(SPIDER_SQL_SET_LEN)) |
6316 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6317 | str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); |
6318 | for (roop_count = 0; roop_count < spider->hs_pushed_ret_fields_num; |
6319 | roop_count++) |
6320 | { |
6321 | Field *top_table_field = |
6322 | spider->get_top_table_field(spider->hs_pushed_ret_fields[roop_count]); |
6323 | if (!(field = spider->field_exchange(top_table_field))) |
6324 | continue; |
6325 | field_name_length = |
6326 | oracle_share->column_name_str[field->field_index].length(); |
6327 | if (top_table_field->is_null()) |
6328 | { |
6329 | if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ |
6330 | 2 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_NULL_LEN + |
6331 | SPIDER_SQL_COMMA_LEN)) |
6332 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6333 | oracle_share->append_column_name(str, field->field_index); |
6334 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
6335 | str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); |
6336 | } else { |
6337 | if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ |
6338 | 2 + SPIDER_SQL_EQUAL_LEN)) |
6339 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6340 | oracle_share->append_column_name(str, field->field_index); |
6341 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
6342 | #ifndef DBUG_OFF |
6343 | my_bitmap_map *tmp_map = dbug_tmp_use_all_columns(table, |
6344 | table->read_set); |
6345 | #endif |
6346 | if ( |
6347 | spider_db_oracle_utility. |
6348 | append_column_value(spider, str, top_table_field, NULL, |
6349 | share->access_charset) || |
6350 | str->reserve(SPIDER_SQL_COMMA_LEN) |
6351 | ) { |
6352 | #ifndef DBUG_OFF |
6353 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
6354 | #endif |
6355 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6356 | } |
6357 | #ifndef DBUG_OFF |
6358 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
6359 | #endif |
6360 | } |
6361 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6362 | } |
6363 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
6364 | #else |
6365 | DBUG_ASSERT(0); |
6366 | #endif |
6367 | } |
6368 | DBUG_RETURN(0); |
6369 | } |
6370 | |
6371 | int spider_oracle_handler::append_dup_update_pushdown_part( |
6372 | const char *alias, |
6373 | uint alias_length |
6374 | ) { |
6375 | int error_num; |
6376 | DBUG_ENTER("spider_oracle_handler::append_dup_update_pushdown_part" ); |
6377 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6378 | dup_update_sql.length(0); |
6379 | error_num = append_update_columns(&dup_update_sql, alias, alias_length); |
6380 | DBUG_RETURN(error_num); |
6381 | } |
6382 | |
6383 | int spider_oracle_handler::append_update_columns_part( |
6384 | const char *alias, |
6385 | uint alias_length |
6386 | ) { |
6387 | int error_num; |
6388 | DBUG_ENTER("spider_oracle_handler::append_update_columns_part" ); |
6389 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6390 | error_num = append_update_columns(&update_sql, alias, alias_length); |
6391 | DBUG_RETURN(error_num); |
6392 | } |
6393 | |
6394 | int spider_oracle_handler::check_update_columns_part() |
6395 | { |
6396 | int error_num; |
6397 | DBUG_ENTER("spider_oracle_handler::check_update_columns_part" ); |
6398 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6399 | error_num = append_update_columns(NULL, NULL, 0); |
6400 | DBUG_RETURN(error_num); |
6401 | } |
6402 | |
6403 | int spider_oracle_handler::append_update_columns( |
6404 | spider_string *str, |
6405 | const char *alias, |
6406 | uint alias_length |
6407 | ) { |
6408 | int error_num; |
6409 | List_iterator_fast<Item> fi(*spider->direct_update_fields), |
6410 | vi(*spider->direct_update_values); |
6411 | Item *field, *value; |
6412 | DBUG_ENTER("spider_oracle_handler::append_update_columns" ); |
6413 | while ((field = fi++)) |
6414 | { |
6415 | value = vi++; |
6416 | if ((error_num = spider_db_print_item_type( |
6417 | (Item *) field, spider, str, alias, alias_length, |
6418 | spider_dbton_oracle.dbton_id, FALSE, NULL))) |
6419 | { |
6420 | if ( |
6421 | error_num == ER_SPIDER_COND_SKIP_NUM && |
6422 | field->type() == Item::FIELD_ITEM && |
6423 | ((Item_field *) field)->field |
6424 | ) |
6425 | continue; |
6426 | DBUG_RETURN(error_num); |
6427 | } |
6428 | if (str) |
6429 | { |
6430 | if (str->reserve(SPIDER_SQL_EQUAL_LEN)) |
6431 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6432 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
6433 | } |
6434 | if ((error_num = spider_db_print_item_type( |
6435 | (Item *) value, spider, str, alias, alias_length, |
6436 | spider_dbton_oracle.dbton_id, FALSE, NULL))) |
6437 | DBUG_RETURN(error_num); |
6438 | if (str) |
6439 | { |
6440 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
6441 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6442 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6443 | } |
6444 | } |
6445 | if (str) |
6446 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
6447 | DBUG_RETURN(0); |
6448 | /* |
6449 | error_num = spider_db_append_update_columns(spider, str, |
6450 | alias, alias_length, spider_dbton_oracle.dbton_id); |
6451 | DBUG_RETURN(error_num); |
6452 | */ |
6453 | } |
6454 | #endif |
6455 | |
6456 | int spider_oracle_handler::append_select_part( |
6457 | ulong sql_type |
6458 | ) { |
6459 | int error_num; |
6460 | spider_string *str; |
6461 | DBUG_ENTER("spider_oracle_handler::append_select_part" ); |
6462 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6463 | switch (sql_type) |
6464 | { |
6465 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6466 | str = &sql; |
6467 | break; |
6468 | case SPIDER_SQL_TYPE_HANDLER: |
6469 | str = &ha_sql; |
6470 | break; |
6471 | default: |
6472 | DBUG_RETURN(0); |
6473 | } |
6474 | error_num = append_select(str, sql_type); |
6475 | DBUG_RETURN(error_num); |
6476 | } |
6477 | |
6478 | int spider_oracle_handler::append_select( |
6479 | spider_string *str, |
6480 | ulong sql_type |
6481 | ) { |
6482 | DBUG_ENTER("spider_oracle_handler::append_select" ); |
6483 | if (sql_type == SPIDER_SQL_TYPE_HANDLER) |
6484 | { |
6485 | if (str->reserve(SPIDER_SQL_HANDLER_LEN)) |
6486 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6487 | str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); |
6488 | } else { |
6489 | if (str->reserve(SPIDER_SQL_SELECT_LEN)) |
6490 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6491 | str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); |
6492 | if (spider->result_list.direct_distinct) |
6493 | { |
6494 | if (str->reserve(SPIDER_SQL_DISTINCT_LEN)) |
6495 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6496 | str->q_append(SPIDER_SQL_DISTINCT_STR, SPIDER_SQL_DISTINCT_LEN); |
6497 | } |
6498 | } |
6499 | DBUG_RETURN(0); |
6500 | } |
6501 | |
6502 | int spider_oracle_handler::append_table_select_part( |
6503 | ulong sql_type |
6504 | ) { |
6505 | int error_num; |
6506 | spider_string *str; |
6507 | DBUG_ENTER("spider_oracle_handler::append_table_select_part" ); |
6508 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6509 | switch (sql_type) |
6510 | { |
6511 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6512 | str = &sql; |
6513 | break; |
6514 | default: |
6515 | DBUG_RETURN(0); |
6516 | } |
6517 | error_num = append_table_select(str); |
6518 | DBUG_RETURN(error_num); |
6519 | } |
6520 | |
6521 | int spider_oracle_handler::append_table_select( |
6522 | spider_string *str |
6523 | ) { |
6524 | DBUG_ENTER("spider_oracle_handler::append_table_select" ); |
6525 | table_name_pos = str->length() + oracle_share->table_select_pos; |
6526 | if (str->append(*(oracle_share->table_select))) |
6527 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6528 | DBUG_RETURN(0); |
6529 | } |
6530 | |
6531 | int spider_oracle_handler::append_key_select_part( |
6532 | ulong sql_type, |
6533 | uint idx |
6534 | ) { |
6535 | int error_num; |
6536 | spider_string *str; |
6537 | DBUG_ENTER("spider_oracle_handler::append_key_select_part" ); |
6538 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6539 | switch (sql_type) |
6540 | { |
6541 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6542 | str = &sql; |
6543 | break; |
6544 | default: |
6545 | DBUG_RETURN(0); |
6546 | } |
6547 | error_num = append_key_select(str, idx); |
6548 | DBUG_RETURN(error_num); |
6549 | } |
6550 | |
6551 | int spider_oracle_handler::append_key_select( |
6552 | spider_string *str, |
6553 | uint idx |
6554 | ) { |
6555 | DBUG_ENTER("spider_oracle_handler::append_key_select" ); |
6556 | table_name_pos = str->length() + oracle_share->key_select_pos[idx]; |
6557 | if (str->append(oracle_share->key_select[idx])) |
6558 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6559 | DBUG_RETURN(0); |
6560 | } |
6561 | |
6562 | int spider_oracle_handler::append_minimum_select_part( |
6563 | ulong sql_type |
6564 | ) { |
6565 | int error_num; |
6566 | spider_string *str; |
6567 | DBUG_ENTER("spider_oracle_handler::append_minimum_select_part" ); |
6568 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6569 | switch (sql_type) |
6570 | { |
6571 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6572 | str = &sql; |
6573 | break; |
6574 | default: |
6575 | DBUG_RETURN(0); |
6576 | } |
6577 | error_num = append_minimum_select(str, sql_type); |
6578 | DBUG_RETURN(error_num); |
6579 | } |
6580 | |
6581 | int spider_oracle_handler::append_minimum_select( |
6582 | spider_string *str, |
6583 | ulong sql_type |
6584 | ) { |
6585 | TABLE *table = spider->get_table(); |
6586 | Field **field; |
6587 | int field_length; |
6588 | bool appended = FALSE; |
6589 | DBUG_ENTER("spider_oracle_handler::append_minimum_select" ); |
6590 | minimum_select_bitmap_create(); |
6591 | for (field = table->field; *field; field++) |
6592 | { |
6593 | if (minimum_select_bit_is_set((*field)->field_index)) |
6594 | { |
6595 | /* |
6596 | spider_set_bit(minimum_select_bitmap, (*field)->field_index); |
6597 | */ |
6598 | field_length = |
6599 | oracle_share->column_name_str[(*field)->field_index].length(); |
6600 | if (str->reserve(field_length + |
6601 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
6602 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6603 | oracle_share->append_column_name(str, (*field)->field_index); |
6604 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6605 | appended = TRUE; |
6606 | } |
6607 | } |
6608 | if (appended) |
6609 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
6610 | else { |
6611 | if (str->reserve(SPIDER_SQL_ONE_LEN)) |
6612 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6613 | str->q_append(SPIDER_SQL_ONE_STR, SPIDER_SQL_ONE_LEN); |
6614 | } |
6615 | DBUG_RETURN(append_from(str, sql_type, first_link_idx)); |
6616 | } |
6617 | |
6618 | int spider_oracle_handler::append_table_select_with_alias( |
6619 | spider_string *str, |
6620 | const char *alias, |
6621 | uint alias_length |
6622 | ) { |
6623 | TABLE *table = spider->get_table(); |
6624 | Field **field; |
6625 | int field_length; |
6626 | DBUG_ENTER("spider_oracle_handler::append_table_select_with_alias" ); |
6627 | for (field = table->field; *field; field++) |
6628 | { |
6629 | field_length = |
6630 | oracle_share->column_name_str[(*field)->field_index].length(); |
6631 | if (str->reserve(alias_length + field_length + |
6632 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
6633 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6634 | str->q_append(alias, alias_length); |
6635 | oracle_share->append_column_name(str, (*field)->field_index); |
6636 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6637 | } |
6638 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
6639 | DBUG_RETURN(0); |
6640 | } |
6641 | |
6642 | int spider_oracle_handler::append_key_select_with_alias( |
6643 | spider_string *str, |
6644 | const KEY *key_info, |
6645 | const char *alias, |
6646 | uint alias_length |
6647 | ) { |
6648 | KEY_PART_INFO *key_part; |
6649 | Field *field; |
6650 | uint part_num; |
6651 | int field_length; |
6652 | DBUG_ENTER("spider_oracle_handler::append_key_select_with_alias" ); |
6653 | for (key_part = key_info->key_part, part_num = 0; |
6654 | part_num < spider_user_defined_key_parts(key_info); key_part++, part_num++) |
6655 | { |
6656 | field = key_part->field; |
6657 | field_length = oracle_share->column_name_str[field->field_index].length(); |
6658 | if (str->reserve(alias_length + field_length + |
6659 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
6660 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6661 | str->q_append(alias, alias_length); |
6662 | oracle_share->append_column_name(str, field->field_index); |
6663 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6664 | } |
6665 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
6666 | DBUG_RETURN(0); |
6667 | } |
6668 | |
6669 | int spider_oracle_handler::append_minimum_select_with_alias( |
6670 | spider_string *str, |
6671 | const char *alias, |
6672 | uint alias_length |
6673 | ) { |
6674 | TABLE *table = spider->get_table(); |
6675 | Field **field; |
6676 | int field_length; |
6677 | bool appended = FALSE; |
6678 | DBUG_ENTER("spider_oracle_handler::append_minimum_select_with_alias" ); |
6679 | minimum_select_bitmap_create(); |
6680 | for (field = table->field; *field; field++) |
6681 | { |
6682 | if (minimum_select_bit_is_set((*field)->field_index)) |
6683 | { |
6684 | /* |
6685 | spider_set_bit(minimum_select_bitmap, (*field)->field_index); |
6686 | */ |
6687 | field_length = |
6688 | oracle_share->column_name_str[(*field)->field_index].length(); |
6689 | if (str->reserve(alias_length + field_length + |
6690 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
6691 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6692 | str->q_append(alias, alias_length); |
6693 | oracle_share->append_column_name(str, (*field)->field_index); |
6694 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6695 | appended = TRUE; |
6696 | } |
6697 | } |
6698 | if (appended) |
6699 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
6700 | else { |
6701 | if (str->reserve(SPIDER_SQL_ONE_LEN)) |
6702 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6703 | str->q_append(SPIDER_SQL_ONE_STR, SPIDER_SQL_ONE_LEN); |
6704 | } |
6705 | DBUG_RETURN(0); |
6706 | } |
6707 | |
6708 | int spider_oracle_handler::append_select_columns_with_alias( |
6709 | spider_string *str, |
6710 | const char *alias, |
6711 | uint alias_length |
6712 | ) { |
6713 | int error_num; |
6714 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
6715 | DBUG_ENTER("spider_oracle_handler::append_select_columns_with_alias" ); |
6716 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
6717 | if ( |
6718 | result_list->direct_aggregate && |
6719 | (error_num = append_sum_select(str, alias, alias_length)) |
6720 | ) |
6721 | DBUG_RETURN(error_num); |
6722 | #endif |
6723 | if ((error_num = append_match_select(str, alias, alias_length))) |
6724 | DBUG_RETURN(error_num); |
6725 | if (!spider->select_column_mode) |
6726 | { |
6727 | if (result_list->keyread) |
6728 | DBUG_RETURN(append_key_select_with_alias( |
6729 | str, result_list->key_info, alias, alias_length)); |
6730 | else |
6731 | DBUG_RETURN(append_table_select_with_alias( |
6732 | str, alias, alias_length)); |
6733 | } |
6734 | DBUG_RETURN(append_minimum_select_with_alias(str, alias, alias_length)); |
6735 | } |
6736 | |
6737 | int spider_oracle_handler::append_hint_after_table_part( |
6738 | ulong sql_type |
6739 | ) { |
6740 | int error_num; |
6741 | spider_string *str; |
6742 | DBUG_ENTER("spider_oracle_handler::append_hint_after_table_part" ); |
6743 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6744 | switch (sql_type) |
6745 | { |
6746 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6747 | case SPIDER_SQL_TYPE_TMP_SQL: |
6748 | str = &sql; |
6749 | break; |
6750 | case SPIDER_SQL_TYPE_INSERT_SQL: |
6751 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
6752 | case SPIDER_SQL_TYPE_DELETE_SQL: |
6753 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
6754 | str = &update_sql; |
6755 | break; |
6756 | case SPIDER_SQL_TYPE_HANDLER: |
6757 | str = &ha_sql; |
6758 | break; |
6759 | default: |
6760 | DBUG_RETURN(0); |
6761 | } |
6762 | error_num = append_hint_after_table(str); |
6763 | DBUG_RETURN(error_num); |
6764 | } |
6765 | |
6766 | int spider_oracle_handler::append_hint_after_table( |
6767 | spider_string *str |
6768 | ) { |
6769 | int error_num; |
6770 | DBUG_ENTER("spider_oracle_handler::append_hint_after_table" ); |
6771 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6772 | if ( |
6773 | oracle_share->key_hint && |
6774 | (error_num = spider_db_append_hint_after_table(spider, |
6775 | str, &oracle_share->key_hint[spider->active_index])) |
6776 | ) |
6777 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6778 | DBUG_RETURN(0); |
6779 | } |
6780 | |
6781 | void spider_oracle_handler::set_where_pos( |
6782 | ulong sql_type |
6783 | ) { |
6784 | DBUG_ENTER("spider_oracle_handler::set_where_pos" ); |
6785 | switch (sql_type) |
6786 | { |
6787 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6788 | case SPIDER_SQL_TYPE_TMP_SQL: |
6789 | where_pos = sql.length(); |
6790 | break; |
6791 | case SPIDER_SQL_TYPE_INSERT_SQL: |
6792 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
6793 | case SPIDER_SQL_TYPE_DELETE_SQL: |
6794 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
6795 | where_pos = update_sql.length(); |
6796 | break; |
6797 | case SPIDER_SQL_TYPE_HANDLER: |
6798 | ha_read_pos = ha_sql.length(); |
6799 | break; |
6800 | default: |
6801 | break; |
6802 | } |
6803 | DBUG_VOID_RETURN; |
6804 | } |
6805 | |
6806 | void spider_oracle_handler::set_where_to_pos( |
6807 | ulong sql_type |
6808 | ) { |
6809 | DBUG_ENTER("spider_oracle_handler::set_where_to_pos" ); |
6810 | switch (sql_type) |
6811 | { |
6812 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6813 | case SPIDER_SQL_TYPE_TMP_SQL: |
6814 | sql.length(where_pos); |
6815 | break; |
6816 | case SPIDER_SQL_TYPE_INSERT_SQL: |
6817 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
6818 | case SPIDER_SQL_TYPE_DELETE_SQL: |
6819 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
6820 | update_sql.length(where_pos); |
6821 | break; |
6822 | case SPIDER_SQL_TYPE_HANDLER: |
6823 | ha_sql.length(ha_read_pos); |
6824 | break; |
6825 | default: |
6826 | break; |
6827 | } |
6828 | DBUG_VOID_RETURN; |
6829 | } |
6830 | |
6831 | int spider_oracle_handler::check_item_type( |
6832 | Item *item |
6833 | ) { |
6834 | int error_num; |
6835 | DBUG_ENTER("spider_oracle_handler::check_item_type" ); |
6836 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6837 | error_num = spider_db_print_item_type(item, spider, NULL, NULL, 0, |
6838 | spider_dbton_oracle.dbton_id, FALSE, NULL); |
6839 | DBUG_RETURN(error_num); |
6840 | } |
6841 | |
6842 | int spider_oracle_handler::append_values_connector_part( |
6843 | ulong sql_type |
6844 | ) { |
6845 | int error_num; |
6846 | spider_string *str; |
6847 | DBUG_ENTER("spider_oracle_handler::append_values_connector_part" ); |
6848 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6849 | switch (sql_type) |
6850 | { |
6851 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6852 | str = &sql; |
6853 | break; |
6854 | case SPIDER_SQL_TYPE_TMP_SQL: |
6855 | str = &tmp_sql; |
6856 | break; |
6857 | default: |
6858 | DBUG_RETURN(0); |
6859 | } |
6860 | error_num = append_values_connector(str); |
6861 | DBUG_RETURN(error_num); |
6862 | } |
6863 | |
6864 | int spider_oracle_handler::append_values_connector( |
6865 | spider_string *str |
6866 | ) { |
6867 | DBUG_ENTER("spider_oracle_handler::append_values_connector" ); |
6868 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6869 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + |
6870 | SPIDER_SQL_COMMA_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) |
6871 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6872 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
6873 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
6874 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
6875 | DBUG_RETURN(0); |
6876 | } |
6877 | |
6878 | int spider_oracle_handler::append_values_terminator_part( |
6879 | ulong sql_type |
6880 | ) { |
6881 | int error_num; |
6882 | spider_string *str; |
6883 | DBUG_ENTER("spider_oracle_handler::append_values_terminator_part" ); |
6884 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6885 | switch (sql_type) |
6886 | { |
6887 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6888 | str = &sql; |
6889 | break; |
6890 | case SPIDER_SQL_TYPE_TMP_SQL: |
6891 | str = &tmp_sql; |
6892 | break; |
6893 | default: |
6894 | DBUG_RETURN(0); |
6895 | } |
6896 | error_num = append_values_terminator(str); |
6897 | DBUG_RETURN(error_num); |
6898 | } |
6899 | |
6900 | int spider_oracle_handler::append_values_terminator( |
6901 | spider_string *str |
6902 | ) { |
6903 | DBUG_ENTER("spider_oracle_handler::append_values_terminator" ); |
6904 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6905 | str->length(str->length() - |
6906 | SPIDER_SQL_COMMA_LEN - SPIDER_SQL_OPEN_PAREN_LEN); |
6907 | DBUG_RETURN(0); |
6908 | } |
6909 | |
6910 | int spider_oracle_handler::append_union_table_connector_part( |
6911 | ulong sql_type |
6912 | ) { |
6913 | int error_num; |
6914 | spider_string *str; |
6915 | DBUG_ENTER("spider_oracle_handler::append_union_table_connector_part" ); |
6916 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6917 | switch (sql_type) |
6918 | { |
6919 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6920 | str = &sql; |
6921 | break; |
6922 | case SPIDER_SQL_TYPE_TMP_SQL: |
6923 | str = &tmp_sql; |
6924 | break; |
6925 | default: |
6926 | DBUG_RETURN(0); |
6927 | } |
6928 | error_num = append_union_table_connector(str); |
6929 | DBUG_RETURN(error_num); |
6930 | } |
6931 | |
6932 | int spider_oracle_handler::append_union_table_connector( |
6933 | spider_string *str |
6934 | ) { |
6935 | DBUG_ENTER("spider_oracle_handler::append_union_table_connector" ); |
6936 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6937 | if (str->reserve((SPIDER_SQL_SPACE_LEN * 2) + SPIDER_SQL_UNION_ALL_LEN)) |
6938 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6939 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
6940 | str->q_append(SPIDER_SQL_UNION_ALL_STR, SPIDER_SQL_UNION_ALL_LEN); |
6941 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
6942 | DBUG_RETURN(0); |
6943 | } |
6944 | |
6945 | int spider_oracle_handler::append_union_table_terminator_part( |
6946 | ulong sql_type |
6947 | ) { |
6948 | int error_num; |
6949 | spider_string *str; |
6950 | DBUG_ENTER("spider_oracle_handler::append_union_table_terminator_part" ); |
6951 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6952 | switch (sql_type) |
6953 | { |
6954 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6955 | str = &sql; |
6956 | break; |
6957 | default: |
6958 | DBUG_RETURN(0); |
6959 | } |
6960 | error_num = append_union_table_terminator(str); |
6961 | DBUG_RETURN(error_num); |
6962 | } |
6963 | |
6964 | int spider_oracle_handler::append_union_table_terminator( |
6965 | spider_string *str |
6966 | ) { |
6967 | DBUG_ENTER("spider_oracle_handler::append_union_table_terminator" ); |
6968 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6969 | str->length(str->length() - |
6970 | ((SPIDER_SQL_SPACE_LEN * 2) + SPIDER_SQL_UNION_ALL_LEN)); |
6971 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
6972 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
6973 | table_name_pos = str->length() + SPIDER_SQL_SPACE_LEN + SPIDER_SQL_A_LEN + |
6974 | SPIDER_SQL_COMMA_LEN; |
6975 | if (str->reserve(tmp_sql.length() - SPIDER_SQL_FROM_LEN)) |
6976 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
6977 | str->q_append(tmp_sql.ptr() + SPIDER_SQL_FROM_LEN, |
6978 | tmp_sql.length() - SPIDER_SQL_FROM_LEN); |
6979 | DBUG_RETURN(0); |
6980 | } |
6981 | |
6982 | int spider_oracle_handler::append_key_column_values_part( |
6983 | const key_range *start_key, |
6984 | ulong sql_type |
6985 | ) { |
6986 | int error_num; |
6987 | spider_string *str; |
6988 | DBUG_ENTER("spider_oracle_handler::append_key_column_values_part" ); |
6989 | switch (sql_type) |
6990 | { |
6991 | case SPIDER_SQL_TYPE_SELECT_SQL: |
6992 | str = &sql; |
6993 | break; |
6994 | case SPIDER_SQL_TYPE_TMP_SQL: |
6995 | str = &tmp_sql; |
6996 | break; |
6997 | default: |
6998 | DBUG_RETURN(0); |
6999 | } |
7000 | error_num = append_key_column_values(str, start_key); |
7001 | DBUG_RETURN(error_num); |
7002 | } |
7003 | |
7004 | int spider_oracle_handler::append_key_column_values( |
7005 | spider_string *str, |
7006 | const key_range *start_key |
7007 | ) { |
7008 | int error_num; |
7009 | const uchar *ptr; |
7010 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
7011 | SPIDER_SHARE *share = spider->share; |
7012 | KEY *key_info = result_list->key_info; |
7013 | uint length; |
7014 | uint store_length; |
7015 | key_part_map full_key_part_map = |
7016 | make_prev_keypart_map(spider_user_defined_key_parts(key_info)); |
7017 | key_part_map start_key_part_map; |
7018 | KEY_PART_INFO *key_part; |
7019 | Field *field; |
7020 | DBUG_ENTER("spider_oracle_handler::append_key_column_values" ); |
7021 | start_key_part_map = start_key->keypart_map & full_key_part_map; |
7022 | DBUG_PRINT("info" , ("spider spider_user_defined_key_parts=%u" , |
7023 | spider_user_defined_key_parts(key_info))); |
7024 | DBUG_PRINT("info" , ("spider full_key_part_map=%lu" , full_key_part_map)); |
7025 | DBUG_PRINT("info" , ("spider start_key_part_map=%lu" , start_key_part_map)); |
7026 | |
7027 | if (!start_key_part_map) |
7028 | DBUG_RETURN(0); |
7029 | |
7030 | for ( |
7031 | key_part = key_info->key_part, |
7032 | length = 0; |
7033 | start_key_part_map; |
7034 | start_key_part_map >>= 1, |
7035 | key_part++, |
7036 | length += store_length |
7037 | ) { |
7038 | store_length = key_part->store_length; |
7039 | ptr = start_key->key + length; |
7040 | field = key_part->field; |
7041 | if ((error_num = spider_db_append_null_value(str, key_part, &ptr))) |
7042 | { |
7043 | if (error_num > 0) |
7044 | DBUG_RETURN(error_num); |
7045 | } else { |
7046 | if (spider_db_oracle_utility.append_column_value(spider, str, field, ptr, |
7047 | share->access_charset)) |
7048 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7049 | } |
7050 | |
7051 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
7052 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7053 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
7054 | } |
7055 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
7056 | DBUG_RETURN(0); |
7057 | } |
7058 | |
7059 | int spider_oracle_handler::append_key_column_values_with_name_part( |
7060 | const key_range *start_key, |
7061 | ulong sql_type |
7062 | ) { |
7063 | int error_num; |
7064 | spider_string *str; |
7065 | DBUG_ENTER("spider_oracle_handler::append_key_column_values_with_name_part" ); |
7066 | switch (sql_type) |
7067 | { |
7068 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7069 | str = &sql; |
7070 | break; |
7071 | case SPIDER_SQL_TYPE_TMP_SQL: |
7072 | str = &tmp_sql; |
7073 | break; |
7074 | default: |
7075 | DBUG_RETURN(0); |
7076 | } |
7077 | error_num = append_key_column_values_with_name(str, start_key); |
7078 | DBUG_RETURN(error_num); |
7079 | } |
7080 | |
7081 | int spider_oracle_handler::append_key_column_values_with_name( |
7082 | spider_string *str, |
7083 | const key_range *start_key |
7084 | ) { |
7085 | int error_num; |
7086 | const uchar *ptr; |
7087 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
7088 | SPIDER_SHARE *share = spider->share; |
7089 | KEY *key_info = result_list->key_info; |
7090 | uint length; |
7091 | uint key_name_length, key_count; |
7092 | uint store_length; |
7093 | key_part_map full_key_part_map = |
7094 | make_prev_keypart_map(spider_user_defined_key_parts(key_info)); |
7095 | key_part_map start_key_part_map; |
7096 | KEY_PART_INFO *key_part; |
7097 | Field *field; |
7098 | char tmp_buf[MAX_FIELD_WIDTH]; |
7099 | DBUG_ENTER("spider_oracle_handler::append_key_column_values_with_name" ); |
7100 | start_key_part_map = start_key->keypart_map & full_key_part_map; |
7101 | DBUG_PRINT("info" , ("spider spider_user_defined_key_parts=%u" , |
7102 | spider_user_defined_key_parts(key_info))); |
7103 | DBUG_PRINT("info" , ("spider full_key_part_map=%lu" , full_key_part_map)); |
7104 | DBUG_PRINT("info" , ("spider start_key_part_map=%lu" , start_key_part_map)); |
7105 | |
7106 | if (!start_key_part_map) |
7107 | DBUG_RETURN(0); |
7108 | |
7109 | for ( |
7110 | key_part = key_info->key_part, |
7111 | length = 0, |
7112 | key_count = 0; |
7113 | start_key_part_map; |
7114 | start_key_part_map >>= 1, |
7115 | key_part++, |
7116 | length += store_length, |
7117 | key_count++ |
7118 | ) { |
7119 | store_length = key_part->store_length; |
7120 | ptr = start_key->key + length; |
7121 | field = key_part->field; |
7122 | if ((error_num = spider_db_append_null_value(str, key_part, &ptr))) |
7123 | { |
7124 | if (error_num > 0) |
7125 | DBUG_RETURN(error_num); |
7126 | } else { |
7127 | if (spider_db_oracle_utility.append_column_value(spider, str, field, ptr, |
7128 | share->access_charset)) |
7129 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7130 | } |
7131 | |
7132 | key_name_length = my_sprintf(tmp_buf, (tmp_buf, "c%u" , key_count)); |
7133 | if (str->reserve(SPIDER_SQL_SPACE_LEN + key_name_length + |
7134 | SPIDER_SQL_COMMA_LEN)) |
7135 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7136 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
7137 | str->q_append(tmp_buf, key_name_length); |
7138 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
7139 | } |
7140 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
7141 | DBUG_RETURN(0); |
7142 | } |
7143 | |
7144 | int spider_oracle_handler::append_key_where_part( |
7145 | const key_range *start_key, |
7146 | const key_range *end_key, |
7147 | ulong sql_type |
7148 | ) { |
7149 | int error_num; |
7150 | spider_string *str, *str_part = NULL, *str_part2 = NULL; |
7151 | bool set_order; |
7152 | DBUG_ENTER("spider_oracle_handler::append_key_where_part" ); |
7153 | switch (sql_type) |
7154 | { |
7155 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7156 | str = &sql; |
7157 | set_order = FALSE; |
7158 | break; |
7159 | case SPIDER_SQL_TYPE_TMP_SQL: |
7160 | str = &tmp_sql; |
7161 | set_order = FALSE; |
7162 | break; |
7163 | case SPIDER_SQL_TYPE_INSERT_SQL: |
7164 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
7165 | case SPIDER_SQL_TYPE_DELETE_SQL: |
7166 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
7167 | str = &update_sql; |
7168 | set_order = FALSE; |
7169 | break; |
7170 | case SPIDER_SQL_TYPE_HANDLER: |
7171 | str = &ha_sql; |
7172 | ha_read_pos = str->length(); |
7173 | str_part = &sql_part; |
7174 | str_part2 = &sql_part2; |
7175 | str_part->length(0); |
7176 | str_part2->length(0); |
7177 | set_order = TRUE; |
7178 | break; |
7179 | default: |
7180 | DBUG_RETURN(0); |
7181 | } |
7182 | error_num = append_key_where(str, str_part, str_part2, start_key, end_key, |
7183 | sql_type, set_order); |
7184 | DBUG_RETURN(error_num); |
7185 | } |
7186 | |
7187 | int spider_oracle_handler::append_key_where( |
7188 | spider_string *str, |
7189 | spider_string *str_part, |
7190 | spider_string *str_part2, |
7191 | const key_range *start_key, |
7192 | const key_range *end_key, |
7193 | ulong sql_type, |
7194 | bool set_order |
7195 | ) { |
7196 | int error_num; |
7197 | DBUG_ENTER("spider_oracle_handler::append_key_where" ); |
7198 | error_num = spider_db_append_key_where_internal(str, str_part, str_part2, |
7199 | start_key, end_key, spider, set_order, sql_type, |
7200 | spider_dbton_oracle.dbton_id); |
7201 | DBUG_RETURN(error_num); |
7202 | } |
7203 | |
7204 | int spider_oracle_handler::append_is_null_part( |
7205 | ulong sql_type, |
7206 | KEY_PART_INFO *key_part, |
7207 | const key_range *key, |
7208 | const uchar **ptr, |
7209 | bool key_eq, |
7210 | bool tgt_final |
7211 | ) { |
7212 | int error_num; |
7213 | spider_string *str, *str_part = NULL, *str_part2 = NULL; |
7214 | DBUG_ENTER("spider_oracle_handler::append_is_null_part" ); |
7215 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7216 | switch (sql_type) |
7217 | { |
7218 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7219 | case SPIDER_SQL_TYPE_TMP_SQL: |
7220 | str = &sql; |
7221 | break; |
7222 | case SPIDER_SQL_TYPE_INSERT_SQL: |
7223 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
7224 | case SPIDER_SQL_TYPE_DELETE_SQL: |
7225 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
7226 | str = &update_sql; |
7227 | break; |
7228 | case SPIDER_SQL_TYPE_HANDLER: |
7229 | str = &ha_sql; |
7230 | str_part = &sql_part; |
7231 | str_part2 = &sql_part2; |
7232 | break; |
7233 | default: |
7234 | DBUG_RETURN(0); |
7235 | } |
7236 | error_num = append_is_null(sql_type, str, str_part, str_part2, |
7237 | key_part, key, ptr, key_eq, tgt_final); |
7238 | DBUG_RETURN(error_num); |
7239 | } |
7240 | |
7241 | int spider_oracle_handler::append_is_null( |
7242 | ulong sql_type, |
7243 | spider_string *str, |
7244 | spider_string *str_part, |
7245 | spider_string *str_part2, |
7246 | KEY_PART_INFO *key_part, |
7247 | const key_range *key, |
7248 | const uchar **ptr, |
7249 | bool key_eq, |
7250 | bool tgt_final |
7251 | ) { |
7252 | DBUG_ENTER("spider_oracle_handler::append_is_null" ); |
7253 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7254 | if (key_part->null_bit) |
7255 | { |
7256 | if (*(*ptr)++) |
7257 | { |
7258 | if (sql_type == SPIDER_SQL_TYPE_HANDLER) |
7259 | { |
7260 | str = str_part; |
7261 | if ( |
7262 | key_eq || |
7263 | key->flag == HA_READ_KEY_EXACT || |
7264 | key->flag == HA_READ_KEY_OR_NEXT |
7265 | ) { |
7266 | if (str->reserve(SPIDER_SQL_IS_NULL_LEN)) |
7267 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7268 | str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); |
7269 | } else { |
7270 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
7271 | ha_next_pos = str->length(); |
7272 | if (str->reserve(SPIDER_SQL_FIRST_LEN)) |
7273 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7274 | str->q_append(SPIDER_SQL_FIRST_STR, SPIDER_SQL_FIRST_LEN); |
7275 | spider->result_list.ha_read_kind = 1; |
7276 | } |
7277 | str = str_part2; |
7278 | } |
7279 | if ( |
7280 | key_eq || |
7281 | key->flag == HA_READ_KEY_EXACT || |
7282 | key->flag == HA_READ_KEY_OR_NEXT |
7283 | ) { |
7284 | if (str->reserve(SPIDER_SQL_IS_NULL_LEN + |
7285 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
7286 | oracle_share->column_name_str[key_part->field->field_index].length())) |
7287 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7288 | oracle_share->append_column_name(str, key_part->field->field_index); |
7289 | str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); |
7290 | } else { |
7291 | if (str->reserve(SPIDER_SQL_IS_NOT_NULL_LEN + |
7292 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
7293 | oracle_share->column_name_str[key_part->field->field_index].length())) |
7294 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7295 | oracle_share->append_column_name(str, key_part->field->field_index); |
7296 | str->q_append(SPIDER_SQL_IS_NOT_NULL_STR, SPIDER_SQL_IS_NOT_NULL_LEN); |
7297 | } |
7298 | DBUG_RETURN(-1); |
7299 | } |
7300 | } |
7301 | DBUG_RETURN(0); |
7302 | } |
7303 | |
7304 | int spider_oracle_handler::append_where_terminator_part( |
7305 | ulong sql_type, |
7306 | bool set_order, |
7307 | int key_count |
7308 | ) { |
7309 | int error_num; |
7310 | spider_string *str, *str_part = NULL, *str_part2 = NULL; |
7311 | DBUG_ENTER("spider_oracle_handler::append_where_terminator_part" ); |
7312 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7313 | switch (sql_type) |
7314 | { |
7315 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7316 | case SPIDER_SQL_TYPE_TMP_SQL: |
7317 | str = &sql; |
7318 | break; |
7319 | case SPIDER_SQL_TYPE_INSERT_SQL: |
7320 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
7321 | case SPIDER_SQL_TYPE_DELETE_SQL: |
7322 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
7323 | str = &update_sql; |
7324 | break; |
7325 | case SPIDER_SQL_TYPE_HANDLER: |
7326 | str = &ha_sql; |
7327 | str_part = &sql_part; |
7328 | str_part2 = &sql_part2; |
7329 | break; |
7330 | default: |
7331 | DBUG_RETURN(0); |
7332 | } |
7333 | error_num = append_where_terminator(sql_type, str, str_part, str_part2, |
7334 | set_order, key_count); |
7335 | DBUG_RETURN(error_num); |
7336 | } |
7337 | |
7338 | int spider_oracle_handler::append_where_terminator( |
7339 | ulong sql_type, |
7340 | spider_string *str, |
7341 | spider_string *str_part, |
7342 | spider_string *str_part2, |
7343 | bool set_order, |
7344 | int key_count |
7345 | ) { |
7346 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
7347 | DBUG_ENTER("spider_oracle_handler::append_where_terminator" ); |
7348 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7349 | if (sql_type != SPIDER_SQL_TYPE_HANDLER) |
7350 | { |
7351 | str->length(str->length() - SPIDER_SQL_AND_LEN); |
7352 | if (!set_order) |
7353 | result_list->key_order = key_count; |
7354 | } else { |
7355 | str_part2->length(str_part2->length() - SPIDER_SQL_AND_LEN); |
7356 | |
7357 | str_part->length(str_part->length() - SPIDER_SQL_COMMA_LEN); |
7358 | if (!result_list->ha_read_kind) |
7359 | str_part->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
7360 | SPIDER_SQL_CLOSE_PAREN_LEN); |
7361 | if (str->append(*str_part)) |
7362 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7363 | uint clause_length = str->length() - ha_next_pos; |
7364 | if (clause_length < SPIDER_SQL_NEXT_LEN) |
7365 | { |
7366 | int roop_count; |
7367 | clause_length = SPIDER_SQL_NEXT_LEN - clause_length; |
7368 | if (str->reserve(clause_length)) |
7369 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7370 | for (roop_count = 0; roop_count < (int) clause_length; roop_count++) |
7371 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
7372 | } |
7373 | } |
7374 | DBUG_RETURN(0); |
7375 | } |
7376 | |
7377 | int spider_oracle_handler::append_match_where_part( |
7378 | ulong sql_type |
7379 | ) { |
7380 | int error_num; |
7381 | spider_string *str; |
7382 | DBUG_ENTER("spider_oracle_handler::append_match_where_part" ); |
7383 | switch (sql_type) |
7384 | { |
7385 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7386 | str = &sql; |
7387 | break; |
7388 | default: |
7389 | DBUG_ASSERT(0); |
7390 | DBUG_RETURN(0); |
7391 | } |
7392 | error_num = append_match_where(str); |
7393 | DBUG_RETURN(error_num); |
7394 | } |
7395 | |
7396 | int spider_oracle_handler::append_match_where( |
7397 | spider_string *str |
7398 | ) { |
7399 | int error_num; |
7400 | bool first = TRUE; |
7401 | st_spider_ft_info *ft_info = spider->ft_first; |
7402 | DBUG_ENTER("spider_oracle_handler::append_match_where" ); |
7403 | if (spider->ft_current) |
7404 | { |
7405 | while (TRUE) |
7406 | { |
7407 | if (ft_info->used_in_where) |
7408 | { |
7409 | if (first) |
7410 | { |
7411 | if (str->reserve(SPIDER_SQL_WHERE_LEN)) |
7412 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7413 | str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); |
7414 | first = FALSE; |
7415 | } |
7416 | if ((error_num = append_match_against(str, ft_info, NULL, 0))) |
7417 | DBUG_RETURN(error_num); |
7418 | if (str->reserve(SPIDER_SQL_AND_LEN)) |
7419 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7420 | str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
7421 | } |
7422 | |
7423 | if (ft_info == spider->ft_current) |
7424 | break; |
7425 | ft_info = ft_info->next; |
7426 | } |
7427 | if (!first) |
7428 | str->length(str->length() - SPIDER_SQL_AND_LEN); |
7429 | } |
7430 | DBUG_RETURN(0); |
7431 | } |
7432 | |
7433 | int spider_oracle_handler::append_update_where( |
7434 | spider_string *str, |
7435 | const TABLE *table, |
7436 | my_ptrdiff_t ptr_diff |
7437 | ) { |
7438 | uint field_name_length; |
7439 | Field **field; |
7440 | SPIDER_SHARE *share = spider->share; |
7441 | DBUG_ENTER("spider_oracle_handler::append_update_where" ); |
7442 | if (str->reserve(SPIDER_SQL_WHERE_LEN)) |
7443 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7444 | str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); |
7445 | for (field = table->field; *field; field++) |
7446 | { |
7447 | if ( |
7448 | table->s->primary_key == MAX_KEY || |
7449 | bitmap_is_set(table->read_set, (*field)->field_index) |
7450 | ) { |
7451 | field_name_length = |
7452 | oracle_share->column_name_str[(*field)->field_index].length(); |
7453 | if ((*field)->is_null(ptr_diff)) |
7454 | { |
7455 | if (str->reserve(field_name_length + |
7456 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
7457 | SPIDER_SQL_IS_NULL_LEN + SPIDER_SQL_AND_LEN)) |
7458 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7459 | oracle_share->append_column_name(str, (*field)->field_index); |
7460 | str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); |
7461 | } else { |
7462 | if (str->reserve(field_name_length + |
7463 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
7464 | SPIDER_SQL_EQUAL_LEN)) |
7465 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7466 | oracle_share->append_column_name(str, (*field)->field_index); |
7467 | str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); |
7468 | (*field)->move_field_offset(ptr_diff); |
7469 | if ( |
7470 | spider_db_oracle_utility. |
7471 | append_column_value(spider, str, *field, NULL, |
7472 | share->access_charset) || |
7473 | str->reserve(SPIDER_SQL_AND_LEN) |
7474 | ) |
7475 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7476 | (*field)->move_field_offset(-ptr_diff); |
7477 | } |
7478 | str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
7479 | } |
7480 | } |
7481 | /* |
7482 | str->length(str->length() - SPIDER_SQL_AND_LEN); |
7483 | */ |
7484 | if (str->reserve(SPIDER_SQL_LIMIT1_LEN)) |
7485 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7486 | str->q_append(SPIDER_SQL_LIMIT1_STR, SPIDER_SQL_LIMIT1_LEN); |
7487 | DBUG_RETURN(0); |
7488 | } |
7489 | |
7490 | int spider_oracle_handler::append_condition_part( |
7491 | const char *alias, |
7492 | uint alias_length, |
7493 | ulong sql_type, |
7494 | bool test_flg |
7495 | ) { |
7496 | int error_num; |
7497 | spider_string *str; |
7498 | bool start_where = FALSE; |
7499 | DBUG_ENTER("spider_oracle_handler::append_condition_part" ); |
7500 | switch (sql_type) |
7501 | { |
7502 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7503 | DBUG_PRINT("info" ,("spider case1 sql_type=%lu" , sql_type)); |
7504 | if (test_flg) |
7505 | { |
7506 | str = NULL; |
7507 | } else { |
7508 | str = &sql; |
7509 | start_where = ((int) str->length() == where_pos); |
7510 | } |
7511 | break; |
7512 | case SPIDER_SQL_TYPE_TMP_SQL: |
7513 | DBUG_PRINT("info" ,("spider case1 sql_type=%lu" , sql_type)); |
7514 | if (test_flg) |
7515 | { |
7516 | str = NULL; |
7517 | } else { |
7518 | str = &tmp_sql; |
7519 | start_where = ((int) str->length() == where_pos); |
7520 | } |
7521 | break; |
7522 | case SPIDER_SQL_TYPE_INSERT_SQL: |
7523 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
7524 | case SPIDER_SQL_TYPE_DELETE_SQL: |
7525 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
7526 | DBUG_PRINT("info" ,("spider case2 sql_type=%lu" , sql_type)); |
7527 | if (test_flg) |
7528 | { |
7529 | str = NULL; |
7530 | } else { |
7531 | str = &update_sql; |
7532 | start_where = ((int) str->length() == where_pos); |
7533 | } |
7534 | break; |
7535 | case SPIDER_SQL_TYPE_HANDLER: |
7536 | DBUG_PRINT("info" ,("spider case3 sql_type=%lu" , sql_type)); |
7537 | if (test_flg) |
7538 | { |
7539 | str = NULL; |
7540 | } else { |
7541 | str = &ha_sql; |
7542 | start_where = TRUE; |
7543 | if (spider->active_index == MAX_KEY) |
7544 | { |
7545 | set_where_pos(SPIDER_SQL_TYPE_HANDLER); |
7546 | if (str->reserve(SPIDER_SQL_READ_LEN + SPIDER_SQL_FIRST_LEN)) |
7547 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7548 | str->q_append(SPIDER_SQL_READ_STR, SPIDER_SQL_READ_LEN); |
7549 | ha_next_pos = str->length(); |
7550 | str->q_append(SPIDER_SQL_FIRST_STR, SPIDER_SQL_FIRST_LEN); |
7551 | sql_part2.length(0); |
7552 | } |
7553 | ha_where_pos = str->length(); |
7554 | |
7555 | if (sql_part2.length()) |
7556 | { |
7557 | str->append(sql_part2); |
7558 | start_where = FALSE; |
7559 | } |
7560 | } |
7561 | break; |
7562 | default: |
7563 | DBUG_PRINT("info" ,("spider default sql_type=%lu" , sql_type)); |
7564 | DBUG_RETURN(0); |
7565 | } |
7566 | error_num = append_condition(str, alias, alias_length, start_where, |
7567 | sql_type); |
7568 | DBUG_PRINT("info" ,("spider str=%s" , str ? str->c_ptr_safe() : "NULL" )); |
7569 | DBUG_PRINT("info" ,("spider length=%u" , str ? str->length() : 0)); |
7570 | DBUG_RETURN(error_num); |
7571 | } |
7572 | |
7573 | int spider_oracle_handler::append_condition( |
7574 | spider_string *str, |
7575 | const char *alias, |
7576 | uint alias_length, |
7577 | bool start_where, |
7578 | ulong sql_type |
7579 | ) { |
7580 | int error_num, restart_pos = 0, start_where_pos; |
7581 | SPIDER_CONDITION *tmp_cond = spider->condition; |
7582 | DBUG_ENTER("spider_oracle_handler::append_condition" ); |
7583 | DBUG_PRINT("info" ,("spider str=%p" , str)); |
7584 | DBUG_PRINT("info" ,("spider alias=%p" , alias)); |
7585 | DBUG_PRINT("info" ,("spider alias_length=%u" , alias_length)); |
7586 | DBUG_PRINT("info" ,("spider start_where=%s" , start_where ? "TRUE" : "FALSE" )); |
7587 | DBUG_PRINT("info" ,("spider sql_type=%lu" , sql_type)); |
7588 | if (str && start_where) |
7589 | { |
7590 | start_where_pos = str->length(); |
7591 | } else { |
7592 | start_where_pos = 0; |
7593 | } |
7594 | |
7595 | if (spider->is_clone && !tmp_cond) |
7596 | { |
7597 | tmp_cond = spider->pt_clone_source_handler->condition; |
7598 | } |
7599 | |
7600 | while (tmp_cond) |
7601 | { |
7602 | if (str) |
7603 | { |
7604 | restart_pos = str->length(); |
7605 | if (start_where) |
7606 | { |
7607 | if (str->reserve(SPIDER_SQL_WHERE_LEN)) |
7608 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7609 | str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); |
7610 | start_where = FALSE; |
7611 | } else { |
7612 | if (str->reserve(SPIDER_SQL_AND_LEN)) |
7613 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7614 | str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
7615 | } |
7616 | } |
7617 | if ((error_num = spider_db_print_item_type( |
7618 | (Item *) tmp_cond->cond, spider, str, alias, alias_length, |
7619 | spider_dbton_oracle.dbton_id, FALSE, NULL))) |
7620 | { |
7621 | if (str && error_num == ER_SPIDER_COND_SKIP_NUM) |
7622 | { |
7623 | DBUG_PRINT("info" ,("spider COND skip" )); |
7624 | str->length(restart_pos); |
7625 | start_where = (restart_pos == start_where_pos); |
7626 | } else |
7627 | DBUG_RETURN(error_num); |
7628 | } |
7629 | tmp_cond = tmp_cond->next; |
7630 | } |
7631 | DBUG_RETURN(0); |
7632 | } |
7633 | |
7634 | int spider_oracle_handler::append_match_against_part( |
7635 | ulong sql_type, |
7636 | st_spider_ft_info *ft_info, |
7637 | const char *alias, |
7638 | uint alias_length |
7639 | ) { |
7640 | int error_num; |
7641 | spider_string *str; |
7642 | DBUG_ENTER("spider_oracle_handler::append_match_against_part" ); |
7643 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7644 | switch (sql_type) |
7645 | { |
7646 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7647 | str = &sql; |
7648 | break; |
7649 | default: |
7650 | DBUG_RETURN(0); |
7651 | } |
7652 | error_num = append_match_against(str, ft_info, alias, alias_length); |
7653 | DBUG_RETURN(error_num); |
7654 | } |
7655 | |
7656 | int spider_oracle_handler::append_match_against( |
7657 | spider_string *str, |
7658 | st_spider_ft_info *ft_info, |
7659 | const char *alias, |
7660 | uint alias_length |
7661 | ) { |
7662 | SPIDER_SHARE *share = spider->share; |
7663 | TABLE *table = spider->get_table(); |
7664 | String *ft_init_key; |
7665 | KEY *key_info; |
7666 | uint key_name_length; |
7667 | int key_count; |
7668 | KEY_PART_INFO *key_part; |
7669 | Field *field; |
7670 | DBUG_ENTER("spider_oracle_handler::append_match_against" ); |
7671 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7672 | if (str->reserve(SPIDER_SQL_MATCH_LEN)) |
7673 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7674 | str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); |
7675 | |
7676 | ft_init_key = ft_info->key; |
7677 | key_info = &table->key_info[ft_info->inx]; |
7678 | DBUG_PRINT("info" , ("spider spider_user_defined_key_parts=%u" , |
7679 | spider_user_defined_key_parts(key_info))); |
7680 | |
7681 | for ( |
7682 | key_part = key_info->key_part, |
7683 | key_count = 0; |
7684 | key_count < (int) spider_user_defined_key_parts(key_info); |
7685 | key_part++, |
7686 | key_count++ |
7687 | ) { |
7688 | field = key_part->field; |
7689 | key_name_length = |
7690 | oracle_share->column_name_str[field->field_index].length(); |
7691 | if (alias_length) |
7692 | { |
7693 | if (str->reserve(alias_length + key_name_length + |
7694 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
7695 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7696 | str->q_append(alias, alias_length); |
7697 | } else { |
7698 | if (str->reserve(key_name_length + |
7699 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
7700 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7701 | } |
7702 | oracle_share->append_column_name(str, field->field_index); |
7703 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
7704 | } |
7705 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
7706 | if (str->reserve(SPIDER_SQL_AGAINST_LEN + SPIDER_SQL_VALUE_QUOTE_LEN)) |
7707 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7708 | str->q_append(SPIDER_SQL_AGAINST_STR, SPIDER_SQL_AGAINST_LEN); |
7709 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
7710 | |
7711 | char buf[MAX_FIELD_WIDTH]; |
7712 | spider_string tmp_str(buf, MAX_FIELD_WIDTH, share->access_charset); |
7713 | tmp_str.init_calc_mem(211); |
7714 | tmp_str.length(0); |
7715 | if ( |
7716 | tmp_str.append(ft_init_key->ptr(), ft_init_key->length(), |
7717 | ft_init_key->charset()) || |
7718 | str->reserve(tmp_str.length() * 2) || |
7719 | spider_db_oracle_utility.append_escaped_util(str, tmp_str.get_str()) |
7720 | ) |
7721 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7722 | |
7723 | if (str->reserve( |
7724 | SPIDER_SQL_VALUE_QUOTE_LEN + SPIDER_SQL_CLOSE_PAREN_LEN + |
7725 | ((ft_info->flags & FT_BOOL) ? SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + |
7726 | ((ft_info->flags & FT_EXPAND) ? |
7727 | SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) |
7728 | )) |
7729 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7730 | str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
7731 | if (ft_info->flags & FT_BOOL) |
7732 | str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, |
7733 | SPIDER_SQL_IN_BOOLEAN_MODE_LEN); |
7734 | if (ft_info->flags & FT_EXPAND) |
7735 | str->q_append(SPIDER_SQL_WITH_QUERY_EXPANSION_STR, |
7736 | SPIDER_SQL_WITH_QUERY_EXPANSION_LEN); |
7737 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
7738 | DBUG_RETURN(0); |
7739 | } |
7740 | |
7741 | int spider_oracle_handler::append_match_select_part( |
7742 | ulong sql_type, |
7743 | const char *alias, |
7744 | uint alias_length |
7745 | ) { |
7746 | int error_num; |
7747 | spider_string *str; |
7748 | DBUG_ENTER("spider_oracle_handler::append_match_select_part" ); |
7749 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7750 | switch (sql_type) |
7751 | { |
7752 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7753 | str = &sql; |
7754 | break; |
7755 | default: |
7756 | DBUG_RETURN(0); |
7757 | } |
7758 | error_num = append_match_select(str, alias, alias_length); |
7759 | DBUG_RETURN(error_num); |
7760 | } |
7761 | |
7762 | int spider_oracle_handler::append_match_select( |
7763 | spider_string *str, |
7764 | const char *alias, |
7765 | uint alias_length |
7766 | ) { |
7767 | int error_num; |
7768 | DBUG_ENTER("spider_oracle_handler::append_match_select" ); |
7769 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7770 | if (spider->ft_current) |
7771 | { |
7772 | st_spider_ft_info *ft_info = spider->ft_first; |
7773 | while (TRUE) |
7774 | { |
7775 | if ((error_num = append_match_against(str, ft_info, |
7776 | alias, alias_length))) |
7777 | DBUG_RETURN(error_num); |
7778 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
7779 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7780 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
7781 | if (ft_info == spider->ft_current) |
7782 | break; |
7783 | ft_info = ft_info->next; |
7784 | } |
7785 | } |
7786 | DBUG_RETURN(0); |
7787 | } |
7788 | |
7789 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
7790 | int spider_oracle_handler::append_sum_select_part( |
7791 | ulong sql_type, |
7792 | const char *alias, |
7793 | uint alias_length |
7794 | ) { |
7795 | int error_num; |
7796 | spider_string *str; |
7797 | DBUG_ENTER("spider_oracle_handler::append_sum_select_part" ); |
7798 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7799 | switch (sql_type) |
7800 | { |
7801 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7802 | str = &sql; |
7803 | break; |
7804 | default: |
7805 | DBUG_RETURN(0); |
7806 | } |
7807 | error_num = append_sum_select(str, alias, alias_length); |
7808 | DBUG_RETURN(error_num); |
7809 | } |
7810 | |
7811 | int spider_oracle_handler::append_sum_select( |
7812 | spider_string *str, |
7813 | const char *alias, |
7814 | uint alias_length |
7815 | ) { |
7816 | int error_num; |
7817 | st_select_lex *select_lex; |
7818 | DBUG_ENTER("spider_oracle_handler::append_sum_select" ); |
7819 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7820 | select_lex = spider_get_select_lex(spider); |
7821 | JOIN *join = select_lex->join; |
7822 | Item_sum **item_sum_ptr; |
7823 | for (item_sum_ptr = join->sum_funcs; *item_sum_ptr; ++item_sum_ptr) |
7824 | { |
7825 | if ((error_num = spider_db_oracle_utility.open_item_sum_func(*item_sum_ptr, |
7826 | spider, str, alias, alias_length, FALSE, NULL))) |
7827 | { |
7828 | DBUG_RETURN(error_num); |
7829 | } |
7830 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
7831 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7832 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
7833 | } |
7834 | DBUG_RETURN(0); |
7835 | } |
7836 | #endif |
7837 | |
7838 | void spider_oracle_handler::set_order_pos( |
7839 | ulong sql_type |
7840 | ) { |
7841 | DBUG_ENTER("spider_oracle_handler::set_order_pos" ); |
7842 | switch (sql_type) |
7843 | { |
7844 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7845 | case SPIDER_SQL_TYPE_TMP_SQL: |
7846 | order_pos = sql.length(); |
7847 | break; |
7848 | case SPIDER_SQL_TYPE_INSERT_SQL: |
7849 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
7850 | case SPIDER_SQL_TYPE_DELETE_SQL: |
7851 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
7852 | order_pos = update_sql.length(); |
7853 | break; |
7854 | case SPIDER_SQL_TYPE_HANDLER: |
7855 | ha_next_pos = ha_sql.length(); |
7856 | break; |
7857 | default: |
7858 | DBUG_ASSERT(0); |
7859 | break; |
7860 | } |
7861 | DBUG_VOID_RETURN; |
7862 | } |
7863 | |
7864 | void spider_oracle_handler::set_order_to_pos( |
7865 | ulong sql_type |
7866 | ) { |
7867 | DBUG_ENTER("spider_oracle_handler::set_order_to_pos" ); |
7868 | switch (sql_type) |
7869 | { |
7870 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7871 | case SPIDER_SQL_TYPE_TMP_SQL: |
7872 | sql.length(order_pos); |
7873 | break; |
7874 | case SPIDER_SQL_TYPE_INSERT_SQL: |
7875 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
7876 | case SPIDER_SQL_TYPE_DELETE_SQL: |
7877 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
7878 | update_sql.length(order_pos); |
7879 | break; |
7880 | case SPIDER_SQL_TYPE_HANDLER: |
7881 | ha_sql.length(ha_next_pos); |
7882 | break; |
7883 | default: |
7884 | DBUG_ASSERT(0); |
7885 | break; |
7886 | } |
7887 | DBUG_VOID_RETURN; |
7888 | } |
7889 | |
7890 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
7891 | int spider_oracle_handler::append_group_by_part( |
7892 | const char *alias, |
7893 | uint alias_length, |
7894 | ulong sql_type |
7895 | ) { |
7896 | int error_num; |
7897 | spider_string *str; |
7898 | DBUG_ENTER("spider_oracle_handler::append_group_by_part" ); |
7899 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7900 | switch (sql_type) |
7901 | { |
7902 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7903 | case SPIDER_SQL_TYPE_TMP_SQL: |
7904 | str = &sql; |
7905 | break; |
7906 | case SPIDER_SQL_TYPE_INSERT_SQL: |
7907 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
7908 | case SPIDER_SQL_TYPE_DELETE_SQL: |
7909 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
7910 | str = &update_sql; |
7911 | break; |
7912 | case SPIDER_SQL_TYPE_HANDLER: |
7913 | str = &ha_sql; |
7914 | break; |
7915 | default: |
7916 | DBUG_RETURN(0); |
7917 | } |
7918 | error_num = append_group_by(str, alias, alias_length); |
7919 | DBUG_RETURN(error_num); |
7920 | } |
7921 | |
7922 | int spider_oracle_handler::append_group_by( |
7923 | spider_string *str, |
7924 | const char *alias, |
7925 | uint alias_length |
7926 | ) { |
7927 | int error_num; |
7928 | st_select_lex *select_lex; |
7929 | DBUG_ENTER("spider_oracle_handler::append_group_by" ); |
7930 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7931 | select_lex = spider_get_select_lex(spider); |
7932 | ORDER *group = (ORDER *) select_lex->group_list.first; |
7933 | if (group) |
7934 | { |
7935 | if (str->reserve(SPIDER_SQL_GROUP_LEN)) |
7936 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7937 | str->q_append(SPIDER_SQL_GROUP_STR, SPIDER_SQL_GROUP_LEN); |
7938 | for (; group; group = group->next) |
7939 | { |
7940 | if ((error_num = spider_db_print_item_type((*group->item), spider, str, |
7941 | alias, alias_length, spider_dbton_oracle.dbton_id, FALSE, NULL))) |
7942 | { |
7943 | DBUG_RETURN(error_num); |
7944 | } |
7945 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
7946 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
7947 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
7948 | } |
7949 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
7950 | } |
7951 | DBUG_RETURN(0); |
7952 | } |
7953 | #endif |
7954 | |
7955 | int spider_oracle_handler::append_key_order_for_merge_with_alias_part( |
7956 | const char *alias, |
7957 | uint alias_length, |
7958 | ulong sql_type |
7959 | ) { |
7960 | int error_num; |
7961 | spider_string *str; |
7962 | DBUG_ENTER("spider_oracle_handler::append_key_order_for_merge_with_alias_part" ); |
7963 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7964 | switch (sql_type) |
7965 | { |
7966 | case SPIDER_SQL_TYPE_SELECT_SQL: |
7967 | case SPIDER_SQL_TYPE_TMP_SQL: |
7968 | str = &sql; |
7969 | break; |
7970 | case SPIDER_SQL_TYPE_INSERT_SQL: |
7971 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
7972 | case SPIDER_SQL_TYPE_DELETE_SQL: |
7973 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
7974 | str = &update_sql; |
7975 | break; |
7976 | case SPIDER_SQL_TYPE_HANDLER: |
7977 | str = &ha_sql; |
7978 | ha_limit_pos = ha_sql.length(); |
7979 | break; |
7980 | default: |
7981 | DBUG_RETURN(0); |
7982 | } |
7983 | error_num = append_key_order_for_merge_with_alias(str, alias, alias_length); |
7984 | DBUG_RETURN(error_num); |
7985 | } |
7986 | |
7987 | int spider_oracle_handler::append_key_order_for_merge_with_alias( |
7988 | spider_string *str, |
7989 | const char *alias, |
7990 | uint alias_length |
7991 | ) { |
7992 | /* sort for index merge */ |
7993 | TABLE *table = spider->get_table(); |
7994 | int length; |
7995 | Field *field; |
7996 | uint key_name_length; |
7997 | DBUG_ENTER("spider_oracle_handler::append_key_order_for_merge_with_alias" ); |
7998 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
7999 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
8000 | if (spider->result_list.direct_aggregate) |
8001 | { |
8002 | int error_num; |
8003 | if ((error_num = append_group_by(str, alias, alias_length))) |
8004 | DBUG_RETURN(error_num); |
8005 | } |
8006 | #endif |
8007 | if ( |
8008 | spider->result_list.direct_order_limit || |
8009 | spider->result_list.internal_limit < 9223372036854775807LL || |
8010 | spider->result_list.split_read < 9223372036854775807LL || |
8011 | spider->result_list.internal_offset |
8012 | ) { |
8013 | if (update_rownum_appended || select_rownum_appended) |
8014 | { |
8015 | if (str->reserve(SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN)) |
8016 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8017 | str->q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8018 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8019 | order_pos = str->length(); |
8020 | limit_pos = str->length(); |
8021 | DBUG_RETURN(0); |
8022 | } |
8023 | sql_part.length(0); |
8024 | if (str == &update_sql) |
8025 | { |
8026 | if (sql_part.reserve(str->length() + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN)) |
8027 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8028 | sql_part.q_append(str->ptr(), where_pos); |
8029 | sql_part.q_append(SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR, |
8030 | SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN); |
8031 | } else { |
8032 | if (sql_part.reserve(str->length() + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN + |
8033 | SPIDER_SQL_ROW_NUMBER_HEAD_LEN)) |
8034 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8035 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR, |
8036 | SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN); |
8037 | sql_part.q_append(str->ptr(), table_name_pos - SPIDER_SQL_FROM_LEN); |
8038 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_HEAD_STR, |
8039 | SPIDER_SQL_ROW_NUMBER_HEAD_LEN); |
8040 | } |
8041 | if (table->s->primary_key < MAX_KEY) |
8042 | { |
8043 | /* sort by primary key */ |
8044 | KEY *key_info = &table->key_info[table->s->primary_key]; |
8045 | KEY_PART_INFO *key_part; |
8046 | for ( |
8047 | key_part = key_info->key_part, |
8048 | length = 1; |
8049 | length <= (int) spider_user_defined_key_parts(key_info); |
8050 | key_part++, |
8051 | length++ |
8052 | ) { |
8053 | field = key_part->field; |
8054 | key_name_length = |
8055 | oracle_share->column_name_str[field->field_index].length(); |
8056 | if (sql_part.reserve(alias_length + key_name_length + |
8057 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
8058 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8059 | sql_part.q_append(alias, alias_length); |
8060 | oracle_share->append_column_name(&sql_part, field->field_index); |
8061 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8062 | } |
8063 | } else { |
8064 | /* sort by all columns */ |
8065 | Field **fieldp; |
8066 | for ( |
8067 | fieldp = table->field, length = 1; |
8068 | *fieldp; |
8069 | fieldp++, length++ |
8070 | ) { |
8071 | key_name_length = |
8072 | oracle_share->column_name_str[(*fieldp)->field_index].length(); |
8073 | if (sql_part.reserve(alias_length + key_name_length + |
8074 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
8075 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8076 | sql_part.q_append(alias, alias_length); |
8077 | oracle_share->append_column_name(&sql_part, (*fieldp)->field_index); |
8078 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8079 | } |
8080 | } |
8081 | uint pos_diff; |
8082 | if (str == &update_sql) |
8083 | { |
8084 | uint table_name_size = (update_set_pos ? update_set_pos : where_pos) - |
8085 | table_name_pos; |
8086 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + |
8087 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + |
8088 | SPIDER_SQL_FROM_LEN + table_name_size)) |
8089 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8090 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, |
8091 | SPIDER_SQL_ROW_NUMBER_TAIL_LEN); |
8092 | sql_part.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
8093 | sql_part.q_append(str->ptr() + table_name_pos, table_name_size); |
8094 | pos_diff = sql_part.length() - where_pos; |
8095 | sql_part.q_append(str->ptr() + where_pos, str->length() - where_pos); |
8096 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8097 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8098 | update_rownum_appended = TRUE; |
8099 | } else { |
8100 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + |
8101 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + |
8102 | SPIDER_SQL_FROM_LEN)) |
8103 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8104 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, |
8105 | SPIDER_SQL_ROW_NUMBER_TAIL_LEN); |
8106 | pos_diff = sql_part.length() + SPIDER_SQL_FROM_LEN - table_name_pos; |
8107 | sql_part.q_append(str->ptr() + table_name_pos - SPIDER_SQL_FROM_LEN, |
8108 | str->length() - table_name_pos + SPIDER_SQL_FROM_LEN); |
8109 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8110 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8111 | select_rownum_appended = TRUE; |
8112 | table_name_pos = table_name_pos + pos_diff; |
8113 | } |
8114 | if (str->copy(sql_part)) |
8115 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8116 | where_pos = where_pos + pos_diff; |
8117 | order_pos = str->length(); |
8118 | limit_pos = str->length(); |
8119 | DBUG_RETURN(0); |
8120 | } |
8121 | if (table->s->primary_key < MAX_KEY) |
8122 | { |
8123 | /* sort by primary key */ |
8124 | KEY *key_info = &table->key_info[table->s->primary_key]; |
8125 | KEY_PART_INFO *key_part; |
8126 | for ( |
8127 | key_part = key_info->key_part, |
8128 | length = 1; |
8129 | length <= (int) spider_user_defined_key_parts(key_info); |
8130 | key_part++, |
8131 | length++ |
8132 | ) { |
8133 | field = key_part->field; |
8134 | key_name_length = |
8135 | oracle_share->column_name_str[field->field_index].length(); |
8136 | if (length == 1) |
8137 | { |
8138 | if (str->reserve(SPIDER_SQL_ORDER_LEN)) |
8139 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8140 | str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
8141 | } |
8142 | if (str->reserve(alias_length + key_name_length + |
8143 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
8144 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8145 | str->q_append(alias, alias_length); |
8146 | oracle_share->append_column_name(str, field->field_index); |
8147 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8148 | } |
8149 | if (length > 1) |
8150 | { |
8151 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
8152 | } |
8153 | } else { |
8154 | /* sort by all columns */ |
8155 | Field **fieldp; |
8156 | for ( |
8157 | fieldp = table->field, length = 1; |
8158 | *fieldp; |
8159 | fieldp++, length++ |
8160 | ) { |
8161 | key_name_length = |
8162 | oracle_share->column_name_str[(*fieldp)->field_index].length(); |
8163 | if (length == 1) |
8164 | { |
8165 | if (str->reserve(SPIDER_SQL_ORDER_LEN)) |
8166 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8167 | str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
8168 | } |
8169 | if (str->reserve(alias_length + key_name_length + |
8170 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
8171 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8172 | str->q_append(alias, alias_length); |
8173 | oracle_share->append_column_name(str, (*fieldp)->field_index); |
8174 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8175 | } |
8176 | if (length > 1) |
8177 | { |
8178 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
8179 | } |
8180 | } |
8181 | limit_pos = str->length(); |
8182 | DBUG_RETURN(0); |
8183 | } |
8184 | |
8185 | int spider_oracle_handler::append_key_order_for_direct_order_limit_with_alias_part( |
8186 | const char *alias, |
8187 | uint alias_length, |
8188 | ulong sql_type |
8189 | ) { |
8190 | int error_num; |
8191 | spider_string *str; |
8192 | DBUG_ENTER("spider_oracle_handler::append_key_order_for_direct_order_limit_with_alias_part" ); |
8193 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8194 | switch (sql_type) |
8195 | { |
8196 | case SPIDER_SQL_TYPE_SELECT_SQL: |
8197 | case SPIDER_SQL_TYPE_TMP_SQL: |
8198 | str = &sql; |
8199 | break; |
8200 | case SPIDER_SQL_TYPE_INSERT_SQL: |
8201 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
8202 | case SPIDER_SQL_TYPE_DELETE_SQL: |
8203 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
8204 | str = &update_sql; |
8205 | break; |
8206 | case SPIDER_SQL_TYPE_HANDLER: |
8207 | str = &ha_sql; |
8208 | break; |
8209 | default: |
8210 | DBUG_RETURN(0); |
8211 | } |
8212 | error_num = append_key_order_for_direct_order_limit_with_alias( |
8213 | str, alias, alias_length); |
8214 | DBUG_RETURN(error_num); |
8215 | } |
8216 | |
8217 | int spider_oracle_handler::append_key_order_for_direct_order_limit_with_alias( |
8218 | spider_string *str, |
8219 | const char *alias, |
8220 | uint alias_length |
8221 | ) { |
8222 | int error_num; |
8223 | ORDER *order; |
8224 | st_select_lex *select_lex; |
8225 | longlong select_limit; |
8226 | longlong offset_limit; |
8227 | DBUG_ENTER("spider_oracle_handler::append_key_order_for_direct_order_limit_with_alias" ); |
8228 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8229 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
8230 | if (spider->result_list.direct_aggregate) |
8231 | { |
8232 | if ((error_num = append_group_by(str, alias, alias_length))) |
8233 | DBUG_RETURN(error_num); |
8234 | } |
8235 | #endif |
8236 | spider_get_select_limit(spider, &select_lex, &select_limit, |
8237 | &offset_limit); |
8238 | if ( |
8239 | spider->result_list.direct_order_limit || |
8240 | spider->result_list.internal_limit < 9223372036854775807LL || |
8241 | spider->result_list.split_read < 9223372036854775807LL || |
8242 | spider->result_list.internal_offset |
8243 | ) { |
8244 | if (update_rownum_appended || select_rownum_appended) |
8245 | { |
8246 | if (str->reserve(SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN)) |
8247 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8248 | str->q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8249 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8250 | order_pos = str->length(); |
8251 | limit_pos = str->length(); |
8252 | DBUG_RETURN(0); |
8253 | } |
8254 | sql_part.length(0); |
8255 | if (str == &update_sql) |
8256 | { |
8257 | if (sql_part.reserve(str->length() + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN)) |
8258 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8259 | sql_part.q_append(str->ptr(), where_pos); |
8260 | sql_part.q_append(SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR, |
8261 | SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN); |
8262 | } else { |
8263 | if (sql_part.reserve(str->length() + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN + |
8264 | SPIDER_SQL_ROW_NUMBER_HEAD_LEN)) |
8265 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8266 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR, |
8267 | SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN); |
8268 | sql_part.q_append(str->ptr(), table_name_pos - SPIDER_SQL_FROM_LEN); |
8269 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_HEAD_STR, |
8270 | SPIDER_SQL_ROW_NUMBER_HEAD_LEN); |
8271 | } |
8272 | bool all_desc = TRUE; |
8273 | if (select_lex->order_list.first) |
8274 | { |
8275 | for (order = (ORDER *) select_lex->order_list.first; order; |
8276 | order = order->next) |
8277 | { |
8278 | if ((error_num = |
8279 | spider_db_print_item_type((*order->item), spider, &sql_part, alias, |
8280 | alias_length, spider_dbton_oracle.dbton_id, FALSE, NULL))) |
8281 | { |
8282 | DBUG_PRINT("info" ,("spider error=%d" , error_num)); |
8283 | DBUG_RETURN(error_num); |
8284 | } |
8285 | if (SPIDER_order_direction_is_asc(order)) |
8286 | { |
8287 | if (sql_part.reserve(SPIDER_SQL_COMMA_LEN)) |
8288 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8289 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8290 | all_desc = FALSE; |
8291 | } else { |
8292 | if (sql_part.reserve(SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) |
8293 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8294 | sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
8295 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8296 | } |
8297 | } |
8298 | } else { |
8299 | all_desc = FALSE; |
8300 | } |
8301 | uint pos_diff; |
8302 | if (str == &update_sql) |
8303 | { |
8304 | uint table_name_size = (update_set_pos ? update_set_pos : where_pos) - |
8305 | table_name_pos; |
8306 | if (all_desc) |
8307 | { |
8308 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + |
8309 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + |
8310 | SPIDER_SQL_FROM_LEN + table_name_size)) |
8311 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8312 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, |
8313 | SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); |
8314 | } else { |
8315 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + |
8316 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + |
8317 | SPIDER_SQL_FROM_LEN + table_name_size)) |
8318 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8319 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, |
8320 | SPIDER_SQL_ROW_NUMBER_TAIL_LEN); |
8321 | } |
8322 | sql_part.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
8323 | sql_part.q_append(str->ptr() + table_name_pos, table_name_size); |
8324 | pos_diff = sql_part.length() - where_pos; |
8325 | sql_part.q_append(str->ptr() + where_pos, str->length() - where_pos); |
8326 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8327 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8328 | update_rownum_appended = TRUE; |
8329 | } else { |
8330 | if (all_desc) |
8331 | { |
8332 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + |
8333 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + |
8334 | SPIDER_SQL_FROM_LEN)) |
8335 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8336 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, |
8337 | SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); |
8338 | } else { |
8339 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + |
8340 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + |
8341 | SPIDER_SQL_FROM_LEN)) |
8342 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8343 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, |
8344 | SPIDER_SQL_ROW_NUMBER_TAIL_LEN); |
8345 | } |
8346 | pos_diff = sql_part.length() + SPIDER_SQL_FROM_LEN - table_name_pos; |
8347 | sql_part.q_append(str->ptr() + table_name_pos - SPIDER_SQL_FROM_LEN, |
8348 | str->length() - table_name_pos + SPIDER_SQL_FROM_LEN); |
8349 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8350 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8351 | select_rownum_appended = TRUE; |
8352 | table_name_pos = table_name_pos + pos_diff; |
8353 | } |
8354 | if (str->copy(sql_part)) |
8355 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8356 | where_pos = where_pos + pos_diff; |
8357 | order_pos = str->length(); |
8358 | limit_pos = str->length(); |
8359 | DBUG_RETURN(0); |
8360 | } |
8361 | if (select_lex->order_list.first) |
8362 | { |
8363 | if (str->reserve(SPIDER_SQL_ORDER_LEN)) |
8364 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8365 | str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
8366 | for (order = (ORDER *) select_lex->order_list.first; order; |
8367 | order = order->next) |
8368 | { |
8369 | if ((error_num = |
8370 | spider_db_print_item_type((*order->item), spider, str, alias, |
8371 | alias_length, spider_dbton_oracle.dbton_id, FALSE, NULL))) |
8372 | { |
8373 | DBUG_PRINT("info" ,("spider error=%d" , error_num)); |
8374 | DBUG_RETURN(error_num); |
8375 | } |
8376 | if (SPIDER_order_direction_is_asc(order)) |
8377 | { |
8378 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
8379 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8380 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8381 | } else { |
8382 | if (str->reserve(SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) |
8383 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8384 | str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
8385 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8386 | } |
8387 | } |
8388 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
8389 | } |
8390 | limit_pos = str->length(); |
8391 | DBUG_RETURN(0); |
8392 | } |
8393 | |
8394 | int spider_oracle_handler::append_key_order_with_alias_part( |
8395 | const char *alias, |
8396 | uint alias_length, |
8397 | ulong sql_type |
8398 | ) { |
8399 | int error_num; |
8400 | spider_string *str; |
8401 | DBUG_ENTER("spider_oracle_handler::append_key_order_with_alias_part" ); |
8402 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8403 | switch (sql_type) |
8404 | { |
8405 | case SPIDER_SQL_TYPE_SELECT_SQL: |
8406 | case SPIDER_SQL_TYPE_TMP_SQL: |
8407 | str = &sql; |
8408 | break; |
8409 | case SPIDER_SQL_TYPE_INSERT_SQL: |
8410 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
8411 | case SPIDER_SQL_TYPE_DELETE_SQL: |
8412 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
8413 | str = &update_sql; |
8414 | break; |
8415 | case SPIDER_SQL_TYPE_HANDLER: |
8416 | str = &ha_sql; |
8417 | error_num = append_key_order_for_handler(str, alias, alias_length); |
8418 | DBUG_RETURN(error_num); |
8419 | default: |
8420 | DBUG_RETURN(0); |
8421 | } |
8422 | error_num = append_key_order_with_alias(str, alias, alias_length); |
8423 | DBUG_RETURN(error_num); |
8424 | } |
8425 | |
8426 | int spider_oracle_handler::append_key_order_for_handler( |
8427 | spider_string *str, |
8428 | const char *alias, |
8429 | uint alias_length |
8430 | ) { |
8431 | DBUG_ENTER("spider_oracle_handler::append_key_order_for_handler" ); |
8432 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8433 | DBUG_PRINT("info" ,("spider ha_next_pos=%d" , ha_next_pos)); |
8434 | DBUG_PRINT("info" ,("spider ha_where_pos=%d" , ha_where_pos)); |
8435 | str->q_append(alias, alias_length); |
8436 | memset((char *) str->ptr() + str->length(), ' ', |
8437 | ha_where_pos - ha_next_pos - alias_length); |
8438 | DBUG_RETURN(0); |
8439 | } |
8440 | |
8441 | int spider_oracle_handler::append_key_order_with_alias( |
8442 | spider_string *str, |
8443 | const char *alias, |
8444 | uint alias_length |
8445 | ) { |
8446 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
8447 | KEY *key_info = result_list->key_info; |
8448 | int length; |
8449 | KEY_PART_INFO *key_part; |
8450 | Field *field; |
8451 | uint key_name_length; |
8452 | DBUG_ENTER("spider_oracle_handler::append_key_order_with_alias" ); |
8453 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8454 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
8455 | if (spider->result_list.direct_aggregate) |
8456 | { |
8457 | int error_num; |
8458 | if ((error_num = append_group_by(str, alias, alias_length))) |
8459 | DBUG_RETURN(error_num); |
8460 | } |
8461 | #endif |
8462 | if ( |
8463 | spider->result_list.direct_order_limit || |
8464 | spider->result_list.internal_limit < 9223372036854775807LL || |
8465 | spider->result_list.split_read < 9223372036854775807LL || |
8466 | spider->result_list.internal_offset |
8467 | ) { |
8468 | if (update_rownum_appended || select_rownum_appended) |
8469 | { |
8470 | if (str->reserve(SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN)) |
8471 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8472 | str->q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8473 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8474 | order_pos = str->length(); |
8475 | limit_pos = str->length(); |
8476 | DBUG_RETURN(0); |
8477 | } |
8478 | sql_part.length(0); |
8479 | if (str == &update_sql) |
8480 | { |
8481 | if (sql_part.reserve(str->length() + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN)) |
8482 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8483 | sql_part.q_append(str->ptr(), where_pos); |
8484 | sql_part.q_append(SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR, |
8485 | SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN); |
8486 | } else { |
8487 | if (sql_part.reserve(str->length() + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN + |
8488 | SPIDER_SQL_ROW_NUMBER_HEAD_LEN)) |
8489 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8490 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR, |
8491 | SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN); |
8492 | sql_part.q_append(str->ptr(), table_name_pos - SPIDER_SQL_FROM_LEN); |
8493 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_HEAD_STR, |
8494 | SPIDER_SQL_ROW_NUMBER_HEAD_LEN); |
8495 | } |
8496 | if (result_list->sorted == TRUE) |
8497 | { |
8498 | if (result_list->desc_flg == TRUE) |
8499 | { |
8500 | for ( |
8501 | key_part = key_info->key_part + result_list->key_order, |
8502 | length = 1; |
8503 | length + result_list->key_order <= |
8504 | (int) spider_user_defined_key_parts(key_info) && |
8505 | length <= result_list->max_order; |
8506 | key_part++, |
8507 | length++ |
8508 | ) { |
8509 | field = key_part->field; |
8510 | key_name_length = |
8511 | oracle_share->column_name_str[field->field_index].length(); |
8512 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
8513 | { |
8514 | if (sql_part.reserve(alias_length + key_name_length + |
8515 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
8516 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8517 | sql_part.q_append(alias, alias_length); |
8518 | oracle_share->append_column_name(&sql_part, field->field_index); |
8519 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8520 | } else { |
8521 | if (sql_part.reserve(alias_length + key_name_length + |
8522 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
8523 | SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) |
8524 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8525 | sql_part.q_append(alias, alias_length); |
8526 | oracle_share->append_column_name(&sql_part, field->field_index); |
8527 | sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
8528 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8529 | } |
8530 | } |
8531 | } else { |
8532 | for ( |
8533 | key_part = key_info->key_part + result_list->key_order, |
8534 | length = 1; |
8535 | length + result_list->key_order <= |
8536 | (int) spider_user_defined_key_parts(key_info) && |
8537 | length <= result_list->max_order; |
8538 | key_part++, |
8539 | length++ |
8540 | ) { |
8541 | field = key_part->field; |
8542 | key_name_length = |
8543 | oracle_share->column_name_str[field->field_index].length(); |
8544 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
8545 | { |
8546 | if (sql_part.reserve(alias_length + key_name_length + |
8547 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
8548 | SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) |
8549 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8550 | sql_part.q_append(alias, alias_length); |
8551 | oracle_share->append_column_name(&sql_part, field->field_index); |
8552 | sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
8553 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8554 | } else { |
8555 | if (sql_part.reserve(alias_length + key_name_length + |
8556 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
8557 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8558 | sql_part.q_append(alias, alias_length); |
8559 | oracle_share->append_column_name(&sql_part, field->field_index); |
8560 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8561 | } |
8562 | } |
8563 | } |
8564 | } |
8565 | uint pos_diff; |
8566 | if (str == &update_sql) |
8567 | { |
8568 | uint table_name_size = (update_set_pos ? update_set_pos : where_pos) - |
8569 | table_name_pos; |
8570 | if (result_list->sorted == TRUE && result_list->desc_flg == TRUE) |
8571 | { |
8572 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + |
8573 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + |
8574 | SPIDER_SQL_FROM_LEN + table_name_size)) |
8575 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8576 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, |
8577 | SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); |
8578 | } else { |
8579 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + |
8580 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + |
8581 | SPIDER_SQL_FROM_LEN + table_name_size)) |
8582 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8583 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, |
8584 | SPIDER_SQL_ROW_NUMBER_TAIL_LEN); |
8585 | } |
8586 | sql_part.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
8587 | sql_part.q_append(str->ptr() + table_name_pos, |
8588 | table_name_size); |
8589 | pos_diff = sql_part.length() - where_pos; |
8590 | sql_part.q_append(str->ptr() + where_pos, str->length() - where_pos); |
8591 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8592 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8593 | update_rownum_appended = TRUE; |
8594 | } else { |
8595 | if (result_list->sorted == TRUE && result_list->desc_flg == TRUE) |
8596 | { |
8597 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + |
8598 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + |
8599 | SPIDER_SQL_FROM_LEN)) |
8600 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8601 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, |
8602 | SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); |
8603 | } else { |
8604 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + |
8605 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + |
8606 | SPIDER_SQL_FROM_LEN)) |
8607 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8608 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, |
8609 | SPIDER_SQL_ROW_NUMBER_TAIL_LEN); |
8610 | } |
8611 | pos_diff = sql_part.length() + SPIDER_SQL_FROM_LEN - table_name_pos; |
8612 | sql_part.q_append(str->ptr() + table_name_pos - SPIDER_SQL_FROM_LEN, |
8613 | str->length() - table_name_pos + SPIDER_SQL_FROM_LEN); |
8614 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
8615 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
8616 | select_rownum_appended = TRUE; |
8617 | table_name_pos = table_name_pos + pos_diff; |
8618 | } |
8619 | if (str->copy(sql_part)) |
8620 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8621 | where_pos = where_pos + pos_diff; |
8622 | order_pos = str->length(); |
8623 | limit_pos = str->length(); |
8624 | DBUG_RETURN(0); |
8625 | } |
8626 | if (result_list->sorted == TRUE) |
8627 | { |
8628 | if (result_list->desc_flg == TRUE) |
8629 | { |
8630 | for ( |
8631 | key_part = key_info->key_part + result_list->key_order, |
8632 | length = 1; |
8633 | length + result_list->key_order < |
8634 | (int) spider_user_defined_key_parts(key_info) && |
8635 | length < result_list->max_order; |
8636 | key_part++, |
8637 | length++ |
8638 | ) { |
8639 | field = key_part->field; |
8640 | key_name_length = |
8641 | oracle_share->column_name_str[field->field_index].length(); |
8642 | if (length == 1) |
8643 | { |
8644 | if (str->reserve(SPIDER_SQL_ORDER_LEN)) |
8645 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8646 | str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
8647 | } |
8648 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
8649 | { |
8650 | if (str->reserve(alias_length + key_name_length + |
8651 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
8652 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8653 | str->q_append(alias, alias_length); |
8654 | oracle_share->append_column_name(str, field->field_index); |
8655 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8656 | } else { |
8657 | if (str->reserve(alias_length + key_name_length + |
8658 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
8659 | SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) |
8660 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8661 | str->q_append(alias, alias_length); |
8662 | oracle_share->append_column_name(str, field->field_index); |
8663 | str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
8664 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8665 | } |
8666 | } |
8667 | if ( |
8668 | length + result_list->key_order <= |
8669 | (int) spider_user_defined_key_parts(key_info) && |
8670 | length <= result_list->max_order |
8671 | ) { |
8672 | field = key_part->field; |
8673 | key_name_length = |
8674 | oracle_share->column_name_str[field->field_index].length(); |
8675 | if (length == 1) |
8676 | { |
8677 | if (str->reserve(SPIDER_SQL_ORDER_LEN)) |
8678 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8679 | str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
8680 | } |
8681 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
8682 | { |
8683 | if (str->reserve(alias_length + key_name_length + |
8684 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) |
8685 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8686 | str->q_append(alias, alias_length); |
8687 | oracle_share->append_column_name(str, field->field_index); |
8688 | } else { |
8689 | if (str->reserve(alias_length + key_name_length + |
8690 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_DESC_LEN)) |
8691 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8692 | str->q_append(alias, alias_length); |
8693 | oracle_share->append_column_name(str, field->field_index); |
8694 | str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
8695 | } |
8696 | } |
8697 | } else { |
8698 | for ( |
8699 | key_part = key_info->key_part + result_list->key_order, |
8700 | length = 1; |
8701 | length + result_list->key_order < |
8702 | (int) spider_user_defined_key_parts(key_info) && |
8703 | length < result_list->max_order; |
8704 | key_part++, |
8705 | length++ |
8706 | ) { |
8707 | field = key_part->field; |
8708 | key_name_length = |
8709 | oracle_share->column_name_str[field->field_index].length(); |
8710 | if (length == 1) |
8711 | { |
8712 | if (str->reserve(SPIDER_SQL_ORDER_LEN)) |
8713 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8714 | str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
8715 | } |
8716 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
8717 | { |
8718 | if (str->reserve(alias_length + key_name_length + |
8719 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
8720 | SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) |
8721 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8722 | str->q_append(alias, alias_length); |
8723 | oracle_share->append_column_name(str, field->field_index); |
8724 | str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
8725 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8726 | } else { |
8727 | if (str->reserve(alias_length + key_name_length + |
8728 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
8729 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8730 | str->q_append(alias, alias_length); |
8731 | oracle_share->append_column_name(str, field->field_index); |
8732 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
8733 | } |
8734 | } |
8735 | if ( |
8736 | length + result_list->key_order <= |
8737 | (int) spider_user_defined_key_parts(key_info) && |
8738 | length <= result_list->max_order |
8739 | ) { |
8740 | field = key_part->field; |
8741 | key_name_length = |
8742 | oracle_share->column_name_str[field->field_index].length(); |
8743 | if (length == 1) |
8744 | { |
8745 | if (str->reserve(SPIDER_SQL_ORDER_LEN)) |
8746 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8747 | str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
8748 | } |
8749 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
8750 | { |
8751 | if (str->reserve(alias_length + key_name_length + |
8752 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_DESC_LEN)) |
8753 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8754 | str->q_append(alias, alias_length); |
8755 | oracle_share->append_column_name(str, field->field_index); |
8756 | str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
8757 | } else { |
8758 | if (str->reserve(alias_length + key_name_length + |
8759 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) |
8760 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8761 | str->q_append(alias, alias_length); |
8762 | oracle_share->append_column_name(str, field->field_index); |
8763 | } |
8764 | } |
8765 | } |
8766 | } |
8767 | limit_pos = str->length(); |
8768 | DBUG_RETURN(0); |
8769 | } |
8770 | |
8771 | int spider_oracle_handler::append_limit_part( |
8772 | longlong offset, |
8773 | longlong limit, |
8774 | ulong sql_type |
8775 | ) { |
8776 | int error_num; |
8777 | spider_string *str; |
8778 | DBUG_ENTER("spider_oracle_handler::append_limit_part" ); |
8779 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8780 | switch (sql_type) |
8781 | { |
8782 | case SPIDER_SQL_TYPE_SELECT_SQL: |
8783 | str = &sql; |
8784 | limit_pos = str->length(); |
8785 | break; |
8786 | case SPIDER_SQL_TYPE_TMP_SQL: |
8787 | str = &tmp_sql; |
8788 | limit_pos = str->length(); |
8789 | break; |
8790 | case SPIDER_SQL_TYPE_INSERT_SQL: |
8791 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
8792 | case SPIDER_SQL_TYPE_DELETE_SQL: |
8793 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
8794 | str = &update_sql; |
8795 | limit_pos = str->length(); |
8796 | break; |
8797 | case SPIDER_SQL_TYPE_HANDLER: |
8798 | str = &ha_sql; |
8799 | ha_limit_pos = str->length(); |
8800 | break; |
8801 | default: |
8802 | DBUG_RETURN(0); |
8803 | } |
8804 | error_num = append_limit(str, offset, limit); |
8805 | DBUG_PRINT("info" ,("spider str=%s" , str->c_ptr_safe())); |
8806 | DBUG_PRINT("info" ,("spider length=%u" , str->length())); |
8807 | DBUG_RETURN(error_num); |
8808 | } |
8809 | |
8810 | int spider_oracle_handler::reappend_limit_part( |
8811 | longlong offset, |
8812 | longlong limit, |
8813 | ulong sql_type |
8814 | ) { |
8815 | int error_num; |
8816 | spider_string *str; |
8817 | DBUG_ENTER("spider_oracle_handler::reappend_limit_part" ); |
8818 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8819 | switch (sql_type) |
8820 | { |
8821 | case SPIDER_SQL_TYPE_SELECT_SQL: |
8822 | str = &sql; |
8823 | str->length(limit_pos); |
8824 | break; |
8825 | case SPIDER_SQL_TYPE_TMP_SQL: |
8826 | str = &tmp_sql; |
8827 | str->length(limit_pos); |
8828 | break; |
8829 | case SPIDER_SQL_TYPE_INSERT_SQL: |
8830 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
8831 | case SPIDER_SQL_TYPE_DELETE_SQL: |
8832 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
8833 | str = &update_sql; |
8834 | str->length(limit_pos); |
8835 | break; |
8836 | case SPIDER_SQL_TYPE_HANDLER: |
8837 | str = &ha_sql; |
8838 | str->length(ha_limit_pos); |
8839 | break; |
8840 | default: |
8841 | DBUG_RETURN(0); |
8842 | } |
8843 | error_num = append_limit(str, offset, limit); |
8844 | DBUG_RETURN(error_num); |
8845 | } |
8846 | |
8847 | int spider_oracle_handler::append_limit( |
8848 | spider_string *str, |
8849 | longlong offset, |
8850 | longlong limit |
8851 | ) { |
8852 | char buf[SPIDER_LONGLONG_LEN + 1]; |
8853 | uint32 length; |
8854 | DBUG_ENTER("spider_oracle_handler::append_limit" ); |
8855 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8856 | DBUG_PRINT("info" , ("spider offset=%lld" , offset)); |
8857 | DBUG_PRINT("info" , ("spider limit=%lld" , limit)); |
8858 | if (offset || limit < 9223372036854775807LL) |
8859 | { |
8860 | if ((int) str->length() == where_pos) |
8861 | { |
8862 | if (offset) |
8863 | { |
8864 | int error_num; |
8865 | if ((error_num = append_key_order_for_direct_order_limit_with_alias( |
8866 | str, NULL, 0))) |
8867 | DBUG_RETURN(error_num); |
8868 | } else { |
8869 | if (str->reserve(SPIDER_SQL_WHERE_LEN + SPIDER_SQL_ROWNUM_LEN)) |
8870 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8871 | str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); |
8872 | str->q_append(SPIDER_SQL_ROWNUM_STR, SPIDER_SQL_ROWNUM_LEN); |
8873 | } |
8874 | } |
8875 | if (offset) |
8876 | { |
8877 | if (str->reserve(SPIDER_SQL_BETWEEN_LEN + SPIDER_SQL_AND_LEN + |
8878 | ((SPIDER_LONGLONG_LEN) * 2))) |
8879 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8880 | str->q_append(SPIDER_SQL_BETWEEN_STR, SPIDER_SQL_BETWEEN_LEN); |
8881 | length = (uint32) (my_charset_bin.cset->longlong10_to_str)( |
8882 | &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, offset + 1); |
8883 | str->q_append(buf, length); |
8884 | str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
8885 | length = (uint32) (my_charset_bin.cset->longlong10_to_str)( |
8886 | &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit + offset); |
8887 | str->q_append(buf, length); |
8888 | } else { |
8889 | if (str->reserve(SPIDER_SQL_HS_LTEQUAL_LEN + |
8890 | (SPIDER_LONGLONG_LEN))) |
8891 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8892 | str->q_append(SPIDER_SQL_HS_LTEQUAL_STR, SPIDER_SQL_HS_LTEQUAL_LEN); |
8893 | length = (uint32) (my_charset_bin.cset->longlong10_to_str)( |
8894 | &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit); |
8895 | str->q_append(buf, length); |
8896 | } |
8897 | if (update_rownum_appended) |
8898 | { |
8899 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) |
8900 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8901 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
8902 | } |
8903 | } |
8904 | DBUG_RETURN(0); |
8905 | } |
8906 | |
8907 | int spider_oracle_handler::append_select_lock_part( |
8908 | ulong sql_type |
8909 | ) { |
8910 | int error_num; |
8911 | spider_string *str; |
8912 | DBUG_ENTER("spider_oracle_handler::append_select_lock_part" ); |
8913 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8914 | switch (sql_type) |
8915 | { |
8916 | case SPIDER_SQL_TYPE_SELECT_SQL: |
8917 | str = &sql; |
8918 | break; |
8919 | default: |
8920 | DBUG_RETURN(0); |
8921 | } |
8922 | error_num = append_select_lock(str); |
8923 | DBUG_PRINT("info" ,("spider str=%s" , str->c_ptr_safe())); |
8924 | DBUG_PRINT("info" ,("spider length=%u" , str->length())); |
8925 | DBUG_RETURN(error_num); |
8926 | } |
8927 | |
8928 | int spider_oracle_handler::append_select_lock( |
8929 | spider_string *str |
8930 | ) { |
8931 | int lock_mode = spider_conn_lock_mode(spider); |
8932 | DBUG_ENTER("spider_oracle_handler::append_select_lock" ); |
8933 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8934 | if (select_rownum_appended) |
8935 | { |
8936 | table_lock_mode = lock_mode; |
8937 | } else { |
8938 | if (lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) |
8939 | { |
8940 | if (str->reserve(SPIDER_SQL_FOR_UPDATE_LEN)) |
8941 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8942 | str->q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); |
8943 | } else if (lock_mode == SPIDER_LOCK_MODE_SHARED) |
8944 | { |
8945 | if (str->reserve(SPIDER_SQL_FOR_UPDATE_LEN)) |
8946 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8947 | str->q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); |
8948 | } |
8949 | } |
8950 | DBUG_RETURN(0); |
8951 | } |
8952 | |
8953 | int spider_oracle_handler::append_union_all_start_part( |
8954 | ulong sql_type |
8955 | ) { |
8956 | int error_num; |
8957 | spider_string *str; |
8958 | DBUG_ENTER("spider_oracle_handler::append_union_all_start_part" ); |
8959 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8960 | switch (sql_type) |
8961 | { |
8962 | case SPIDER_SQL_TYPE_SELECT_SQL: |
8963 | str = &sql; |
8964 | break; |
8965 | default: |
8966 | DBUG_RETURN(0); |
8967 | } |
8968 | error_num = append_union_all_start(str); |
8969 | DBUG_RETURN(error_num); |
8970 | } |
8971 | |
8972 | int spider_oracle_handler::append_union_all_start( |
8973 | spider_string *str |
8974 | ) { |
8975 | DBUG_ENTER("spider_oracle_handler::append_union_all_start" ); |
8976 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8977 | if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) |
8978 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
8979 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
8980 | DBUG_RETURN(0); |
8981 | } |
8982 | |
8983 | int spider_oracle_handler::append_union_all_part( |
8984 | ulong sql_type |
8985 | ) { |
8986 | int error_num; |
8987 | spider_string *str; |
8988 | DBUG_ENTER("spider_oracle_handler::append_union_all_part" ); |
8989 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
8990 | switch (sql_type) |
8991 | { |
8992 | case SPIDER_SQL_TYPE_SELECT_SQL: |
8993 | str = &sql; |
8994 | break; |
8995 | default: |
8996 | DBUG_RETURN(0); |
8997 | } |
8998 | error_num = append_union_all(str); |
8999 | DBUG_RETURN(error_num); |
9000 | } |
9001 | |
9002 | int spider_oracle_handler::append_union_all( |
9003 | spider_string *str |
9004 | ) { |
9005 | DBUG_ENTER("spider_oracle_handler::append_union_all" ); |
9006 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9007 | if (str->reserve(SPIDER_SQL_UNION_ALL_LEN)) |
9008 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9009 | str->q_append(SPIDER_SQL_UNION_ALL_STR, SPIDER_SQL_UNION_ALL_LEN); |
9010 | DBUG_RETURN(0); |
9011 | } |
9012 | |
9013 | int spider_oracle_handler::append_union_all_end_part( |
9014 | ulong sql_type |
9015 | ) { |
9016 | int error_num; |
9017 | spider_string *str; |
9018 | DBUG_ENTER("spider_oracle_handler::append_union_all_end_part" ); |
9019 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9020 | switch (sql_type) |
9021 | { |
9022 | case SPIDER_SQL_TYPE_SELECT_SQL: |
9023 | str = &sql; |
9024 | break; |
9025 | default: |
9026 | DBUG_RETURN(0); |
9027 | } |
9028 | error_num = append_union_all_end(str); |
9029 | DBUG_RETURN(error_num); |
9030 | } |
9031 | |
9032 | int spider_oracle_handler::append_union_all_end( |
9033 | spider_string *str |
9034 | ) { |
9035 | DBUG_ENTER("spider_oracle_handler::append_union_all_end" ); |
9036 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9037 | str->length(str->length() - |
9038 | SPIDER_SQL_UNION_ALL_LEN + SPIDER_SQL_CLOSE_PAREN_LEN); |
9039 | DBUG_RETURN(0); |
9040 | } |
9041 | |
9042 | int spider_oracle_handler::append_multi_range_cnt_part( |
9043 | ulong sql_type, |
9044 | uint multi_range_cnt, |
9045 | bool with_comma |
9046 | ) { |
9047 | int error_num; |
9048 | spider_string *str; |
9049 | DBUG_ENTER("spider_oracle_handler::append_multi_range_cnt_part" ); |
9050 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9051 | switch (sql_type) |
9052 | { |
9053 | case SPIDER_SQL_TYPE_SELECT_SQL: |
9054 | str = &sql; |
9055 | break; |
9056 | case SPIDER_SQL_TYPE_TMP_SQL: |
9057 | str = &tmp_sql; |
9058 | break; |
9059 | default: |
9060 | DBUG_RETURN(0); |
9061 | } |
9062 | error_num = append_multi_range_cnt(str, multi_range_cnt, with_comma); |
9063 | DBUG_RETURN(error_num); |
9064 | } |
9065 | |
9066 | int spider_oracle_handler::append_multi_range_cnt( |
9067 | spider_string *str, |
9068 | uint multi_range_cnt, |
9069 | bool with_comma |
9070 | ) { |
9071 | int range_cnt_length; |
9072 | char range_cnt_str[SPIDER_SQL_INT_LEN]; |
9073 | DBUG_ENTER("spider_oracle_handler::append_multi_range_cnt" ); |
9074 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9075 | range_cnt_length = my_sprintf(range_cnt_str, (range_cnt_str, "%u" , |
9076 | multi_range_cnt)); |
9077 | if (with_comma) |
9078 | { |
9079 | if (str->reserve(range_cnt_length + SPIDER_SQL_COMMA_LEN)) |
9080 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9081 | str->q_append(range_cnt_str, range_cnt_length); |
9082 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
9083 | } else { |
9084 | if (str->reserve(range_cnt_length)) |
9085 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9086 | str->q_append(range_cnt_str, range_cnt_length); |
9087 | } |
9088 | DBUG_RETURN(0); |
9089 | } |
9090 | |
9091 | int spider_oracle_handler::append_multi_range_cnt_with_name_part( |
9092 | ulong sql_type, |
9093 | uint multi_range_cnt |
9094 | ) { |
9095 | int error_num; |
9096 | spider_string *str; |
9097 | DBUG_ENTER("spider_oracle_handler::append_multi_range_cnt_with_name_part" ); |
9098 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9099 | switch (sql_type) |
9100 | { |
9101 | case SPIDER_SQL_TYPE_SELECT_SQL: |
9102 | str = &sql; |
9103 | break; |
9104 | case SPIDER_SQL_TYPE_TMP_SQL: |
9105 | str = &tmp_sql; |
9106 | break; |
9107 | default: |
9108 | DBUG_RETURN(0); |
9109 | } |
9110 | error_num = append_multi_range_cnt_with_name(str, multi_range_cnt); |
9111 | DBUG_RETURN(error_num); |
9112 | } |
9113 | |
9114 | int spider_oracle_handler::append_multi_range_cnt_with_name( |
9115 | spider_string *str, |
9116 | uint multi_range_cnt |
9117 | ) { |
9118 | int range_cnt_length; |
9119 | char range_cnt_str[SPIDER_SQL_INT_LEN]; |
9120 | DBUG_ENTER("spider_oracle_handler::append_multi_range_cnt_with_name" ); |
9121 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9122 | range_cnt_length = my_sprintf(range_cnt_str, (range_cnt_str, "%u" , |
9123 | multi_range_cnt)); |
9124 | if (str->reserve(range_cnt_length + SPIDER_SQL_SPACE_LEN + |
9125 | SPIDER_SQL_ID_LEN + SPIDER_SQL_COMMA_LEN)) |
9126 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9127 | str->q_append(range_cnt_str, range_cnt_length); |
9128 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
9129 | str->q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); |
9130 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
9131 | DBUG_RETURN(0); |
9132 | } |
9133 | |
9134 | int spider_oracle_handler::append_open_handler_part( |
9135 | ulong sql_type, |
9136 | uint handler_id, |
9137 | SPIDER_CONN *conn, |
9138 | int link_idx |
9139 | ) { |
9140 | int error_num; |
9141 | spider_string *str; |
9142 | DBUG_ENTER("spider_oracle_handler::append_open_handler_part" ); |
9143 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9144 | switch (sql_type) |
9145 | { |
9146 | case SPIDER_SQL_TYPE_HANDLER: |
9147 | str = &ha_sql; |
9148 | break; |
9149 | default: |
9150 | DBUG_RETURN(0); |
9151 | } |
9152 | error_num = append_open_handler(str, handler_id, conn, link_idx); |
9153 | exec_ha_sql = str; |
9154 | DBUG_RETURN(error_num); |
9155 | } |
9156 | |
9157 | int spider_oracle_handler::append_open_handler( |
9158 | spider_string *str, |
9159 | uint handler_id, |
9160 | SPIDER_CONN *conn, |
9161 | int link_idx |
9162 | ) { |
9163 | int error_num; |
9164 | DBUG_ENTER("spider_oracle_handler::append_open_handler" ); |
9165 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9166 | DBUG_PRINT("info" ,("spider link_idx=%d" , link_idx)); |
9167 | DBUG_PRINT("info" ,("spider m_handler_cid=%s" , |
9168 | spider->m_handler_cid[link_idx])); |
9169 | if (str->reserve(SPIDER_SQL_HANDLER_LEN)) |
9170 | { |
9171 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9172 | } |
9173 | str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); |
9174 | if ((error_num = oracle_share->append_table_name(str, |
9175 | spider->conn_link_idx[link_idx]))) |
9176 | DBUG_RETURN(error_num); |
9177 | if (str->reserve(SPIDER_SQL_OPEN_LEN + SPIDER_SQL_AS_LEN + |
9178 | SPIDER_SQL_HANDLER_CID_LEN)) |
9179 | { |
9180 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9181 | } |
9182 | str->q_append(SPIDER_SQL_OPEN_STR, SPIDER_SQL_OPEN_LEN); |
9183 | str->q_append(SPIDER_SQL_AS_STR, SPIDER_SQL_AS_LEN); |
9184 | str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); |
9185 | DBUG_RETURN(0); |
9186 | } |
9187 | |
9188 | int spider_oracle_handler::append_close_handler_part( |
9189 | ulong sql_type, |
9190 | int link_idx |
9191 | ) { |
9192 | int error_num; |
9193 | spider_string *str; |
9194 | DBUG_ENTER("spider_oracle_handler::append_close_handler_part" ); |
9195 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9196 | switch (sql_type) |
9197 | { |
9198 | case SPIDER_SQL_TYPE_HANDLER: |
9199 | str = &ha_sql; |
9200 | break; |
9201 | default: |
9202 | DBUG_RETURN(0); |
9203 | } |
9204 | error_num = append_close_handler(str, link_idx); |
9205 | exec_ha_sql = str; |
9206 | DBUG_RETURN(error_num); |
9207 | } |
9208 | |
9209 | int spider_oracle_handler::append_close_handler( |
9210 | spider_string *str, |
9211 | int link_idx |
9212 | ) { |
9213 | DBUG_ENTER("spider_oracle_handler::append_close_handler" ); |
9214 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9215 | if (str->reserve(SPIDER_SQL_HANDLER_LEN + SPIDER_SQL_CLOSE_LEN + |
9216 | SPIDER_SQL_HANDLER_CID_LEN)) |
9217 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9218 | str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); |
9219 | str->q_append(spider->m_handler_cid[link_idx], |
9220 | SPIDER_SQL_HANDLER_CID_LEN); |
9221 | str->q_append(SPIDER_SQL_CLOSE_STR, SPIDER_SQL_CLOSE_LEN); |
9222 | DBUG_RETURN(0); |
9223 | } |
9224 | |
9225 | int spider_oracle_handler::append_insert_terminator_part( |
9226 | ulong sql_type |
9227 | ) { |
9228 | int error_num; |
9229 | spider_string *str; |
9230 | DBUG_ENTER("spider_oracle_handler::append_insert_terminator_part" ); |
9231 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9232 | switch (sql_type) |
9233 | { |
9234 | case SPIDER_SQL_TYPE_INSERT_SQL: |
9235 | str = &insert_sql; |
9236 | break; |
9237 | default: |
9238 | DBUG_RETURN(0); |
9239 | } |
9240 | error_num = append_insert_terminator(str); |
9241 | DBUG_RETURN(error_num); |
9242 | } |
9243 | |
9244 | int spider_oracle_handler::append_insert_terminator( |
9245 | spider_string *str |
9246 | ) { |
9247 | DBUG_ENTER("spider_oracle_handler::append_insert_terminator" ); |
9248 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9249 | if (spider->result_list.insert_dup_update_pushdown) |
9250 | { |
9251 | DBUG_PRINT("info" ,("spider add duplicate key update" )); |
9252 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
9253 | if (str->reserve(SPIDER_SQL_DUPLICATE_KEY_UPDATE_LEN + |
9254 | dup_update_sql.length())) |
9255 | { |
9256 | str->length(0); |
9257 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9258 | } |
9259 | str->q_append(SPIDER_SQL_DUPLICATE_KEY_UPDATE_STR, |
9260 | SPIDER_SQL_DUPLICATE_KEY_UPDATE_LEN); |
9261 | if (str->append(dup_update_sql)) |
9262 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9263 | } else { |
9264 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
9265 | } |
9266 | DBUG_RETURN(0); |
9267 | } |
9268 | |
9269 | int spider_oracle_handler::append_insert_values_part( |
9270 | ulong sql_type |
9271 | ) { |
9272 | int error_num; |
9273 | spider_string *str; |
9274 | DBUG_ENTER("spider_oracle_handler::append_insert_values_part" ); |
9275 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9276 | switch (sql_type) |
9277 | { |
9278 | case SPIDER_SQL_TYPE_INSERT_SQL: |
9279 | str = &insert_sql; |
9280 | break; |
9281 | default: |
9282 | DBUG_RETURN(0); |
9283 | } |
9284 | error_num = append_insert_values(str); |
9285 | DBUG_RETURN(error_num); |
9286 | } |
9287 | |
9288 | int spider_oracle_handler::append_insert_values( |
9289 | spider_string *str |
9290 | ) { |
9291 | SPIDER_SHARE *share = spider->share; |
9292 | TABLE *table = spider->get_table(); |
9293 | Field **field; |
9294 | bool add_value = FALSE; |
9295 | DBUG_ENTER("spider_oracle_handler::append_insert_values" ); |
9296 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9297 | nextval_pos = 0; |
9298 | if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) |
9299 | { |
9300 | str->length(0); |
9301 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9302 | } |
9303 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
9304 | for (field = table->field; *field; field++) |
9305 | { |
9306 | DBUG_PRINT("info" ,("spider field_index=%u" , (*field)->field_index)); |
9307 | if ( |
9308 | bitmap_is_set(table->write_set, (*field)->field_index) || |
9309 | bitmap_is_set(table->read_set, (*field)->field_index) |
9310 | ) { |
9311 | #ifndef DBUG_OFF |
9312 | my_bitmap_map *tmp_map = |
9313 | dbug_tmp_use_all_columns(table, table->read_set); |
9314 | #endif |
9315 | add_value = TRUE; |
9316 | DBUG_PRINT("info" ,("spider is_null()=%s" , |
9317 | (*field)->is_null() ? "TRUE" : "FALSE" )); |
9318 | DBUG_PRINT("info" ,("spider table->next_number_field=%p" , |
9319 | table->next_number_field)); |
9320 | DBUG_PRINT("info" ,("spider *field=%p" , *field)); |
9321 | DBUG_PRINT("info" ,("spider force_auto_increment=%s" , |
9322 | (table->next_number_field && spider->force_auto_increment) ? |
9323 | "TRUE" : "FALSE" )); |
9324 | if ( |
9325 | table->next_number_field == *field && |
9326 | !table->auto_increment_field_not_null && |
9327 | !spider->force_auto_increment |
9328 | ) { |
9329 | nextval_pos = str->length(); |
9330 | if (str->reserve(oracle_share->nextval_max_length + |
9331 | SPIDER_SQL_COMMA_LEN)) |
9332 | { |
9333 | #ifndef DBUG_OFF |
9334 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
9335 | #endif |
9336 | str->length(0); |
9337 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9338 | } |
9339 | str->length(str->length() + oracle_share->nextval_max_length); |
9340 | } else if ((*field)->is_null()) |
9341 | { |
9342 | if (str->reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) |
9343 | { |
9344 | #ifndef DBUG_OFF |
9345 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
9346 | #endif |
9347 | str->length(0); |
9348 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9349 | } |
9350 | str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); |
9351 | } else { |
9352 | if ( |
9353 | spider_db_oracle_utility. |
9354 | append_column_value(spider, str, *field, NULL, |
9355 | share->access_charset) || |
9356 | str->reserve(SPIDER_SQL_COMMA_LEN) |
9357 | ) { |
9358 | #ifndef DBUG_OFF |
9359 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
9360 | #endif |
9361 | str->length(0); |
9362 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9363 | } |
9364 | } |
9365 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
9366 | #ifndef DBUG_OFF |
9367 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
9368 | #endif |
9369 | } |
9370 | } |
9371 | if (add_value) |
9372 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
9373 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) |
9374 | { |
9375 | str->length(0); |
9376 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9377 | } |
9378 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
9379 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
9380 | DBUG_RETURN(0); |
9381 | } |
9382 | |
9383 | int spider_oracle_handler::append_into_part( |
9384 | ulong sql_type |
9385 | ) { |
9386 | int error_num; |
9387 | spider_string *str; |
9388 | DBUG_ENTER("spider_oracle_handler::append_into_part" ); |
9389 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9390 | switch (sql_type) |
9391 | { |
9392 | case SPIDER_SQL_TYPE_INSERT_SQL: |
9393 | str = &insert_sql; |
9394 | break; |
9395 | default: |
9396 | DBUG_RETURN(0); |
9397 | } |
9398 | error_num = append_into(str); |
9399 | DBUG_RETURN(error_num); |
9400 | } |
9401 | |
9402 | int spider_oracle_handler::append_into( |
9403 | spider_string *str |
9404 | ) { |
9405 | const TABLE *table = spider->get_table(); |
9406 | Field **field; |
9407 | uint field_name_length = 0; |
9408 | DBUG_ENTER("spider_oracle_handler::append_into" ); |
9409 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9410 | if (str->reserve(SPIDER_SQL_INTO_LEN + oracle_share->db_nm_max_length + |
9411 | SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + |
9412 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) |
9413 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9414 | str->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); |
9415 | insert_table_name_pos = str->length(); |
9416 | append_table_name_with_adjusting(str, first_link_idx, |
9417 | SPIDER_SQL_TYPE_INSERT_SQL); |
9418 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
9419 | for (field = table->field; *field; field++) |
9420 | { |
9421 | if ( |
9422 | bitmap_is_set(table->write_set, (*field)->field_index) || |
9423 | bitmap_is_set(table->read_set, (*field)->field_index) |
9424 | ) { |
9425 | field_name_length = |
9426 | oracle_share->column_name_str[(*field)->field_index].length(); |
9427 | if (str->reserve(field_name_length + |
9428 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) |
9429 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9430 | oracle_share->append_column_name(str, (*field)->field_index); |
9431 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
9432 | } |
9433 | } |
9434 | if (field_name_length) |
9435 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
9436 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_VALUES_LEN)) |
9437 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9438 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
9439 | str->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); |
9440 | insert_pos = str->length(); |
9441 | DBUG_RETURN(0); |
9442 | } |
9443 | |
9444 | void spider_oracle_handler::set_insert_to_pos( |
9445 | ulong sql_type |
9446 | ) { |
9447 | DBUG_ENTER("spider_oracle_handler::set_insert_to_pos" ); |
9448 | switch (sql_type) |
9449 | { |
9450 | case SPIDER_SQL_TYPE_INSERT_SQL: |
9451 | insert_sql.length(insert_pos); |
9452 | break; |
9453 | default: |
9454 | DBUG_ASSERT(0); |
9455 | break; |
9456 | } |
9457 | DBUG_VOID_RETURN; |
9458 | } |
9459 | |
9460 | int spider_oracle_handler::append_from_part( |
9461 | ulong sql_type, |
9462 | int link_idx |
9463 | ) { |
9464 | int error_num; |
9465 | spider_string *str; |
9466 | DBUG_ENTER("spider_oracle_handler::append_from_part" ); |
9467 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9468 | switch (sql_type) |
9469 | { |
9470 | case SPIDER_SQL_TYPE_HANDLER: |
9471 | str = &ha_sql; |
9472 | break; |
9473 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
9474 | case SPIDER_SQL_TYPE_DELETE_SQL: |
9475 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
9476 | str = &update_sql; |
9477 | break; |
9478 | default: |
9479 | str = &sql; |
9480 | break; |
9481 | } |
9482 | error_num = append_from(str, sql_type, link_idx); |
9483 | DBUG_RETURN(error_num); |
9484 | } |
9485 | |
9486 | int spider_oracle_handler::append_from( |
9487 | spider_string *str, |
9488 | ulong sql_type, |
9489 | int link_idx |
9490 | ) { |
9491 | DBUG_ENTER("spider_oracle_handler::append_from" ); |
9492 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9493 | DBUG_PRINT("info" ,("spider link_idx=%d" , link_idx)); |
9494 | if (sql_type == SPIDER_SQL_TYPE_HANDLER) |
9495 | { |
9496 | ha_table_name_pos = str->length(); |
9497 | DBUG_PRINT("info" ,("spider ha_table_name_pos=%u" , ha_table_name_pos)); |
9498 | ha_sql_handler_id = spider->m_handler_id[link_idx]; |
9499 | DBUG_PRINT("info" ,("spider ha_sql_handler_id=%u" , ha_sql_handler_id)); |
9500 | if (str->reserve(SPIDER_SQL_HANDLER_CID_LEN)) |
9501 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9502 | str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); |
9503 | DBUG_PRINT("info" ,("spider m_handler_cid=%s" , |
9504 | spider->m_handler_cid[link_idx])); |
9505 | } else { |
9506 | if (str->reserve(SPIDER_SQL_FROM_LEN + oracle_share->db_nm_max_length + |
9507 | SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + |
9508 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) |
9509 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9510 | str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
9511 | table_name_pos = str->length(); |
9512 | append_table_name_with_adjusting(str, link_idx, sql_type); |
9513 | } |
9514 | DBUG_RETURN(0); |
9515 | } |
9516 | |
9517 | int spider_oracle_handler::append_flush_tables_part( |
9518 | ulong sql_type, |
9519 | int link_idx, |
9520 | bool lock |
9521 | ) { |
9522 | int error_num; |
9523 | spider_string *str; |
9524 | DBUG_ENTER("spider_oracle_handler::append_flush_tables_part" ); |
9525 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9526 | switch (sql_type) |
9527 | { |
9528 | case SPIDER_SQL_TYPE_OTHER_SQL: |
9529 | str = &spider->result_list.sqls[link_idx]; |
9530 | break; |
9531 | default: |
9532 | DBUG_RETURN(0); |
9533 | } |
9534 | error_num = append_flush_tables(str, link_idx, lock); |
9535 | DBUG_RETURN(error_num); |
9536 | } |
9537 | |
9538 | int spider_oracle_handler::append_flush_tables( |
9539 | spider_string *str, |
9540 | int link_idx, |
9541 | bool lock |
9542 | ) { |
9543 | DBUG_ENTER("spider_oracle_handler::append_flush_tables" ); |
9544 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9545 | if (lock) |
9546 | { |
9547 | if (str->reserve(SPIDER_SQL_FLUSH_TABLES_LEN + |
9548 | SPIDER_SQL_WITH_READ_LOCK_LEN)) |
9549 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9550 | str->q_append(SPIDER_SQL_FLUSH_TABLES_STR, SPIDER_SQL_FLUSH_TABLES_LEN); |
9551 | str->q_append(SPIDER_SQL_WITH_READ_LOCK_STR, |
9552 | SPIDER_SQL_WITH_READ_LOCK_LEN); |
9553 | } else { |
9554 | if (str->reserve(SPIDER_SQL_FLUSH_TABLES_LEN)) |
9555 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9556 | str->q_append(SPIDER_SQL_FLUSH_TABLES_STR, SPIDER_SQL_FLUSH_TABLES_LEN); |
9557 | } |
9558 | DBUG_RETURN(0); |
9559 | } |
9560 | |
9561 | int spider_oracle_handler::append_optimize_table_part( |
9562 | ulong sql_type, |
9563 | int link_idx |
9564 | ) { |
9565 | int error_num; |
9566 | spider_string *str; |
9567 | DBUG_ENTER("spider_oracle_handler::append_optimize_table_part" ); |
9568 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9569 | switch (sql_type) |
9570 | { |
9571 | case SPIDER_SQL_TYPE_OTHER_SQL: |
9572 | str = &spider->result_list.sqls[link_idx]; |
9573 | break; |
9574 | default: |
9575 | DBUG_RETURN(0); |
9576 | } |
9577 | error_num = append_optimize_table(str, link_idx); |
9578 | DBUG_RETURN(error_num); |
9579 | } |
9580 | |
9581 | int spider_oracle_handler::append_optimize_table( |
9582 | spider_string *str, |
9583 | int link_idx |
9584 | ) { |
9585 | SPIDER_SHARE *share = spider->share; |
9586 | int conn_link_idx = spider->conn_link_idx[link_idx]; |
9587 | int local_length = spider_param_internal_optimize_local(spider->trx->thd, |
9588 | share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; |
9589 | DBUG_ENTER("spider_oracle_handler::append_optimize_table" ); |
9590 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9591 | if (str->reserve(SPIDER_SQL_SQL_OPTIMIZE_LEN + SPIDER_SQL_SQL_TABLE_LEN + |
9592 | local_length + |
9593 | oracle_share->db_names_str[conn_link_idx].length() + |
9594 | SPIDER_SQL_DOT_LEN + |
9595 | oracle_share->table_names_str[conn_link_idx].length() + |
9596 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) |
9597 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9598 | str->q_append(SPIDER_SQL_SQL_OPTIMIZE_STR, SPIDER_SQL_SQL_OPTIMIZE_LEN); |
9599 | if (local_length) |
9600 | str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); |
9601 | str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); |
9602 | oracle_share->append_table_name(str, conn_link_idx); |
9603 | DBUG_RETURN(0); |
9604 | } |
9605 | |
9606 | int spider_oracle_handler::append_analyze_table_part( |
9607 | ulong sql_type, |
9608 | int link_idx |
9609 | ) { |
9610 | int error_num; |
9611 | spider_string *str; |
9612 | DBUG_ENTER("spider_oracle_handler::append_analyze_table_part" ); |
9613 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9614 | switch (sql_type) |
9615 | { |
9616 | case SPIDER_SQL_TYPE_OTHER_SQL: |
9617 | str = &spider->result_list.sqls[link_idx]; |
9618 | break; |
9619 | default: |
9620 | DBUG_RETURN(0); |
9621 | } |
9622 | error_num = append_analyze_table(str, link_idx); |
9623 | DBUG_RETURN(error_num); |
9624 | } |
9625 | |
9626 | int spider_oracle_handler::append_analyze_table( |
9627 | spider_string *str, |
9628 | int link_idx |
9629 | ) { |
9630 | SPIDER_SHARE *share = spider->share; |
9631 | int conn_link_idx = spider->conn_link_idx[link_idx]; |
9632 | int local_length = spider_param_internal_optimize_local(spider->trx->thd, |
9633 | share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; |
9634 | DBUG_ENTER("spider_oracle_handler::append_analyze_table" ); |
9635 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9636 | if (str->reserve(SPIDER_SQL_SQL_ANALYZE_LEN + SPIDER_SQL_SQL_TABLE_LEN + |
9637 | local_length + |
9638 | oracle_share->db_names_str[conn_link_idx].length() + |
9639 | SPIDER_SQL_DOT_LEN + |
9640 | oracle_share->table_names_str[conn_link_idx].length() + |
9641 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) |
9642 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9643 | str->q_append(SPIDER_SQL_SQL_ANALYZE_STR, SPIDER_SQL_SQL_ANALYZE_LEN); |
9644 | if (local_length) |
9645 | str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); |
9646 | str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); |
9647 | oracle_share->append_table_name(str, conn_link_idx); |
9648 | DBUG_RETURN(0); |
9649 | } |
9650 | |
9651 | int spider_oracle_handler::append_repair_table_part( |
9652 | ulong sql_type, |
9653 | int link_idx, |
9654 | HA_CHECK_OPT* check_opt |
9655 | ) { |
9656 | int error_num; |
9657 | spider_string *str; |
9658 | DBUG_ENTER("spider_oracle_handler::append_repair_table_part" ); |
9659 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9660 | switch (sql_type) |
9661 | { |
9662 | case SPIDER_SQL_TYPE_OTHER_SQL: |
9663 | str = &spider->result_list.sqls[link_idx]; |
9664 | break; |
9665 | default: |
9666 | DBUG_RETURN(0); |
9667 | } |
9668 | error_num = append_repair_table(str, link_idx, check_opt); |
9669 | DBUG_RETURN(error_num); |
9670 | } |
9671 | |
9672 | int spider_oracle_handler::append_repair_table( |
9673 | spider_string *str, |
9674 | int link_idx, |
9675 | HA_CHECK_OPT* check_opt |
9676 | ) { |
9677 | SPIDER_SHARE *share = spider->share; |
9678 | int conn_link_idx = spider->conn_link_idx[link_idx]; |
9679 | int local_length = spider_param_internal_optimize_local(spider->trx->thd, |
9680 | share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; |
9681 | DBUG_ENTER("spider_oracle_handler::append_repair_table" ); |
9682 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9683 | if (str->reserve(SPIDER_SQL_SQL_REPAIR_LEN + SPIDER_SQL_SQL_TABLE_LEN + |
9684 | local_length + |
9685 | oracle_share->db_names_str[conn_link_idx].length() + |
9686 | SPIDER_SQL_DOT_LEN + |
9687 | oracle_share->table_names_str[conn_link_idx].length() + |
9688 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) |
9689 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9690 | str->q_append(SPIDER_SQL_SQL_REPAIR_STR, SPIDER_SQL_SQL_REPAIR_LEN); |
9691 | if (local_length) |
9692 | str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); |
9693 | str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); |
9694 | oracle_share->append_table_name(str, conn_link_idx); |
9695 | if (check_opt->flags & T_QUICK) |
9696 | { |
9697 | if (str->reserve(SPIDER_SQL_SQL_QUICK_LEN)) |
9698 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9699 | str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN); |
9700 | } |
9701 | if (check_opt->flags & T_EXTEND) |
9702 | { |
9703 | if (str->reserve(SPIDER_SQL_SQL_EXTENDED_LEN)) |
9704 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9705 | str->q_append(SPIDER_SQL_SQL_EXTENDED_STR, SPIDER_SQL_SQL_EXTENDED_LEN); |
9706 | } |
9707 | if (check_opt->sql_flags & TT_USEFRM) |
9708 | { |
9709 | if (str->reserve(SPIDER_SQL_SQL_USE_FRM_LEN)) |
9710 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9711 | str->q_append(SPIDER_SQL_SQL_USE_FRM_STR, SPIDER_SQL_SQL_USE_FRM_LEN); |
9712 | } |
9713 | DBUG_RETURN(0); |
9714 | } |
9715 | |
9716 | int spider_oracle_handler::append_check_table_part( |
9717 | ulong sql_type, |
9718 | int link_idx, |
9719 | HA_CHECK_OPT* check_opt |
9720 | ) { |
9721 | int error_num; |
9722 | spider_string *str; |
9723 | DBUG_ENTER("spider_oracle_handler::append_check_table_part" ); |
9724 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9725 | switch (sql_type) |
9726 | { |
9727 | case SPIDER_SQL_TYPE_OTHER_SQL: |
9728 | str = &spider->result_list.sqls[link_idx]; |
9729 | break; |
9730 | default: |
9731 | DBUG_RETURN(0); |
9732 | } |
9733 | error_num = append_check_table(str, link_idx, check_opt); |
9734 | DBUG_RETURN(error_num); |
9735 | } |
9736 | |
9737 | int spider_oracle_handler::append_check_table( |
9738 | spider_string *str, |
9739 | int link_idx, |
9740 | HA_CHECK_OPT* check_opt |
9741 | ) { |
9742 | int conn_link_idx = spider->conn_link_idx[link_idx]; |
9743 | DBUG_ENTER("spider_oracle_handler::append_check_table" ); |
9744 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9745 | if (str->reserve(SPIDER_SQL_SQL_CHECK_TABLE_LEN + |
9746 | oracle_share->db_names_str[conn_link_idx].length() + |
9747 | SPIDER_SQL_DOT_LEN + |
9748 | oracle_share->table_names_str[conn_link_idx].length() + |
9749 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) |
9750 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9751 | str->q_append(SPIDER_SQL_SQL_CHECK_TABLE_STR, |
9752 | SPIDER_SQL_SQL_CHECK_TABLE_LEN); |
9753 | oracle_share->append_table_name(str, conn_link_idx); |
9754 | if (check_opt->flags & T_QUICK) |
9755 | { |
9756 | if (str->reserve(SPIDER_SQL_SQL_QUICK_LEN)) |
9757 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9758 | str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN); |
9759 | } |
9760 | if (check_opt->flags & T_FAST) |
9761 | { |
9762 | if (str->reserve(SPIDER_SQL_SQL_FAST_LEN)) |
9763 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9764 | str->q_append(SPIDER_SQL_SQL_FAST_STR, SPIDER_SQL_SQL_FAST_LEN); |
9765 | } |
9766 | if (check_opt->flags & T_MEDIUM) |
9767 | { |
9768 | if (str->reserve(SPIDER_SQL_SQL_MEDIUM_LEN)) |
9769 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9770 | str->q_append(SPIDER_SQL_SQL_MEDIUM_STR, SPIDER_SQL_SQL_MEDIUM_LEN); |
9771 | } |
9772 | if (check_opt->flags & T_EXTEND) |
9773 | { |
9774 | if (str->reserve(SPIDER_SQL_SQL_EXTENDED_LEN)) |
9775 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9776 | str->q_append(SPIDER_SQL_SQL_EXTENDED_STR, SPIDER_SQL_SQL_EXTENDED_LEN); |
9777 | } |
9778 | DBUG_RETURN(0); |
9779 | } |
9780 | |
9781 | int spider_oracle_handler::append_enable_keys_part( |
9782 | ulong sql_type, |
9783 | int link_idx |
9784 | ) { |
9785 | int error_num; |
9786 | spider_string *str; |
9787 | DBUG_ENTER("spider_oracle_handler::append_enable_keys_part" ); |
9788 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9789 | switch (sql_type) |
9790 | { |
9791 | case SPIDER_SQL_TYPE_OTHER_SQL: |
9792 | str = &spider->result_list.sqls[link_idx]; |
9793 | break; |
9794 | default: |
9795 | DBUG_RETURN(0); |
9796 | } |
9797 | error_num = append_enable_keys(str, link_idx); |
9798 | DBUG_RETURN(error_num); |
9799 | } |
9800 | |
9801 | int spider_oracle_handler::append_enable_keys( |
9802 | spider_string *str, |
9803 | int link_idx |
9804 | ) { |
9805 | int conn_link_idx = spider->conn_link_idx[link_idx]; |
9806 | DBUG_ENTER("spider_oracle_handler::append_enable_keys" ); |
9807 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9808 | if (str->reserve(SPIDER_SQL_SQL_ALTER_TABLE_LEN + |
9809 | oracle_share->db_names_str[conn_link_idx].length() + |
9810 | SPIDER_SQL_DOT_LEN + |
9811 | oracle_share->table_names_str[conn_link_idx].length() + |
9812 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_SQL_ENABLE_KEYS_LEN)) |
9813 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9814 | str->q_append(SPIDER_SQL_SQL_ALTER_TABLE_STR, |
9815 | SPIDER_SQL_SQL_ALTER_TABLE_LEN); |
9816 | oracle_share->append_table_name(str, conn_link_idx); |
9817 | str->q_append(SPIDER_SQL_SQL_ENABLE_KEYS_STR, |
9818 | SPIDER_SQL_SQL_ENABLE_KEYS_LEN); |
9819 | DBUG_RETURN(0); |
9820 | } |
9821 | |
9822 | int spider_oracle_handler::append_disable_keys_part( |
9823 | ulong sql_type, |
9824 | int link_idx |
9825 | ) { |
9826 | int error_num; |
9827 | spider_string *str; |
9828 | DBUG_ENTER("spider_oracle_handler::append_disable_keys_part" ); |
9829 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9830 | switch (sql_type) |
9831 | { |
9832 | case SPIDER_SQL_TYPE_OTHER_SQL: |
9833 | str = &spider->result_list.sqls[link_idx]; |
9834 | break; |
9835 | default: |
9836 | DBUG_RETURN(0); |
9837 | } |
9838 | error_num = append_disable_keys(str, link_idx); |
9839 | DBUG_RETURN(error_num); |
9840 | } |
9841 | |
9842 | int spider_oracle_handler::append_disable_keys( |
9843 | spider_string *str, |
9844 | int link_idx |
9845 | ) { |
9846 | int conn_link_idx = spider->conn_link_idx[link_idx]; |
9847 | DBUG_ENTER("spider_oracle_handler::append_disable_keys" ); |
9848 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9849 | if (str->reserve(SPIDER_SQL_SQL_ALTER_TABLE_LEN + |
9850 | oracle_share->db_names_str[conn_link_idx].length() + |
9851 | SPIDER_SQL_DOT_LEN + |
9852 | oracle_share->table_names_str[conn_link_idx].length() + |
9853 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_SQL_DISABLE_KEYS_LEN)) |
9854 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9855 | str->q_append(SPIDER_SQL_SQL_ALTER_TABLE_STR, |
9856 | SPIDER_SQL_SQL_ALTER_TABLE_LEN); |
9857 | oracle_share->append_table_name(str, conn_link_idx); |
9858 | str->q_append(SPIDER_SQL_SQL_DISABLE_KEYS_STR, |
9859 | SPIDER_SQL_SQL_DISABLE_KEYS_LEN); |
9860 | DBUG_RETURN(0); |
9861 | } |
9862 | |
9863 | int spider_oracle_handler::append_delete_all_rows_part( |
9864 | ulong sql_type |
9865 | ) { |
9866 | int error_num; |
9867 | spider_string *str; |
9868 | DBUG_ENTER("spider_oracle_handler::append_delete_all_rows_part" ); |
9869 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9870 | switch (sql_type) |
9871 | { |
9872 | case SPIDER_SQL_TYPE_DELETE_SQL: |
9873 | str = &update_sql; |
9874 | break; |
9875 | default: |
9876 | DBUG_RETURN(0); |
9877 | } |
9878 | error_num = append_delete_all_rows(str, sql_type); |
9879 | DBUG_RETURN(error_num); |
9880 | } |
9881 | |
9882 | int spider_oracle_handler::append_delete_all_rows( |
9883 | spider_string *str, |
9884 | ulong sql_type |
9885 | ) { |
9886 | int error_num; |
9887 | DBUG_ENTER("spider_oracle_handler::append_delete_all_rows" ); |
9888 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9889 | if (spider->sql_command == SQLCOM_TRUNCATE) |
9890 | { |
9891 | if ((error_num = append_truncate(str, sql_type, first_link_idx))) |
9892 | DBUG_RETURN(error_num); |
9893 | } else { |
9894 | if ( |
9895 | (error_num = append_delete(str)) || |
9896 | (error_num = append_from(str, sql_type, first_link_idx)) |
9897 | ) |
9898 | DBUG_RETURN(error_num); |
9899 | } |
9900 | DBUG_RETURN(0); |
9901 | } |
9902 | |
9903 | int spider_oracle_handler::append_truncate( |
9904 | spider_string *str, |
9905 | ulong sql_type, |
9906 | int link_idx |
9907 | ) { |
9908 | DBUG_ENTER("spider_oracle_handler::append_truncate" ); |
9909 | if (str->reserve(SPIDER_SQL_TRUNCATE_TABLE_LEN + |
9910 | oracle_share->db_nm_max_length + |
9911 | SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + |
9912 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) |
9913 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9914 | str->q_append(SPIDER_SQL_TRUNCATE_TABLE_STR, SPIDER_SQL_TRUNCATE_TABLE_LEN); |
9915 | table_name_pos = str->length(); |
9916 | append_table_name_with_adjusting(str, link_idx, sql_type); |
9917 | DBUG_RETURN(0); |
9918 | } |
9919 | |
9920 | int spider_oracle_handler::append_explain_select_part( |
9921 | key_range *start_key, |
9922 | key_range *end_key, |
9923 | ulong sql_type, |
9924 | int link_idx |
9925 | ) { |
9926 | int error_num; |
9927 | spider_string *str; |
9928 | DBUG_ENTER("spider_oracle_handler::append_explain_select_part" ); |
9929 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9930 | switch (sql_type) |
9931 | { |
9932 | case SPIDER_SQL_TYPE_OTHER_SQL: |
9933 | str = &spider->result_list.sqls[link_idx]; |
9934 | break; |
9935 | default: |
9936 | DBUG_RETURN(0); |
9937 | } |
9938 | error_num = |
9939 | append_explain_select(str, start_key, end_key, sql_type, link_idx); |
9940 | DBUG_RETURN(error_num); |
9941 | } |
9942 | |
9943 | int spider_oracle_handler::append_explain_select( |
9944 | spider_string *str, |
9945 | key_range *start_key, |
9946 | key_range *end_key, |
9947 | ulong sql_type, |
9948 | int link_idx |
9949 | ) { |
9950 | int error_num; |
9951 | DBUG_ENTER("spider_oracle_handler::append_explain_select" ); |
9952 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
9953 | if (str->reserve(SPIDER_SQL_EXPLAIN_SELECT_LEN)) |
9954 | { |
9955 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9956 | } |
9957 | str->q_append(SPIDER_SQL_EXPLAIN_SELECT_STR, SPIDER_SQL_EXPLAIN_SELECT_LEN); |
9958 | if ( |
9959 | (error_num = append_from(str, sql_type, link_idx)) || |
9960 | (error_num = append_key_where(str, NULL, NULL, start_key, end_key, |
9961 | sql_type, FALSE)) |
9962 | ) { |
9963 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
9964 | } |
9965 | DBUG_RETURN(0); |
9966 | } |
9967 | |
9968 | /******************************************************************** |
9969 | * Determine whether the current query's projection list |
9970 | * consists solely of the specified column. |
9971 | * |
9972 | * Params IN - field_index: |
9973 | * Field index of the column of interest within |
9974 | * its table. |
9975 | * |
9976 | * Returns TRUE - if the query's projection list consists |
9977 | * solely of the specified column. |
9978 | * FALSE - otherwise. |
9979 | ********************************************************************/ |
9980 | bool spider_oracle_handler::is_sole_projection_field( uint16 field_index ) |
9981 | { |
9982 | // Determine whether the projection list consists solely of the field of interest |
9983 | bool is_field_in_projection_list = FALSE; |
9984 | TABLE* table = spider->get_table(); |
9985 | uint16 projection_field_count = 0; |
9986 | uint16 projection_field_index; |
9987 | Field** field; |
9988 | DBUG_ENTER( "spider_oracle_handler::is_sole_projection_field" ); |
9989 | |
9990 | for ( field = table->field; *field; field++ ) |
9991 | { |
9992 | projection_field_index = ( *field )->field_index; |
9993 | |
9994 | if ( !( minimum_select_bit_is_set( projection_field_index ) ) ) |
9995 | { |
9996 | // Current field is not in the projection list |
9997 | continue; |
9998 | } |
9999 | |
10000 | projection_field_count++; |
10001 | |
10002 | if ( !is_field_in_projection_list ) |
10003 | { |
10004 | if (field_index == projection_field_index) |
10005 | { |
10006 | // Field of interest is in the projection list |
10007 | is_field_in_projection_list = TRUE; |
10008 | } |
10009 | } |
10010 | |
10011 | if ( is_field_in_projection_list && ( projection_field_count != 1 ) ) |
10012 | { |
10013 | // Field of interest is not the sole column in the projection list |
10014 | DBUG_RETURN( FALSE ); |
10015 | } |
10016 | } |
10017 | |
10018 | if ( is_field_in_projection_list && ( projection_field_count == 1 ) ) |
10019 | { |
10020 | // Field of interest is the only column in the projection list |
10021 | DBUG_RETURN( TRUE ); |
10022 | } |
10023 | |
10024 | DBUG_RETURN( FALSE ); |
10025 | } |
10026 | |
10027 | bool spider_oracle_handler::is_bulk_insert_exec_period( |
10028 | bool bulk_end |
10029 | ) { |
10030 | DBUG_ENTER("spider_oracle_handler::is_bulk_insert_exec_period" ); |
10031 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10032 | DBUG_PRINT("info" ,("spider insert_sql.length=%u" , insert_sql.length())); |
10033 | DBUG_PRINT("info" ,("spider insert_pos=%d" , insert_pos)); |
10034 | DBUG_PRINT("info" ,("spider insert_sql=%s" , insert_sql.c_ptr_safe())); |
10035 | if ( |
10036 | /* |
10037 | (bulk_end || (int) insert_sql.length() >= spider->bulk_size) && |
10038 | */ |
10039 | (int) insert_sql.length() > insert_pos |
10040 | ) { |
10041 | DBUG_RETURN(TRUE); |
10042 | } |
10043 | DBUG_RETURN(FALSE); |
10044 | } |
10045 | |
10046 | bool spider_oracle_handler::sql_is_filled_up( |
10047 | ulong sql_type |
10048 | ) { |
10049 | DBUG_ENTER("spider_oracle_handler::sql_is_filled_up" ); |
10050 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10051 | DBUG_RETURN(filled_up); |
10052 | } |
10053 | |
10054 | bool spider_oracle_handler::sql_is_empty( |
10055 | ulong sql_type |
10056 | ) { |
10057 | bool is_empty; |
10058 | DBUG_ENTER("spider_oracle_handler::sql_is_empty" ); |
10059 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10060 | switch (sql_type) |
10061 | { |
10062 | case SPIDER_SQL_TYPE_SELECT_SQL: |
10063 | is_empty = (sql.length() == 0); |
10064 | break; |
10065 | case SPIDER_SQL_TYPE_INSERT_SQL: |
10066 | is_empty = (insert_sql.length() == 0); |
10067 | break; |
10068 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
10069 | case SPIDER_SQL_TYPE_DELETE_SQL: |
10070 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
10071 | is_empty = (update_sql.length() == 0); |
10072 | break; |
10073 | case SPIDER_SQL_TYPE_TMP_SQL: |
10074 | is_empty = (tmp_sql.length() == 0); |
10075 | break; |
10076 | case SPIDER_SQL_TYPE_HANDLER: |
10077 | is_empty = (ha_sql.length() == 0); |
10078 | break; |
10079 | default: |
10080 | is_empty = TRUE; |
10081 | break; |
10082 | } |
10083 | DBUG_RETURN(is_empty); |
10084 | } |
10085 | |
10086 | bool spider_oracle_handler::support_multi_split_read() |
10087 | { |
10088 | DBUG_ENTER("spider_oracle_handler::support_multi_split_read" ); |
10089 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10090 | DBUG_RETURN(FALSE); |
10091 | } |
10092 | |
10093 | bool spider_oracle_handler::support_bulk_update() |
10094 | { |
10095 | DBUG_ENTER("spider_oracle_handler::support_bulk_update" ); |
10096 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10097 | DBUG_RETURN(FALSE); |
10098 | } |
10099 | |
10100 | int spider_oracle_handler::bulk_tmp_table_insert() |
10101 | { |
10102 | int error_num; |
10103 | DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_insert" ); |
10104 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10105 | error_num = store_sql_to_bulk_tmp_table(&update_sql, upd_tmp_tbl); |
10106 | DBUG_RETURN(error_num); |
10107 | } |
10108 | |
10109 | int spider_oracle_handler::bulk_tmp_table_insert( |
10110 | int link_idx |
10111 | ) { |
10112 | int error_num; |
10113 | DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_insert" ); |
10114 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10115 | error_num = store_sql_to_bulk_tmp_table( |
10116 | &spider->result_list.update_sqls[link_idx], |
10117 | spider->result_list.upd_tmp_tbls[link_idx]); |
10118 | DBUG_RETURN(error_num); |
10119 | } |
10120 | |
10121 | int spider_oracle_handler::bulk_tmp_table_end_bulk_insert() |
10122 | { |
10123 | int error_num; |
10124 | DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_end_bulk_insert" ); |
10125 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10126 | if ((error_num = upd_tmp_tbl->file->ha_end_bulk_insert())) |
10127 | { |
10128 | DBUG_RETURN(error_num); |
10129 | } |
10130 | DBUG_RETURN(0); |
10131 | } |
10132 | |
10133 | int spider_oracle_handler::bulk_tmp_table_rnd_init() |
10134 | { |
10135 | int error_num; |
10136 | DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_init" ); |
10137 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10138 | upd_tmp_tbl->file->extra(HA_EXTRA_CACHE); |
10139 | if ((error_num = upd_tmp_tbl->file->ha_rnd_init(TRUE))) |
10140 | { |
10141 | DBUG_RETURN(error_num); |
10142 | } |
10143 | reading_from_bulk_tmp_table = TRUE; |
10144 | DBUG_RETURN(0); |
10145 | } |
10146 | |
10147 | int spider_oracle_handler::bulk_tmp_table_rnd_next() |
10148 | { |
10149 | int error_num; |
10150 | DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_next" ); |
10151 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10152 | #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 |
10153 | error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); |
10154 | #else |
10155 | error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); |
10156 | #endif |
10157 | if (!error_num) |
10158 | { |
10159 | error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); |
10160 | } |
10161 | DBUG_RETURN(error_num); |
10162 | } |
10163 | |
10164 | int spider_oracle_handler::bulk_tmp_table_rnd_end() |
10165 | { |
10166 | int error_num; |
10167 | DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_end" ); |
10168 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10169 | reading_from_bulk_tmp_table = FALSE; |
10170 | if ((error_num = upd_tmp_tbl->file->ha_rnd_end())) |
10171 | { |
10172 | DBUG_RETURN(error_num); |
10173 | } |
10174 | DBUG_RETURN(0); |
10175 | } |
10176 | |
10177 | bool spider_oracle_handler::need_copy_for_update( |
10178 | int link_idx |
10179 | ) { |
10180 | int all_link_idx = spider->conn_link_idx[link_idx]; |
10181 | DBUG_ENTER("spider_oracle_handler::need_copy_for_update" ); |
10182 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10183 | DBUG_RETURN(!oracle_share->same_db_table_name || |
10184 | spider->share->link_statuses[all_link_idx] == SPIDER_LINK_STATUS_RECOVERY); |
10185 | } |
10186 | |
10187 | bool spider_oracle_handler::bulk_tmp_table_created() |
10188 | { |
10189 | DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_created" ); |
10190 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10191 | DBUG_RETURN(upd_tmp_tbl); |
10192 | } |
10193 | |
10194 | int spider_oracle_handler::mk_bulk_tmp_table_and_bulk_start() |
10195 | { |
10196 | THD *thd = spider->trx->thd; |
10197 | TABLE *table = spider->get_table(); |
10198 | DBUG_ENTER("spider_oracle_handler::mk_bulk_tmp_table_and_bulk_start" ); |
10199 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10200 | if (!upd_tmp_tbl) |
10201 | { |
10202 | if (!(upd_tmp_tbl = spider_mk_sys_tmp_table( |
10203 | thd, table, &upd_tmp_tbl_prm, "a" , update_sql.charset()))) |
10204 | { |
10205 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10206 | } |
10207 | upd_tmp_tbl->file->extra(HA_EXTRA_WRITE_CACHE); |
10208 | upd_tmp_tbl->file->ha_start_bulk_insert((ha_rows) 0); |
10209 | } |
10210 | DBUG_RETURN(0); |
10211 | } |
10212 | |
10213 | void spider_oracle_handler::rm_bulk_tmp_table() |
10214 | { |
10215 | DBUG_ENTER("spider_oracle_handler::rm_bulk_tmp_table" ); |
10216 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10217 | if (upd_tmp_tbl) |
10218 | { |
10219 | spider_rm_sys_tmp_table(spider->trx->thd, upd_tmp_tbl, &upd_tmp_tbl_prm); |
10220 | upd_tmp_tbl = NULL; |
10221 | } |
10222 | DBUG_VOID_RETURN; |
10223 | } |
10224 | |
10225 | int spider_oracle_handler::store_sql_to_bulk_tmp_table( |
10226 | spider_string *str, |
10227 | TABLE *tmp_table |
10228 | ) { |
10229 | int error_num; |
10230 | DBUG_ENTER("spider_oracle_handler::store_sql_to_bulk_tmp_table" ); |
10231 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10232 | tmp_table->field[0]->set_notnull(); |
10233 | tmp_table->field[0]->store(str->ptr(), str->length(), str->charset()); |
10234 | if ((error_num = tmp_table->file->ha_write_row(tmp_table->record[0]))) |
10235 | DBUG_RETURN(error_num); |
10236 | DBUG_RETURN(0); |
10237 | } |
10238 | |
10239 | int spider_oracle_handler::restore_sql_from_bulk_tmp_table( |
10240 | spider_string *str, |
10241 | TABLE *tmp_table |
10242 | ) { |
10243 | DBUG_ENTER("spider_oracle_handler::restore_sql_from_bulk_tmp_table" ); |
10244 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10245 | tmp_table->field[0]->val_str(str->get_str()); |
10246 | str->mem_calc(); |
10247 | DBUG_RETURN(0); |
10248 | } |
10249 | |
10250 | int spider_oracle_handler::insert_lock_tables_list( |
10251 | SPIDER_CONN *conn, |
10252 | int link_idx |
10253 | ) { |
10254 | spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; |
10255 | SPIDER_LINK_FOR_HASH *tmp_link_for_hash2 = &link_for_hash[link_idx]; |
10256 | DBUG_ENTER("spider_oracle_handler::insert_lock_tables_list" ); |
10257 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10258 | uint old_elements = |
10259 | db_conn->lock_table_hash.array.max_element; |
10260 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
10261 | if (my_hash_insert_with_hash_value( |
10262 | &db_conn->lock_table_hash, |
10263 | tmp_link_for_hash2->db_table_str_hash_value, |
10264 | (uchar*) tmp_link_for_hash2)) |
10265 | #else |
10266 | if (my_hash_insert(&db_conn->lock_table_hash, |
10267 | (uchar*) tmp_link_for_hash2)) |
10268 | #endif |
10269 | { |
10270 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10271 | } |
10272 | if (db_conn->lock_table_hash.array.max_element > old_elements) |
10273 | { |
10274 | spider_alloc_calc_mem(spider_current_trx, |
10275 | db_conn->lock_table_hash, |
10276 | (db_conn->lock_table_hash.array.max_element - old_elements) * |
10277 | db_conn->lock_table_hash.array.size_of_element); |
10278 | } |
10279 | DBUG_RETURN(0); |
10280 | } |
10281 | |
10282 | int spider_oracle_handler::append_lock_tables_list( |
10283 | SPIDER_CONN *conn, |
10284 | int link_idx, |
10285 | int *appended |
10286 | ) { |
10287 | int error_num; |
10288 | SPIDER_LINK_FOR_HASH *tmp_link_for_hash, *tmp_link_for_hash2; |
10289 | int conn_link_idx = spider->conn_link_idx[link_idx]; |
10290 | spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; |
10291 | DBUG_ENTER("spider_oracle_handler::append_lock_tables_list" ); |
10292 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10293 | tmp_link_for_hash2 = &link_for_hash[link_idx]; |
10294 | tmp_link_for_hash2->db_table_str = |
10295 | &oracle_share->db_table_str[conn_link_idx]; |
10296 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
10297 | tmp_link_for_hash2->db_table_str_hash_value = |
10298 | oracle_share->db_table_str_hash_value[conn_link_idx]; |
10299 | if (!(tmp_link_for_hash = (SPIDER_LINK_FOR_HASH *) |
10300 | my_hash_search_using_hash_value( |
10301 | &db_conn->lock_table_hash, |
10302 | tmp_link_for_hash2->db_table_str_hash_value, |
10303 | (uchar*) tmp_link_for_hash2->db_table_str->ptr(), |
10304 | tmp_link_for_hash2->db_table_str->length()))) |
10305 | #else |
10306 | if (!(tmp_link_for_hash = (SPIDER_LINK_FOR_HASH *) my_hash_search( |
10307 | &db_conn->lock_table_hash, |
10308 | (uchar*) tmp_link_for_hash2->db_table_str->ptr(), |
10309 | tmp_link_for_hash2->db_table_str->length()))) |
10310 | #endif |
10311 | { |
10312 | if ((error_num = insert_lock_tables_list(conn, link_idx))) |
10313 | DBUG_RETURN(error_num); |
10314 | *appended = 1; |
10315 | } else { |
10316 | if (tmp_link_for_hash->spider->lock_type < spider->lock_type) |
10317 | { |
10318 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
10319 | my_hash_delete_with_hash_value( |
10320 | &db_conn->lock_table_hash, |
10321 | tmp_link_for_hash->db_table_str_hash_value, |
10322 | (uchar*) tmp_link_for_hash); |
10323 | #else |
10324 | my_hash_delete(&db_conn->lock_table_hash, |
10325 | (uchar*) tmp_link_for_hash); |
10326 | #endif |
10327 | uint old_elements = |
10328 | db_conn->lock_table_hash.array.max_element; |
10329 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
10330 | if (my_hash_insert_with_hash_value( |
10331 | &db_conn->lock_table_hash, |
10332 | tmp_link_for_hash2->db_table_str_hash_value, |
10333 | (uchar*) tmp_link_for_hash2)) |
10334 | #else |
10335 | if (my_hash_insert(&db_conn->lock_table_hash, |
10336 | (uchar*) tmp_link_for_hash2)) |
10337 | #endif |
10338 | { |
10339 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10340 | } |
10341 | if (db_conn->lock_table_hash.array.max_element > old_elements) |
10342 | { |
10343 | spider_alloc_calc_mem(spider_current_trx, |
10344 | db_conn->lock_table_hash, |
10345 | (db_conn->lock_table_hash.array.max_element - old_elements) * |
10346 | db_conn->lock_table_hash.array.size_of_element); |
10347 | } |
10348 | } |
10349 | } |
10350 | DBUG_RETURN(0); |
10351 | } |
10352 | |
10353 | int spider_oracle_handler::realloc_sql( |
10354 | ulong *realloced |
10355 | ) { |
10356 | THD *thd = spider->trx->thd; |
10357 | st_spider_share *share = spider->share; |
10358 | int init_sql_alloc_size = |
10359 | spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); |
10360 | DBUG_ENTER("spider_oracle_handler::realloc_sql" ); |
10361 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10362 | if ((int) sql.alloced_length() > init_sql_alloc_size * 2) |
10363 | { |
10364 | sql.free(); |
10365 | if (sql.real_alloc(init_sql_alloc_size)) |
10366 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10367 | *realloced |= SPIDER_SQL_TYPE_SELECT_SQL; |
10368 | } |
10369 | if ((int) ha_sql.alloced_length() > init_sql_alloc_size * 2) |
10370 | { |
10371 | ha_sql.free(); |
10372 | if (ha_sql.real_alloc(init_sql_alloc_size)) |
10373 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10374 | *realloced |= SPIDER_SQL_TYPE_SELECT_SQL; |
10375 | } |
10376 | if ((int) dup_update_sql.alloced_length() > init_sql_alloc_size * 2) |
10377 | { |
10378 | dup_update_sql.free(); |
10379 | if (dup_update_sql.real_alloc(init_sql_alloc_size)) |
10380 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10381 | } |
10382 | if ((int) insert_sql.alloced_length() > init_sql_alloc_size * 2) |
10383 | { |
10384 | insert_sql.free(); |
10385 | if (insert_sql.real_alloc(init_sql_alloc_size)) |
10386 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10387 | *realloced |= SPIDER_SQL_TYPE_INSERT_SQL; |
10388 | } |
10389 | if ((int) update_sql.alloced_length() > init_sql_alloc_size * 2) |
10390 | { |
10391 | update_sql.free(); |
10392 | if (update_sql.real_alloc(init_sql_alloc_size)) |
10393 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10394 | *realloced |= (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL); |
10395 | } |
10396 | update_sql.length(0); |
10397 | if ((int) tmp_sql.alloced_length() > init_sql_alloc_size * 2) |
10398 | { |
10399 | tmp_sql.free(); |
10400 | if (tmp_sql.real_alloc(init_sql_alloc_size)) |
10401 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10402 | *realloced |= SPIDER_SQL_TYPE_TMP_SQL; |
10403 | } |
10404 | DBUG_RETURN(0); |
10405 | } |
10406 | |
10407 | int spider_oracle_handler::reset_sql( |
10408 | ulong sql_type |
10409 | ) { |
10410 | DBUG_ENTER("spider_oracle_handler::reset_sql" ); |
10411 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10412 | if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) |
10413 | { |
10414 | table_lock_mode = 0; |
10415 | select_rownum_appended = FALSE; |
10416 | sql.length(0); |
10417 | } |
10418 | if (sql_type & SPIDER_SQL_TYPE_INSERT_SQL) |
10419 | { |
10420 | insert_sql.length(0); |
10421 | } |
10422 | if (sql_type & (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL | |
10423 | SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) |
10424 | { |
10425 | update_rownum_appended = FALSE; |
10426 | update_set_pos = 0; |
10427 | update_sql.length(0); |
10428 | } |
10429 | if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) |
10430 | { |
10431 | tmp_sql.length(0); |
10432 | } |
10433 | if (sql_type & SPIDER_SQL_TYPE_HANDLER) |
10434 | { |
10435 | ha_sql.length(0); |
10436 | } |
10437 | DBUG_RETURN(0); |
10438 | } |
10439 | |
10440 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
10441 | int spider_oracle_handler::reset_keys( |
10442 | ulong sql_type |
10443 | ) { |
10444 | DBUG_ENTER("spider_oracle_handler::reset_keys" ); |
10445 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10446 | DBUG_ASSERT(0); |
10447 | DBUG_RETURN(0); |
10448 | } |
10449 | |
10450 | int spider_oracle_handler::reset_upds( |
10451 | ulong sql_type |
10452 | ) { |
10453 | DBUG_ENTER("spider_oracle_handler::reset_upds" ); |
10454 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10455 | hs_upds.clear(); |
10456 | DBUG_RETURN(0); |
10457 | } |
10458 | |
10459 | int spider_oracle_handler::reset_strs( |
10460 | ulong sql_type |
10461 | ) { |
10462 | DBUG_ENTER("spider_oracle_handler::reset_strs" ); |
10463 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10464 | DBUG_ASSERT(0); |
10465 | DBUG_RETURN(0); |
10466 | } |
10467 | |
10468 | int spider_oracle_handler::reset_strs_pos( |
10469 | ulong sql_type |
10470 | ) { |
10471 | DBUG_ENTER("spider_oracle_handler::reset_strs_pos" ); |
10472 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10473 | DBUG_ASSERT(0); |
10474 | DBUG_RETURN(0); |
10475 | } |
10476 | |
10477 | int spider_oracle_handler::push_back_upds( |
10478 | SPIDER_HS_STRING_REF &info |
10479 | ) { |
10480 | int error_num; |
10481 | DBUG_ENTER("spider_oracle_handler::push_back_upds" ); |
10482 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10483 | error_num = hs_upds.push_back(info); |
10484 | DBUG_RETURN(error_num); |
10485 | } |
10486 | #endif |
10487 | |
10488 | bool spider_oracle_handler::need_lock_before_set_sql_for_exec( |
10489 | ulong sql_type |
10490 | ) { |
10491 | DBUG_ENTER("spider_oracle_handler::need_lock_before_set_sql_for_exec" ); |
10492 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10493 | DBUG_RETURN(FALSE); |
10494 | } |
10495 | |
10496 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
10497 | int spider_oracle_handler::set_sql_for_exec( |
10498 | ulong sql_type, |
10499 | int link_idx, |
10500 | SPIDER_LINK_IDX_CHAIN *link_idx_chain |
10501 | ) { |
10502 | int error_num; |
10503 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
10504 | int all_link_idx = spider->conn_link_idx[link_idx]; |
10505 | DBUG_ENTER("spider_oracle_handler::set_sql_for_exec" ); |
10506 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10507 | if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) |
10508 | { |
10509 | if (table_lock_mode) |
10510 | { |
10511 | spider_string *str = &result_list->insert_sqls[link_idx]; |
10512 | str->length(0); |
10513 | if (str->reserve(SPIDER_SQL_LOCK_TABLE_LEN)) |
10514 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10515 | str->q_append(SPIDER_SQL_LOCK_TABLE_STR, SPIDER_SQL_LOCK_TABLE_LEN); |
10516 | if ((error_num = oracle_share->append_table_name(str, all_link_idx))) |
10517 | DBUG_RETURN(error_num); |
10518 | if (table_lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) |
10519 | { |
10520 | if (str->reserve(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN)) |
10521 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10522 | str->q_append(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR, |
10523 | SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN); |
10524 | } else if (table_lock_mode == SPIDER_LOCK_MODE_SHARED) |
10525 | { |
10526 | if (str->reserve(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN)) |
10527 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10528 | str->q_append(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR, |
10529 | SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN); |
10530 | } |
10531 | exec_lock_sql = str; |
10532 | } |
10533 | |
10534 | if ((error_num = spider_db_oracle_utility.reappend_tables( |
10535 | spider->fields, link_idx_chain, &sql))) |
10536 | DBUG_RETURN(error_num); |
10537 | exec_sql = &sql; |
10538 | } |
10539 | DBUG_RETURN(0); |
10540 | } |
10541 | #endif |
10542 | |
10543 | int spider_oracle_handler::set_sql_for_exec( |
10544 | ulong sql_type, |
10545 | int link_idx |
10546 | ) { |
10547 | int error_num; |
10548 | uint tmp_pos; |
10549 | SPIDER_SHARE *share = spider->share; |
10550 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
10551 | int all_link_idx = spider->conn_link_idx[link_idx]; |
10552 | DBUG_ENTER("spider_oracle_handler::set_sql_for_exec" ); |
10553 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10554 | if (sql_type & (SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL)) |
10555 | { |
10556 | if (table_lock_mode) |
10557 | { |
10558 | spider_string *str = &result_list->insert_sqls[link_idx]; |
10559 | str->length(0); |
10560 | if (str->reserve(SPIDER_SQL_LOCK_TABLE_LEN)) |
10561 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10562 | str->q_append(SPIDER_SQL_LOCK_TABLE_STR, SPIDER_SQL_LOCK_TABLE_LEN); |
10563 | if ((error_num = oracle_share->append_table_name(str, all_link_idx))) |
10564 | DBUG_RETURN(error_num); |
10565 | if (table_lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) |
10566 | { |
10567 | if (str->reserve(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN)) |
10568 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10569 | str->q_append(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR, |
10570 | SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN); |
10571 | } else if (table_lock_mode == SPIDER_LOCK_MODE_SHARED) |
10572 | { |
10573 | if (str->reserve(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN)) |
10574 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10575 | str->q_append(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR, |
10576 | SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN); |
10577 | } |
10578 | exec_lock_sql = str; |
10579 | } |
10580 | |
10581 | if (oracle_share->same_db_table_name || link_idx == first_link_idx) |
10582 | { |
10583 | if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) |
10584 | exec_sql = &sql; |
10585 | if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) |
10586 | exec_tmp_sql = &tmp_sql; |
10587 | } else { |
10588 | char tmp_table_name[MAX_FIELD_WIDTH * 2], |
10589 | tgt_table_name[MAX_FIELD_WIDTH * 2]; |
10590 | int tmp_table_name_length; |
10591 | spider_string tgt_table_name_str(tgt_table_name, |
10592 | MAX_FIELD_WIDTH * 2, |
10593 | oracle_share->db_names_str[link_idx].charset()); |
10594 | const char *table_names[2], *table_aliases[2]; |
10595 | uint table_name_lengths[2], table_alias_lengths[2]; |
10596 | tgt_table_name_str.init_calc_mem(212); |
10597 | tgt_table_name_str.length(0); |
10598 | if (result_list->tmp_table_join && spider->bka_mode != 2) |
10599 | { |
10600 | create_tmp_bka_table_name(tmp_table_name, &tmp_table_name_length, |
10601 | link_idx); |
10602 | append_table_name_with_adjusting(&tgt_table_name_str, link_idx, |
10603 | SPIDER_SQL_TYPE_TMP_SQL); |
10604 | table_names[0] = tmp_table_name; |
10605 | table_names[1] = tgt_table_name_str.ptr(); |
10606 | table_name_lengths[0] = tmp_table_name_length; |
10607 | table_name_lengths[1] = tgt_table_name_str.length(); |
10608 | table_aliases[0] = SPIDER_SQL_A_STR; |
10609 | table_aliases[1] = SPIDER_SQL_B_STR; |
10610 | table_alias_lengths[0] = SPIDER_SQL_A_LEN; |
10611 | table_alias_lengths[1] = SPIDER_SQL_B_LEN; |
10612 | } |
10613 | if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) |
10614 | { |
10615 | exec_sql = &result_list->sqls[link_idx]; |
10616 | if (exec_sql->copy(sql)) |
10617 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10618 | else if (result_list->use_union) |
10619 | { |
10620 | if ((error_num = reset_union_table_name(exec_sql, link_idx, |
10621 | SPIDER_SQL_TYPE_SELECT_SQL))) |
10622 | DBUG_RETURN(error_num); |
10623 | } else { |
10624 | tmp_pos = exec_sql->length(); |
10625 | exec_sql->length(table_name_pos); |
10626 | if (result_list->tmp_table_join && spider->bka_mode != 2) |
10627 | { |
10628 | if ((error_num = spider_db_oracle_utility.append_from_with_alias( |
10629 | exec_sql, table_names, table_name_lengths, |
10630 | table_aliases, table_alias_lengths, 2, |
10631 | &table_name_pos, TRUE)) |
10632 | ) |
10633 | DBUG_RETURN(error_num); |
10634 | exec_sql->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
10635 | } else { |
10636 | append_table_name_with_adjusting(exec_sql, link_idx, |
10637 | SPIDER_SQL_TYPE_SELECT_SQL); |
10638 | } |
10639 | exec_sql->length(tmp_pos); |
10640 | } |
10641 | } |
10642 | if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) |
10643 | { |
10644 | exec_tmp_sql = &result_list->tmp_sqls[link_idx]; |
10645 | if (result_list->tmp_table_join && spider->bka_mode != 2) |
10646 | { |
10647 | if (exec_tmp_sql->copy(tmp_sql)) |
10648 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10649 | else { |
10650 | tmp_pos = exec_tmp_sql->length(); |
10651 | exec_tmp_sql->length(tmp_sql_pos1); |
10652 | exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); |
10653 | exec_tmp_sql->length(tmp_sql_pos2); |
10654 | exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); |
10655 | exec_tmp_sql->length(tmp_sql_pos3); |
10656 | exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); |
10657 | exec_tmp_sql->length(tmp_pos); |
10658 | } |
10659 | } |
10660 | } |
10661 | } |
10662 | } |
10663 | if (sql_type & SPIDER_SQL_TYPE_INSERT_SQL) |
10664 | { |
10665 | if (oracle_share->same_db_table_name || link_idx == first_link_idx) |
10666 | exec_insert_sql = &insert_sql; |
10667 | else { |
10668 | exec_insert_sql = &result_list->insert_sqls[link_idx]; |
10669 | if (exec_insert_sql->copy(insert_sql)) |
10670 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10671 | DBUG_PRINT("info" ,("spider exec_insert_sql=%s" , |
10672 | exec_insert_sql->c_ptr_safe())); |
10673 | tmp_pos = exec_insert_sql->length(); |
10674 | exec_insert_sql->length(insert_table_name_pos); |
10675 | append_table_name_with_adjusting(exec_insert_sql, link_idx, |
10676 | sql_type); |
10677 | exec_insert_sql->length(tmp_pos); |
10678 | DBUG_PRINT("info" ,("spider exec_insert_sql->length=%u" , |
10679 | exec_insert_sql->length())); |
10680 | DBUG_PRINT("info" ,("spider exec_insert_sql=%s" , |
10681 | exec_insert_sql->c_ptr_safe())); |
10682 | } |
10683 | if (nextval_pos) |
10684 | { |
10685 | memcpy((uchar *) exec_insert_sql->ptr() + nextval_pos, |
10686 | oracle_share->nextval_str[all_link_idx].ptr(), |
10687 | oracle_share->nextval_max_length); |
10688 | } |
10689 | } |
10690 | if (sql_type & SPIDER_SQL_TYPE_BULK_UPDATE_SQL) |
10691 | { |
10692 | if (reading_from_bulk_tmp_table) |
10693 | { |
10694 | if ( |
10695 | oracle_share->same_db_table_name && |
10696 | share->link_statuses[all_link_idx] != SPIDER_LINK_STATUS_RECOVERY |
10697 | ) { |
10698 | exec_update_sql = &insert_sql; |
10699 | } else if (!spider->result_list.upd_tmp_tbls[link_idx]) |
10700 | { |
10701 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
10702 | } else { |
10703 | exec_update_sql = &spider->result_list.insert_sqls[link_idx]; |
10704 | if ((error_num = restore_sql_from_bulk_tmp_table(exec_update_sql, |
10705 | spider->result_list.upd_tmp_tbls[link_idx]))) |
10706 | { |
10707 | DBUG_RETURN(error_num); |
10708 | } |
10709 | } |
10710 | } else { |
10711 | if ( |
10712 | oracle_share->same_db_table_name && |
10713 | share->link_statuses[all_link_idx] != SPIDER_LINK_STATUS_RECOVERY |
10714 | ) { |
10715 | exec_update_sql = &update_sql; |
10716 | } else { |
10717 | exec_update_sql = &spider->result_list.update_sqls[link_idx]; |
10718 | } |
10719 | } |
10720 | DBUG_PRINT("info" ,("spider exec_update_sql=%s" , |
10721 | exec_update_sql->c_ptr_safe())); |
10722 | } else if (sql_type & |
10723 | (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL)) |
10724 | { |
10725 | if (oracle_share->same_db_table_name || link_idx == first_link_idx) |
10726 | exec_update_sql = &update_sql; |
10727 | else { |
10728 | exec_update_sql = &spider->result_list.update_sqls[link_idx]; |
10729 | if (exec_update_sql->copy(update_sql)) |
10730 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10731 | tmp_pos = exec_update_sql->length(); |
10732 | exec_update_sql->length(table_name_pos); |
10733 | append_table_name_with_adjusting(exec_update_sql, link_idx, |
10734 | sql_type); |
10735 | exec_update_sql->length(tmp_pos); |
10736 | } |
10737 | DBUG_PRINT("info" ,("spider exec_update_sql=%s" , |
10738 | exec_update_sql->c_ptr_safe())); |
10739 | } |
10740 | if (sql_type & SPIDER_SQL_TYPE_HANDLER) |
10741 | { |
10742 | if (spider->m_handler_id[link_idx] == ha_sql_handler_id) |
10743 | exec_ha_sql = &ha_sql; |
10744 | else { |
10745 | exec_ha_sql = &result_list->sqls[link_idx]; |
10746 | if (exec_ha_sql->copy(ha_sql)) |
10747 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
10748 | else { |
10749 | tmp_pos = exec_ha_sql->length(); |
10750 | exec_ha_sql->length(ha_table_name_pos); |
10751 | append_table_name_with_adjusting(exec_ha_sql, link_idx, |
10752 | SPIDER_SQL_TYPE_HANDLER); |
10753 | exec_ha_sql->length(tmp_pos); |
10754 | } |
10755 | } |
10756 | DBUG_PRINT("info" ,("spider exec_ha_sql=%s" , |
10757 | exec_ha_sql->c_ptr_safe())); |
10758 | } |
10759 | DBUG_RETURN(0); |
10760 | } |
10761 | |
10762 | int spider_oracle_handler::set_sql_for_exec( |
10763 | spider_db_copy_table *tgt_ct, |
10764 | ulong sql_type |
10765 | ) { |
10766 | spider_oracle_copy_table *oracle_ct = (spider_oracle_copy_table *) tgt_ct; |
10767 | DBUG_ENTER("spider_oracle_handler::set_sql_for_exec" ); |
10768 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10769 | switch (sql_type) |
10770 | { |
10771 | case SPIDER_SQL_TYPE_INSERT_SQL: |
10772 | exec_insert_sql = &oracle_ct->sql; |
10773 | break; |
10774 | default: |
10775 | DBUG_ASSERT(0); |
10776 | break; |
10777 | } |
10778 | DBUG_RETURN(0); |
10779 | } |
10780 | |
10781 | int spider_oracle_handler::execute_sql( |
10782 | ulong sql_type, |
10783 | SPIDER_CONN *conn, |
10784 | int quick_mode, |
10785 | int *need_mon |
10786 | ) { |
10787 | spider_string *tgt_sql; |
10788 | uint tgt_length; |
10789 | DBUG_ENTER("spider_oracle_handler::execute_sql" ); |
10790 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10791 | switch (sql_type) |
10792 | { |
10793 | case SPIDER_SQL_TYPE_SELECT_SQL: |
10794 | DBUG_PRINT("info" ,("spider SPIDER_SQL_TYPE_SELECT_SQL" )); |
10795 | tgt_sql = exec_sql; |
10796 | tgt_length = tgt_sql->length(); |
10797 | if (table_lock_mode) |
10798 | { |
10799 | DBUG_PRINT("info" ,("spider table_lock_mode=%d" , table_lock_mode)); |
10800 | spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; |
10801 | db_conn->table_lock_mode = table_lock_mode; |
10802 | db_conn->exec_lock_sql = exec_lock_sql; |
10803 | table_lock_mode = 0; |
10804 | } |
10805 | break; |
10806 | case SPIDER_SQL_TYPE_INSERT_SQL: |
10807 | DBUG_PRINT("info" ,("spider SPIDER_SQL_TYPE_SELECT_SQL" )); |
10808 | tgt_sql = exec_insert_sql; |
10809 | tgt_length = tgt_sql->length(); |
10810 | break; |
10811 | case SPIDER_SQL_TYPE_UPDATE_SQL: |
10812 | case SPIDER_SQL_TYPE_DELETE_SQL: |
10813 | case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: |
10814 | DBUG_PRINT("info" ,("spider %s" , |
10815 | sql_type == SPIDER_SQL_TYPE_UPDATE_SQL ? "SPIDER_SQL_TYPE_UPDATE_SQL" : |
10816 | sql_type == SPIDER_SQL_TYPE_DELETE_SQL ? "SPIDER_SQL_TYPE_DELETE_SQL" : |
10817 | "SPIDER_SQL_TYPE_BULK_UPDATE_SQL" |
10818 | )); |
10819 | tgt_sql = exec_update_sql; |
10820 | tgt_length = tgt_sql->length(); |
10821 | break; |
10822 | case SPIDER_SQL_TYPE_TMP_SQL: |
10823 | DBUG_PRINT("info" ,("spider SPIDER_SQL_TYPE_TMP_SQL" )); |
10824 | tgt_sql = exec_tmp_sql; |
10825 | tgt_length = tgt_sql->length(); |
10826 | break; |
10827 | case SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL: |
10828 | DBUG_PRINT("info" ,("spider SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL" )); |
10829 | tgt_sql = exec_tmp_sql; |
10830 | tgt_length = tmp_sql_pos5; |
10831 | break; |
10832 | case SPIDER_SQL_TYPE_HANDLER: |
10833 | DBUG_PRINT("info" ,("spider SPIDER_SQL_TYPE_HANDLER" )); |
10834 | tgt_sql = exec_ha_sql; |
10835 | tgt_length = tgt_sql->length(); |
10836 | break; |
10837 | default: |
10838 | /* nothing to do */ |
10839 | DBUG_PRINT("info" ,("spider default" )); |
10840 | DBUG_RETURN(0); |
10841 | } |
10842 | DBUG_RETURN(spider_db_query( |
10843 | conn, |
10844 | tgt_sql->ptr(), |
10845 | tgt_length, |
10846 | quick_mode, |
10847 | need_mon |
10848 | )); |
10849 | } |
10850 | |
10851 | int spider_oracle_handler::reset() |
10852 | { |
10853 | DBUG_ENTER("spider_oracle_handler::reset" ); |
10854 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
10855 | update_sql.length(0); |
10856 | DBUG_RETURN(0); |
10857 | } |
10858 | |
10859 | int spider_oracle_handler::sts_mode_exchange( |
10860 | int sts_mode |
10861 | ) { |
10862 | DBUG_ENTER("spider_oracle_handler::sts_mode_exchange" ); |
10863 | DBUG_PRINT("info" ,("spider sts_mode=%d" , sts_mode)); |
10864 | DBUG_RETURN(1); |
10865 | } |
10866 | |
10867 | int spider_oracle_handler::show_table_status( |
10868 | int link_idx, |
10869 | int sts_mode, |
10870 | uint flag |
10871 | ) { |
10872 | int error_num; |
10873 | SPIDER_CONN *conn = spider->conns[link_idx]; |
10874 | SPIDER_DB_RESULT *res; |
10875 | SPIDER_SHARE *share = spider->share; |
10876 | uint pos = (2 * spider->conn_link_idx[link_idx]); |
10877 | ulonglong auto_increment_value = 0; |
10878 | DBUG_ENTER("spider_oracle_handler::show_table_status" ); |
10879 | DBUG_PRINT("info" ,("spider sts_mode=%d" , sts_mode)); |
10880 | if ( |
10881 | (flag & HA_STATUS_AUTO) && |
10882 | (error_num = show_autoinc(link_idx)) |
10883 | ) { |
10884 | DBUG_RETURN(error_num); |
10885 | } |
10886 | |
10887 | if (sts_mode == 1) |
10888 | { |
10889 | /* |
10890 | pthread_mutex_lock(&conn->mta_conn_mutex); |
10891 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
10892 | conn->need_mon = &spider->need_mons[link_idx]; |
10893 | conn->mta_conn_mutex_lock_already = TRUE; |
10894 | conn->mta_conn_mutex_unlock_later = TRUE; |
10895 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
10896 | share); |
10897 | if ( |
10898 | (error_num = spider_db_set_names(spider, conn, link_idx)) || |
10899 | ( |
10900 | spider_db_query( |
10901 | conn, |
10902 | oracle_share->show_table_status[0 + pos].ptr(), |
10903 | oracle_share->show_table_status[0 + pos].length(), |
10904 | -1, |
10905 | &spider->need_mons[link_idx]) && |
10906 | (error_num = spider_db_errorno(conn)) |
10907 | ) |
10908 | ) { |
10909 | if ( |
10910 | error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && |
10911 | !conn->disable_reconnect |
10912 | ) { |
10913 | */ |
10914 | /* retry */ |
10915 | /* |
10916 | if ((error_num = spider_db_ping(spider, conn, link_idx))) |
10917 | { |
10918 | conn->mta_conn_mutex_lock_already = FALSE; |
10919 | conn->mta_conn_mutex_unlock_later = FALSE; |
10920 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
10921 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
10922 | DBUG_RETURN(error_num); |
10923 | } |
10924 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
10925 | { |
10926 | conn->mta_conn_mutex_lock_already = FALSE; |
10927 | conn->mta_conn_mutex_unlock_later = FALSE; |
10928 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
10929 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
10930 | DBUG_RETURN(error_num); |
10931 | } |
10932 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
10933 | share); |
10934 | if (spider_db_query( |
10935 | conn, |
10936 | oracle_share->show_table_status[0 + pos].ptr(), |
10937 | oracle_share->show_table_status[0 + pos].length(), |
10938 | -1, |
10939 | &spider->need_mons[link_idx]) |
10940 | ) { |
10941 | conn->mta_conn_mutex_lock_already = FALSE; |
10942 | conn->mta_conn_mutex_unlock_later = FALSE; |
10943 | DBUG_RETURN(spider_db_errorno(conn)); |
10944 | } |
10945 | } else { |
10946 | conn->mta_conn_mutex_lock_already = FALSE; |
10947 | conn->mta_conn_mutex_unlock_later = FALSE; |
10948 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
10949 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
10950 | DBUG_RETURN(error_num); |
10951 | } |
10952 | } |
10953 | st_spider_db_request_key request_key; |
10954 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
10955 | request_key.query_id = spider->trx->thd->query_id; |
10956 | request_key.handler = spider; |
10957 | request_key.request_id = 1; |
10958 | request_key.next = NULL; |
10959 | if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) |
10960 | { |
10961 | conn->mta_conn_mutex_lock_already = FALSE; |
10962 | conn->mta_conn_mutex_unlock_later = FALSE; |
10963 | if (error_num || (error_num = spider_db_errorno(conn))) |
10964 | DBUG_RETURN(error_num); |
10965 | else { |
10966 | my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, |
10967 | ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), |
10968 | oracle_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), |
10969 | oracle_share->table_names_str[spider->conn_link_idx[ |
10970 | link_idx]].ptr()); |
10971 | DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); |
10972 | } |
10973 | } |
10974 | conn->mta_conn_mutex_lock_already = FALSE; |
10975 | conn->mta_conn_mutex_unlock_later = FALSE; |
10976 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
10977 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
10978 | error_num = res->fetch_table_status( |
10979 | sts_mode, |
10980 | share->records, |
10981 | share->mean_rec_length, |
10982 | share->data_file_length, |
10983 | share->max_data_file_length, |
10984 | share->index_file_length, |
10985 | auto_increment_value, |
10986 | share->create_time, |
10987 | share->update_time, |
10988 | share->check_time |
10989 | ); |
10990 | res->free_result(); |
10991 | delete res; |
10992 | if (error_num) |
10993 | DBUG_RETURN(error_num); |
10994 | */ |
10995 | if (!share->records) |
10996 | share->records = 10000; |
10997 | share->mean_rec_length = 65535; |
10998 | share->data_file_length = 65535; |
10999 | share->max_data_file_length = 65535; |
11000 | share->index_file_length = 65535; |
11001 | share->create_time = (time_t) 0; |
11002 | share->update_time = (time_t) 0; |
11003 | share->check_time = (time_t) 0; |
11004 | } else { |
11005 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11006 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11007 | conn->need_mon = &spider->need_mons[link_idx]; |
11008 | conn->mta_conn_mutex_lock_already = TRUE; |
11009 | conn->mta_conn_mutex_unlock_later = TRUE; |
11010 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11011 | share); |
11012 | if ( |
11013 | (error_num = spider_db_set_names(spider, conn, link_idx)) || |
11014 | ( |
11015 | spider_db_query( |
11016 | conn, |
11017 | oracle_share->show_table_status[1 + pos].ptr(), |
11018 | oracle_share->show_table_status[1 + pos].length(), |
11019 | -1, |
11020 | &spider->need_mons[link_idx]) && |
11021 | (error_num = spider_db_errorno(conn)) |
11022 | ) |
11023 | ) { |
11024 | if ( |
11025 | error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && |
11026 | !conn->disable_reconnect |
11027 | ) { |
11028 | /* retry */ |
11029 | if ((error_num = spider_db_ping(spider, conn, link_idx))) |
11030 | { |
11031 | conn->mta_conn_mutex_lock_already = FALSE; |
11032 | conn->mta_conn_mutex_unlock_later = FALSE; |
11033 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11034 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11035 | DBUG_RETURN(error_num); |
11036 | } |
11037 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11038 | { |
11039 | conn->mta_conn_mutex_lock_already = FALSE; |
11040 | conn->mta_conn_mutex_unlock_later = FALSE; |
11041 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11042 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11043 | DBUG_RETURN(error_num); |
11044 | } |
11045 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11046 | share); |
11047 | if (spider_db_query( |
11048 | conn, |
11049 | oracle_share->show_table_status[1 + pos].ptr(), |
11050 | oracle_share->show_table_status[1 + pos].length(), |
11051 | -1, |
11052 | &spider->need_mons[link_idx]) |
11053 | ) { |
11054 | conn->mta_conn_mutex_lock_already = FALSE; |
11055 | conn->mta_conn_mutex_unlock_later = FALSE; |
11056 | DBUG_RETURN(spider_db_errorno(conn)); |
11057 | } |
11058 | } else { |
11059 | conn->mta_conn_mutex_lock_already = FALSE; |
11060 | conn->mta_conn_mutex_unlock_later = FALSE; |
11061 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11062 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11063 | DBUG_RETURN(error_num); |
11064 | } |
11065 | } |
11066 | st_spider_db_request_key request_key; |
11067 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
11068 | request_key.query_id = spider->trx->thd->query_id; |
11069 | request_key.handler = spider; |
11070 | request_key.request_id = 1; |
11071 | request_key.next = NULL; |
11072 | if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) |
11073 | { |
11074 | conn->mta_conn_mutex_lock_already = FALSE; |
11075 | conn->mta_conn_mutex_unlock_later = FALSE; |
11076 | if (error_num || (error_num = spider_db_errorno(conn))) |
11077 | DBUG_RETURN(error_num); |
11078 | else |
11079 | DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); |
11080 | } |
11081 | conn->mta_conn_mutex_lock_already = FALSE; |
11082 | conn->mta_conn_mutex_unlock_later = FALSE; |
11083 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11084 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11085 | error_num = res->fetch_table_status( |
11086 | sts_mode, |
11087 | share->records, |
11088 | share->mean_rec_length, |
11089 | share->data_file_length, |
11090 | share->max_data_file_length, |
11091 | share->index_file_length, |
11092 | auto_increment_value, |
11093 | share->create_time, |
11094 | share->update_time, |
11095 | share->check_time |
11096 | ); |
11097 | res->free_result(); |
11098 | delete res; |
11099 | if (error_num) |
11100 | DBUG_RETURN(error_num); |
11101 | } |
11102 | if (auto_increment_value > share->lgtm_tblhnd_share->auto_increment_value) |
11103 | { |
11104 | share->lgtm_tblhnd_share->auto_increment_value = auto_increment_value; |
11105 | DBUG_PRINT("info" ,("spider auto_increment_value=%llu" , |
11106 | share->lgtm_tblhnd_share->auto_increment_value)); |
11107 | } |
11108 | DBUG_RETURN(0); |
11109 | } |
11110 | |
11111 | int spider_oracle_handler::crd_mode_exchange( |
11112 | int crd_mode |
11113 | ) { |
11114 | DBUG_ENTER("spider_oracle_handler::crd_mode_exchange" ); |
11115 | DBUG_PRINT("info" ,("spider crd_mode=%d" , crd_mode)); |
11116 | DBUG_RETURN(1); |
11117 | } |
11118 | |
11119 | int spider_oracle_handler::show_index( |
11120 | int link_idx, |
11121 | int crd_mode |
11122 | ) { |
11123 | int error_num; |
11124 | SPIDER_CONN *conn = spider->conns[link_idx]; |
11125 | SPIDER_SHARE *share = spider->share; |
11126 | TABLE *table = spider->get_table(); |
11127 | SPIDER_DB_RESULT *res; |
11128 | int roop_count; |
11129 | longlong *tmp_cardinality; |
11130 | uint pos = (2 * spider->conn_link_idx[link_idx]); |
11131 | DBUG_ENTER("spider_oracle_handler::show_index" ); |
11132 | DBUG_PRINT("info" ,("spider crd_mode=%d" , crd_mode)); |
11133 | if (crd_mode == 1) |
11134 | { |
11135 | /* |
11136 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11137 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11138 | conn->need_mon = &spider->need_mons[link_idx]; |
11139 | conn->mta_conn_mutex_lock_already = TRUE; |
11140 | conn->mta_conn_mutex_unlock_later = TRUE; |
11141 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11142 | share); |
11143 | if ( |
11144 | (error_num = spider_db_set_names(spider, conn, link_idx)) || |
11145 | ( |
11146 | spider_db_query( |
11147 | conn, |
11148 | oracle_share->show_index[0 + pos].ptr(), |
11149 | oracle_share->show_index[0 + pos].length(), |
11150 | -1, |
11151 | &spider->need_mons[link_idx]) && |
11152 | (error_num = spider_db_errorno(conn)) |
11153 | ) |
11154 | ) { |
11155 | if ( |
11156 | error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && |
11157 | !conn->disable_reconnect |
11158 | ) { |
11159 | */ |
11160 | /* retry */ |
11161 | /* |
11162 | if ((error_num = spider_db_ping(spider, conn, link_idx))) |
11163 | { |
11164 | conn->mta_conn_mutex_lock_already = FALSE; |
11165 | conn->mta_conn_mutex_unlock_later = FALSE; |
11166 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11167 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11168 | DBUG_RETURN(error_num); |
11169 | } |
11170 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11171 | { |
11172 | conn->mta_conn_mutex_lock_already = FALSE; |
11173 | conn->mta_conn_mutex_unlock_later = FALSE; |
11174 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11175 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11176 | DBUG_RETURN(error_num); |
11177 | } |
11178 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11179 | share); |
11180 | if (spider_db_query( |
11181 | conn, |
11182 | oracle_share->show_index[0 + pos].ptr(), |
11183 | oracle_share->show_index[0 + pos].length(), |
11184 | -1, |
11185 | &spider->need_mons[link_idx]) |
11186 | ) { |
11187 | conn->mta_conn_mutex_lock_already = FALSE; |
11188 | conn->mta_conn_mutex_unlock_later = FALSE; |
11189 | DBUG_RETURN(spider_db_errorno(conn)); |
11190 | } |
11191 | } else { |
11192 | conn->mta_conn_mutex_lock_already = FALSE; |
11193 | conn->mta_conn_mutex_unlock_later = FALSE; |
11194 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11195 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11196 | DBUG_RETURN(error_num); |
11197 | } |
11198 | } |
11199 | st_spider_db_request_key request_key; |
11200 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
11201 | request_key.query_id = spider->trx->thd->query_id; |
11202 | request_key.handler = spider; |
11203 | request_key.request_id = 1; |
11204 | request_key.next = NULL; |
11205 | if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) |
11206 | { |
11207 | if (error_num || (error_num = spider_db_errorno(conn))) |
11208 | { |
11209 | conn->mta_conn_mutex_lock_already = FALSE; |
11210 | conn->mta_conn_mutex_unlock_later = FALSE; |
11211 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11212 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11213 | DBUG_RETURN(error_num); |
11214 | } |
11215 | */ |
11216 | /* no record is ok */ |
11217 | /* |
11218 | } |
11219 | conn->mta_conn_mutex_lock_already = FALSE; |
11220 | conn->mta_conn_mutex_unlock_later = FALSE; |
11221 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11222 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11223 | if (res) |
11224 | { |
11225 | error_num = res->fetch_table_cardinality( |
11226 | crd_mode, |
11227 | table, |
11228 | share->cardinality, |
11229 | share->cardinality_upd, |
11230 | share->bitmap_size |
11231 | ); |
11232 | } |
11233 | */ |
11234 | for (roop_count = 0, tmp_cardinality = share->cardinality; |
11235 | roop_count < (int) table->s->fields; |
11236 | roop_count++, tmp_cardinality++) |
11237 | { |
11238 | if (!spider_bit_is_set(share->cardinality_upd, roop_count)) |
11239 | { |
11240 | DBUG_PRINT("info" , |
11241 | ("spider init column cardinality id=%d" , roop_count)); |
11242 | *tmp_cardinality = 1; |
11243 | } |
11244 | } |
11245 | /* |
11246 | if (res) |
11247 | { |
11248 | res->free_result(); |
11249 | delete res; |
11250 | } |
11251 | if (error_num) |
11252 | DBUG_RETURN(error_num); |
11253 | */ |
11254 | } else { |
11255 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11256 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11257 | conn->need_mon = &spider->need_mons[link_idx]; |
11258 | conn->mta_conn_mutex_lock_already = TRUE; |
11259 | conn->mta_conn_mutex_unlock_later = TRUE; |
11260 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11261 | share); |
11262 | if ( |
11263 | (error_num = spider_db_set_names(spider, conn, link_idx)) || |
11264 | ( |
11265 | spider_db_query( |
11266 | conn, |
11267 | oracle_share->show_index[1 + pos].ptr(), |
11268 | oracle_share->show_index[1 + pos].length(), |
11269 | -1, |
11270 | &spider->need_mons[link_idx]) && |
11271 | (error_num = spider_db_errorno(conn)) |
11272 | ) |
11273 | ) { |
11274 | if ( |
11275 | error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && |
11276 | !conn->disable_reconnect |
11277 | ) { |
11278 | /* retry */ |
11279 | if ((error_num = spider_db_ping(spider, conn, link_idx))) |
11280 | { |
11281 | conn->mta_conn_mutex_lock_already = FALSE; |
11282 | conn->mta_conn_mutex_unlock_later = FALSE; |
11283 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11284 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11285 | DBUG_RETURN(error_num); |
11286 | } |
11287 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11288 | { |
11289 | conn->mta_conn_mutex_lock_already = FALSE; |
11290 | conn->mta_conn_mutex_unlock_later = FALSE; |
11291 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11292 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11293 | DBUG_RETURN(error_num); |
11294 | } |
11295 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11296 | share); |
11297 | if (spider_db_query( |
11298 | conn, |
11299 | oracle_share->show_index[1 + pos].ptr(), |
11300 | oracle_share->show_index[1 + pos].length(), |
11301 | -1, |
11302 | &spider->need_mons[link_idx]) |
11303 | ) { |
11304 | conn->mta_conn_mutex_lock_already = FALSE; |
11305 | conn->mta_conn_mutex_unlock_later = FALSE; |
11306 | DBUG_RETURN(spider_db_errorno(conn)); |
11307 | } |
11308 | } else { |
11309 | conn->mta_conn_mutex_lock_already = FALSE; |
11310 | conn->mta_conn_mutex_unlock_later = FALSE; |
11311 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11312 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11313 | DBUG_RETURN(error_num); |
11314 | } |
11315 | } |
11316 | st_spider_db_request_key request_key; |
11317 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
11318 | request_key.query_id = spider->trx->thd->query_id; |
11319 | request_key.handler = spider; |
11320 | request_key.request_id = 1; |
11321 | request_key.next = NULL; |
11322 | if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) |
11323 | { |
11324 | if (error_num || (error_num = spider_db_errorno(conn))) |
11325 | { |
11326 | conn->mta_conn_mutex_lock_already = FALSE; |
11327 | conn->mta_conn_mutex_unlock_later = FALSE; |
11328 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11329 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11330 | DBUG_RETURN(error_num); |
11331 | } |
11332 | /* no record is ok */ |
11333 | } |
11334 | conn->mta_conn_mutex_lock_already = FALSE; |
11335 | conn->mta_conn_mutex_unlock_later = FALSE; |
11336 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11337 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11338 | if (res) |
11339 | { |
11340 | error_num = res->fetch_table_cardinality( |
11341 | crd_mode, |
11342 | table, |
11343 | share->cardinality, |
11344 | share->cardinality_upd, |
11345 | share->bitmap_size |
11346 | ); |
11347 | } |
11348 | for (roop_count = 0, tmp_cardinality = share->cardinality; |
11349 | roop_count < (int) table->s->fields; |
11350 | roop_count++, tmp_cardinality++) |
11351 | { |
11352 | if (!spider_bit_is_set(share->cardinality_upd, roop_count)) |
11353 | { |
11354 | DBUG_PRINT("info" , |
11355 | ("spider init column cardinality id=%d" , roop_count)); |
11356 | *tmp_cardinality = 1; |
11357 | } |
11358 | } |
11359 | if (res) |
11360 | { |
11361 | res->free_result(); |
11362 | delete res; |
11363 | } |
11364 | if (error_num) |
11365 | DBUG_RETURN(error_num); |
11366 | } |
11367 | DBUG_RETURN(0); |
11368 | } |
11369 | |
11370 | int spider_oracle_handler::show_records( |
11371 | int link_idx |
11372 | ) { |
11373 | int error_num; |
11374 | SPIDER_CONN *conn = spider->conns[link_idx]; |
11375 | SPIDER_DB_RESULT *res; |
11376 | SPIDER_SHARE *share = spider->share; |
11377 | uint pos = spider->conn_link_idx[link_idx]; |
11378 | DBUG_ENTER("spider_oracle_handler::show_records" ); |
11379 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11380 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11381 | conn->need_mon = &spider->need_mons[link_idx]; |
11382 | conn->mta_conn_mutex_lock_already = TRUE; |
11383 | conn->mta_conn_mutex_unlock_later = TRUE; |
11384 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11385 | share); |
11386 | if ( |
11387 | (error_num = spider_db_set_names(spider, conn, link_idx)) || |
11388 | ( |
11389 | spider_db_query( |
11390 | conn, |
11391 | oracle_share->show_records[pos].ptr(), |
11392 | oracle_share->show_records[pos].length(), |
11393 | -1, |
11394 | &spider->need_mons[link_idx]) && |
11395 | (error_num = spider_db_errorno(conn)) |
11396 | ) |
11397 | ) { |
11398 | if ( |
11399 | error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && |
11400 | !conn->disable_reconnect |
11401 | ) { |
11402 | /* retry */ |
11403 | if ((error_num = spider_db_ping(spider, conn, link_idx))) |
11404 | { |
11405 | conn->mta_conn_mutex_lock_already = FALSE; |
11406 | conn->mta_conn_mutex_unlock_later = FALSE; |
11407 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11408 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11409 | DBUG_PRINT("info" , ("spider error_num=%d 1" , error_num)); |
11410 | DBUG_RETURN(error_num); |
11411 | } |
11412 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11413 | { |
11414 | conn->mta_conn_mutex_lock_already = FALSE; |
11415 | conn->mta_conn_mutex_unlock_later = FALSE; |
11416 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11417 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11418 | DBUG_PRINT("info" , ("spider error_num=%d 2" , error_num)); |
11419 | DBUG_RETURN(error_num); |
11420 | } |
11421 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11422 | share); |
11423 | if (spider_db_query( |
11424 | conn, |
11425 | oracle_share->show_records[pos].ptr(), |
11426 | oracle_share->show_records[pos].length(), |
11427 | -1, |
11428 | &spider->need_mons[link_idx]) |
11429 | ) { |
11430 | conn->mta_conn_mutex_lock_already = FALSE; |
11431 | conn->mta_conn_mutex_unlock_later = FALSE; |
11432 | DBUG_PRINT("info" , ("spider error_num=%d 3" , error_num)); |
11433 | DBUG_RETURN(spider_db_errorno(conn)); |
11434 | } |
11435 | } else { |
11436 | conn->mta_conn_mutex_lock_already = FALSE; |
11437 | conn->mta_conn_mutex_unlock_later = FALSE; |
11438 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11439 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11440 | DBUG_PRINT("info" , ("spider error_num=%d 4" , error_num)); |
11441 | DBUG_RETURN(error_num); |
11442 | } |
11443 | } |
11444 | st_spider_db_request_key request_key; |
11445 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
11446 | request_key.query_id = spider->trx->thd->query_id; |
11447 | request_key.handler = spider; |
11448 | request_key.request_id = 1; |
11449 | request_key.next = NULL; |
11450 | if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) |
11451 | { |
11452 | conn->mta_conn_mutex_lock_already = FALSE; |
11453 | conn->mta_conn_mutex_unlock_later = FALSE; |
11454 | if (error_num || (error_num = spider_db_errorno(conn))) |
11455 | { |
11456 | DBUG_PRINT("info" , ("spider error_num=%d 5" , error_num)); |
11457 | DBUG_RETURN(error_num); |
11458 | } else { |
11459 | DBUG_PRINT("info" , ("spider error_num=%d 6" , |
11460 | ER_QUERY_ON_FOREIGN_DATA_SOURCE)); |
11461 | DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); |
11462 | } |
11463 | } |
11464 | conn->mta_conn_mutex_lock_already = FALSE; |
11465 | conn->mta_conn_mutex_unlock_later = FALSE; |
11466 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11467 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11468 | error_num = res->fetch_table_records( |
11469 | 1, |
11470 | spider->table_rows |
11471 | ); |
11472 | res->free_result(); |
11473 | delete res; |
11474 | if (error_num) |
11475 | { |
11476 | DBUG_PRINT("info" , ("spider error_num=%d 7" , error_num)); |
11477 | DBUG_RETURN(error_num); |
11478 | } |
11479 | spider->trx->direct_aggregate_count++; |
11480 | DBUG_RETURN(0); |
11481 | } |
11482 | |
11483 | int spider_oracle_handler::show_autoinc( |
11484 | int link_idx |
11485 | ) { |
11486 | int error_num; |
11487 | SPIDER_CONN *conn = spider->conns[link_idx]; |
11488 | SPIDER_DB_RESULT *res; |
11489 | SPIDER_SHARE *share = spider->share; |
11490 | uint pos = spider->conn_link_idx[link_idx]; |
11491 | ulonglong auto_increment_value; |
11492 | DBUG_ENTER("spider_oracle_handler::show_autoinc" ); |
11493 | if (!oracle_share->show_autoinc) |
11494 | DBUG_RETURN(0); |
11495 | |
11496 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11497 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11498 | conn->need_mon = &spider->need_mons[link_idx]; |
11499 | conn->mta_conn_mutex_lock_already = TRUE; |
11500 | conn->mta_conn_mutex_unlock_later = TRUE; |
11501 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11502 | share); |
11503 | if ( |
11504 | (error_num = spider_db_set_names(spider, conn, link_idx)) || |
11505 | ( |
11506 | spider_db_query( |
11507 | conn, |
11508 | oracle_share->show_autoinc[pos].ptr(), |
11509 | oracle_share->show_autoinc[pos].length(), |
11510 | -1, |
11511 | &spider->need_mons[link_idx]) && |
11512 | (error_num = spider_db_errorno(conn)) |
11513 | ) |
11514 | ) { |
11515 | if ( |
11516 | error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && |
11517 | !conn->disable_reconnect |
11518 | ) { |
11519 | /* retry */ |
11520 | if ((error_num = spider_db_ping(spider, conn, link_idx))) |
11521 | { |
11522 | conn->mta_conn_mutex_lock_already = FALSE; |
11523 | conn->mta_conn_mutex_unlock_later = FALSE; |
11524 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11525 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11526 | DBUG_PRINT("info" , ("spider error_num=%d 1" , error_num)); |
11527 | DBUG_RETURN(error_num); |
11528 | } |
11529 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11530 | { |
11531 | conn->mta_conn_mutex_lock_already = FALSE; |
11532 | conn->mta_conn_mutex_unlock_later = FALSE; |
11533 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11534 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11535 | DBUG_PRINT("info" , ("spider error_num=%d 2" , error_num)); |
11536 | DBUG_RETURN(error_num); |
11537 | } |
11538 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11539 | share); |
11540 | if (spider_db_query( |
11541 | conn, |
11542 | oracle_share->show_records[pos].ptr(), |
11543 | oracle_share->show_records[pos].length(), |
11544 | -1, |
11545 | &spider->need_mons[link_idx]) |
11546 | ) { |
11547 | conn->mta_conn_mutex_lock_already = FALSE; |
11548 | conn->mta_conn_mutex_unlock_later = FALSE; |
11549 | DBUG_PRINT("info" , ("spider error_num=%d 3" , error_num)); |
11550 | DBUG_RETURN(spider_db_errorno(conn)); |
11551 | } |
11552 | } else { |
11553 | conn->mta_conn_mutex_lock_already = FALSE; |
11554 | conn->mta_conn_mutex_unlock_later = FALSE; |
11555 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11556 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11557 | DBUG_PRINT("info" , ("spider error_num=%d 4" , error_num)); |
11558 | DBUG_RETURN(error_num); |
11559 | } |
11560 | } |
11561 | st_spider_db_request_key request_key; |
11562 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
11563 | request_key.query_id = spider->trx->thd->query_id; |
11564 | request_key.handler = spider; |
11565 | request_key.request_id = 1; |
11566 | request_key.next = NULL; |
11567 | if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) |
11568 | { |
11569 | conn->mta_conn_mutex_lock_already = FALSE; |
11570 | conn->mta_conn_mutex_unlock_later = FALSE; |
11571 | if (error_num || (error_num = spider_db_errorno(conn))) |
11572 | { |
11573 | DBUG_PRINT("info" , ("spider error_num=%d 5" , error_num)); |
11574 | DBUG_RETURN(error_num); |
11575 | } else { |
11576 | DBUG_PRINT("info" , ("spider error_num=%d 6" , |
11577 | ER_QUERY_ON_FOREIGN_DATA_SOURCE)); |
11578 | DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); |
11579 | } |
11580 | } |
11581 | conn->mta_conn_mutex_lock_already = FALSE; |
11582 | conn->mta_conn_mutex_unlock_later = FALSE; |
11583 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11584 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11585 | error_num = res->fetch_table_records( |
11586 | 1, |
11587 | auto_increment_value |
11588 | ); |
11589 | res->free_result(); |
11590 | delete res; |
11591 | if (error_num) |
11592 | { |
11593 | DBUG_PRINT("info" , ("spider error_num=%d 7" , error_num)); |
11594 | DBUG_RETURN(error_num); |
11595 | } |
11596 | if (auto_increment_value >= |
11597 | share->lgtm_tblhnd_share->auto_increment_value) |
11598 | { |
11599 | share->lgtm_tblhnd_share->auto_increment_value = |
11600 | auto_increment_value + 1; |
11601 | DBUG_PRINT("info" ,("spider auto_increment_value=%llu" , |
11602 | share->lgtm_tblhnd_share->auto_increment_value)); |
11603 | } |
11604 | DBUG_RETURN(0); |
11605 | } |
11606 | |
11607 | int spider_oracle_handler::show_last_insert_id( |
11608 | int link_idx, |
11609 | ulonglong &last_insert_id |
11610 | ) { |
11611 | int error_num; |
11612 | SPIDER_CONN *conn = spider->conns[link_idx]; |
11613 | SPIDER_DB_RESULT *res; |
11614 | uint pos = spider->conn_link_idx[link_idx]; |
11615 | spider_db_oracle *db_oracle = (spider_db_oracle *) conn->db_conn; |
11616 | DBUG_ENTER("spider_oracle_handler::show_last_insert_id" ); |
11617 | if (!oracle_share->show_last_insert_id) |
11618 | { |
11619 | DBUG_ASSERT(0); |
11620 | last_insert_id = 0; |
11621 | db_oracle->stored_last_insert_id = 0; |
11622 | DBUG_RETURN(0); |
11623 | } |
11624 | |
11625 | if ( |
11626 | spider_db_query( |
11627 | conn, |
11628 | oracle_share->show_last_insert_id[pos].ptr(), |
11629 | oracle_share->show_last_insert_id[pos].length(), |
11630 | -1, |
11631 | &spider->need_mons[link_idx]) && |
11632 | (error_num = spider_db_errorno(conn)) |
11633 | ) { |
11634 | DBUG_PRINT("info" , ("spider error_num=%d 4" , error_num)); |
11635 | DBUG_RETURN(error_num); |
11636 | } |
11637 | st_spider_db_request_key request_key; |
11638 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
11639 | request_key.query_id = spider->trx->thd->query_id; |
11640 | request_key.handler = spider; |
11641 | request_key.request_id = 1; |
11642 | request_key.next = NULL; |
11643 | if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) |
11644 | { |
11645 | if (error_num || (error_num = spider_db_errorno(conn))) |
11646 | { |
11647 | DBUG_PRINT("info" , ("spider error_num=%d 5" , error_num)); |
11648 | DBUG_RETURN(error_num); |
11649 | } else { |
11650 | DBUG_PRINT("info" , ("spider error_num=%d 6" , |
11651 | ER_QUERY_ON_FOREIGN_DATA_SOURCE)); |
11652 | DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); |
11653 | } |
11654 | } |
11655 | error_num = res->fetch_table_records( |
11656 | 1, |
11657 | last_insert_id |
11658 | ); |
11659 | res->free_result(); |
11660 | delete res; |
11661 | if (error_num) |
11662 | { |
11663 | DBUG_PRINT("info" , ("spider error_num=%d 7" , error_num)); |
11664 | DBUG_RETURN(error_num); |
11665 | } |
11666 | db_oracle->stored_last_insert_id = last_insert_id; |
11667 | DBUG_RETURN(0); |
11668 | } |
11669 | |
11670 | ha_rows spider_oracle_handler::explain_select( |
11671 | key_range *start_key, |
11672 | key_range *end_key, |
11673 | int link_idx |
11674 | ) { |
11675 | int error_num; |
11676 | SPIDER_CONN *conn = spider->conns[link_idx]; |
11677 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
11678 | spider_string *str = &result_list->sqls[link_idx]; |
11679 | SPIDER_DB_RESULT *res; |
11680 | ha_rows rows; |
11681 | spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; |
11682 | DBUG_ENTER("spider_oracle_handler::explain_select" ); |
11683 | if ((error_num = dbton_hdl->append_explain_select_part( |
11684 | start_key, end_key, SPIDER_SQL_TYPE_OTHER_SQL, link_idx))) |
11685 | { |
11686 | my_errno = error_num; |
11687 | DBUG_RETURN(HA_POS_ERROR); |
11688 | } |
11689 | |
11690 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11691 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11692 | conn->need_mon = &spider->need_mons[link_idx]; |
11693 | conn->mta_conn_mutex_lock_already = TRUE; |
11694 | conn->mta_conn_mutex_unlock_later = TRUE; |
11695 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11696 | spider->share); |
11697 | if ( |
11698 | (error_num = spider_db_set_names(spider, conn, link_idx)) || |
11699 | ( |
11700 | spider_db_query( |
11701 | conn, |
11702 | str->ptr(), |
11703 | str->length(), |
11704 | -1, |
11705 | &spider->need_mons[link_idx]) && |
11706 | (error_num = spider_db_errorno(conn)) |
11707 | ) |
11708 | ) { |
11709 | if ( |
11710 | error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && |
11711 | !conn->disable_reconnect |
11712 | ) { |
11713 | /* retry */ |
11714 | if ((error_num = spider_db_ping(spider, conn, link_idx))) |
11715 | { |
11716 | if (spider->check_error_mode(error_num)) |
11717 | my_errno = error_num; |
11718 | conn->mta_conn_mutex_lock_already = FALSE; |
11719 | conn->mta_conn_mutex_unlock_later = FALSE; |
11720 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11721 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11722 | DBUG_RETURN(HA_POS_ERROR); |
11723 | } |
11724 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11725 | { |
11726 | if (spider->check_error_mode(error_num)) |
11727 | my_errno = error_num; |
11728 | conn->mta_conn_mutex_lock_already = FALSE; |
11729 | conn->mta_conn_mutex_unlock_later = FALSE; |
11730 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11731 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11732 | DBUG_RETURN(HA_POS_ERROR); |
11733 | } |
11734 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11735 | spider->share); |
11736 | if (spider_db_query( |
11737 | conn, |
11738 | str->ptr(), |
11739 | str->length(), |
11740 | -1, |
11741 | &spider->need_mons[link_idx]) |
11742 | ) { |
11743 | error_num = spider_db_errorno(conn); |
11744 | if (spider->check_error_mode(error_num)) |
11745 | my_errno = error_num; |
11746 | conn->mta_conn_mutex_lock_already = FALSE; |
11747 | conn->mta_conn_mutex_unlock_later = FALSE; |
11748 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11749 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11750 | DBUG_RETURN(HA_POS_ERROR); |
11751 | } |
11752 | } else { |
11753 | if (spider->check_error_mode(error_num)) |
11754 | my_errno = error_num; |
11755 | conn->mta_conn_mutex_lock_already = FALSE; |
11756 | conn->mta_conn_mutex_unlock_later = FALSE; |
11757 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11758 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11759 | DBUG_RETURN(HA_POS_ERROR); |
11760 | } |
11761 | } |
11762 | st_spider_db_request_key request_key; |
11763 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
11764 | request_key.query_id = spider->trx->thd->query_id; |
11765 | request_key.handler = spider; |
11766 | request_key.request_id = 1; |
11767 | request_key.next = NULL; |
11768 | if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) |
11769 | { |
11770 | if (error_num || (error_num = spider_db_errorno(conn))) |
11771 | { |
11772 | if (spider->check_error_mode(error_num)) |
11773 | my_errno = error_num; |
11774 | conn->mta_conn_mutex_lock_already = FALSE; |
11775 | conn->mta_conn_mutex_unlock_later = FALSE; |
11776 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11777 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11778 | DBUG_RETURN(HA_POS_ERROR); |
11779 | } else { |
11780 | my_errno = ER_QUERY_ON_FOREIGN_DATA_SOURCE; |
11781 | conn->mta_conn_mutex_lock_already = FALSE; |
11782 | conn->mta_conn_mutex_unlock_later = FALSE; |
11783 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11784 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11785 | DBUG_RETURN(HA_POS_ERROR); |
11786 | } |
11787 | } |
11788 | conn->mta_conn_mutex_lock_already = FALSE; |
11789 | conn->mta_conn_mutex_unlock_later = FALSE; |
11790 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11791 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11792 | error_num = res->fetch_table_records( |
11793 | 2, |
11794 | rows |
11795 | ); |
11796 | res->free_result(); |
11797 | delete res; |
11798 | if (error_num) |
11799 | { |
11800 | my_errno = error_num; |
11801 | DBUG_RETURN(HA_POS_ERROR); |
11802 | } |
11803 | DBUG_RETURN(rows); |
11804 | } |
11805 | |
11806 | int spider_oracle_handler::lock_tables( |
11807 | int link_idx |
11808 | ) { |
11809 | int error_num; |
11810 | SPIDER_CONN *conn = spider->conns[link_idx]; |
11811 | spider_string *str = &sql; |
11812 | DBUG_ENTER("spider_oracle_handler::lock_tables" ); |
11813 | do { |
11814 | str->length(0); |
11815 | if ((error_num = conn->db_conn->append_lock_tables(str))) |
11816 | { |
11817 | DBUG_RETURN(error_num); |
11818 | } |
11819 | if (str->length()) |
11820 | { |
11821 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11822 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11823 | conn->need_mon = &spider->need_mons[link_idx]; |
11824 | conn->mta_conn_mutex_lock_already = TRUE; |
11825 | conn->mta_conn_mutex_unlock_later = TRUE; |
11826 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11827 | { |
11828 | conn->mta_conn_mutex_lock_already = FALSE; |
11829 | conn->mta_conn_mutex_unlock_later = FALSE; |
11830 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11831 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11832 | DBUG_RETURN(error_num); |
11833 | } |
11834 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11835 | spider->share); |
11836 | if (spider_db_query( |
11837 | conn, |
11838 | str->ptr(), |
11839 | str->length(), |
11840 | -1, |
11841 | &spider->need_mons[link_idx]) |
11842 | ) { |
11843 | conn->mta_conn_mutex_lock_already = FALSE; |
11844 | conn->mta_conn_mutex_unlock_later = FALSE; |
11845 | DBUG_RETURN(spider_db_errorno(conn)); |
11846 | } |
11847 | conn->mta_conn_mutex_lock_already = FALSE; |
11848 | conn->mta_conn_mutex_unlock_later = FALSE; |
11849 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11850 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11851 | } |
11852 | if (!conn->table_locked) |
11853 | { |
11854 | conn->table_locked = TRUE; |
11855 | spider->trx->locked_connections++; |
11856 | } |
11857 | } while (str->length()); |
11858 | DBUG_RETURN(0); |
11859 | } |
11860 | |
11861 | int spider_oracle_handler::unlock_tables( |
11862 | int link_idx |
11863 | ) { |
11864 | int error_num; |
11865 | SPIDER_CONN *conn = spider->conns[link_idx]; |
11866 | DBUG_ENTER("spider_oracle_handler::unlock_tables" ); |
11867 | if (conn->table_locked) |
11868 | { |
11869 | if ((error_num = conn->db_conn->commit(&spider->need_mons[link_idx]))) |
11870 | { |
11871 | DBUG_RETURN(error_num); |
11872 | } |
11873 | } |
11874 | DBUG_RETURN(0); |
11875 | } |
11876 | |
11877 | int spider_oracle_handler::disable_keys( |
11878 | SPIDER_CONN *conn, |
11879 | int link_idx |
11880 | ) { |
11881 | int error_num; |
11882 | SPIDER_SHARE *share = spider->share; |
11883 | spider_string *str = &spider->result_list.sqls[link_idx]; |
11884 | DBUG_ENTER("spider_oracle_handler::disable_keys" ); |
11885 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
11886 | str->length(0); |
11887 | if ((error_num = append_disable_keys_part(SPIDER_SQL_TYPE_OTHER_HS, |
11888 | link_idx))) |
11889 | { |
11890 | DBUG_RETURN(error_num); |
11891 | } |
11892 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11893 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11894 | conn->need_mon = &spider->need_mons[link_idx]; |
11895 | conn->mta_conn_mutex_lock_already = TRUE; |
11896 | conn->mta_conn_mutex_unlock_later = TRUE; |
11897 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11898 | { |
11899 | conn->mta_conn_mutex_lock_already = FALSE; |
11900 | conn->mta_conn_mutex_unlock_later = FALSE; |
11901 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11902 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11903 | DBUG_RETURN(error_num); |
11904 | } |
11905 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11906 | share); |
11907 | if (spider_db_query( |
11908 | conn, |
11909 | str->ptr(), |
11910 | str->length(), |
11911 | -1, |
11912 | &spider->need_mons[link_idx]) |
11913 | ) { |
11914 | conn->mta_conn_mutex_lock_already = FALSE; |
11915 | conn->mta_conn_mutex_unlock_later = FALSE; |
11916 | error_num = spider_db_errorno(conn); |
11917 | DBUG_RETURN(error_num); |
11918 | } |
11919 | conn->mta_conn_mutex_lock_already = FALSE; |
11920 | conn->mta_conn_mutex_unlock_later = FALSE; |
11921 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11922 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11923 | DBUG_RETURN(0); |
11924 | } |
11925 | |
11926 | int spider_oracle_handler::enable_keys( |
11927 | SPIDER_CONN *conn, |
11928 | int link_idx |
11929 | ) { |
11930 | int error_num; |
11931 | SPIDER_SHARE *share = spider->share; |
11932 | spider_string *str = &spider->result_list.sqls[link_idx]; |
11933 | DBUG_ENTER("spider_oracle_handler::enable_keys" ); |
11934 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
11935 | str->length(0); |
11936 | if ((error_num = append_enable_keys_part(SPIDER_SQL_TYPE_OTHER_HS, |
11937 | link_idx))) |
11938 | { |
11939 | DBUG_RETURN(error_num); |
11940 | } |
11941 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11942 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11943 | conn->need_mon = &spider->need_mons[link_idx]; |
11944 | conn->mta_conn_mutex_lock_already = TRUE; |
11945 | conn->mta_conn_mutex_unlock_later = TRUE; |
11946 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11947 | { |
11948 | conn->mta_conn_mutex_lock_already = FALSE; |
11949 | conn->mta_conn_mutex_unlock_later = FALSE; |
11950 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11951 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11952 | DBUG_RETURN(error_num); |
11953 | } |
11954 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
11955 | share); |
11956 | if (spider_db_query( |
11957 | conn, |
11958 | str->ptr(), |
11959 | str->length(), |
11960 | -1, |
11961 | &spider->need_mons[link_idx]) |
11962 | ) { |
11963 | conn->mta_conn_mutex_lock_already = FALSE; |
11964 | conn->mta_conn_mutex_unlock_later = FALSE; |
11965 | error_num = spider_db_errorno(conn); |
11966 | DBUG_RETURN(error_num); |
11967 | } |
11968 | conn->mta_conn_mutex_lock_already = FALSE; |
11969 | conn->mta_conn_mutex_unlock_later = FALSE; |
11970 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11971 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
11972 | DBUG_RETURN(0); |
11973 | } |
11974 | |
11975 | int spider_oracle_handler::check_table( |
11976 | SPIDER_CONN *conn, |
11977 | int link_idx, |
11978 | HA_CHECK_OPT* check_opt |
11979 | ) { |
11980 | int error_num; |
11981 | SPIDER_SHARE *share = spider->share; |
11982 | spider_string *str = &spider->result_list.sqls[link_idx]; |
11983 | DBUG_ENTER("spider_oracle_handler::check_table" ); |
11984 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
11985 | str->length(0); |
11986 | if ((error_num = append_check_table_part(SPIDER_SQL_TYPE_OTHER_HS, |
11987 | link_idx, check_opt))) |
11988 | { |
11989 | DBUG_RETURN(error_num); |
11990 | } |
11991 | pthread_mutex_lock(&conn->mta_conn_mutex); |
11992 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
11993 | conn->need_mon = &spider->need_mons[link_idx]; |
11994 | conn->mta_conn_mutex_lock_already = TRUE; |
11995 | conn->mta_conn_mutex_unlock_later = TRUE; |
11996 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
11997 | { |
11998 | conn->mta_conn_mutex_lock_already = FALSE; |
11999 | conn->mta_conn_mutex_unlock_later = FALSE; |
12000 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12001 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12002 | DBUG_RETURN(error_num); |
12003 | } |
12004 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
12005 | share); |
12006 | if (spider_db_query( |
12007 | conn, |
12008 | str->ptr(), |
12009 | str->length(), |
12010 | -1, |
12011 | &spider->need_mons[link_idx]) |
12012 | ) { |
12013 | conn->mta_conn_mutex_lock_already = FALSE; |
12014 | conn->mta_conn_mutex_unlock_later = FALSE; |
12015 | error_num = spider_db_errorno(conn); |
12016 | DBUG_RETURN(error_num); |
12017 | } |
12018 | conn->mta_conn_mutex_lock_already = FALSE; |
12019 | conn->mta_conn_mutex_unlock_later = FALSE; |
12020 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12021 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12022 | DBUG_RETURN(0); |
12023 | } |
12024 | |
12025 | int spider_oracle_handler::repair_table( |
12026 | SPIDER_CONN *conn, |
12027 | int link_idx, |
12028 | HA_CHECK_OPT* check_opt |
12029 | ) { |
12030 | int error_num; |
12031 | SPIDER_SHARE *share = spider->share; |
12032 | spider_string *str = &spider->result_list.sqls[link_idx]; |
12033 | DBUG_ENTER("spider_oracle_handler::repair_table" ); |
12034 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12035 | str->length(0); |
12036 | if ((error_num = append_repair_table_part(SPIDER_SQL_TYPE_OTHER_HS, |
12037 | link_idx, check_opt))) |
12038 | { |
12039 | DBUG_RETURN(error_num); |
12040 | } |
12041 | pthread_mutex_lock(&conn->mta_conn_mutex); |
12042 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12043 | conn->need_mon = &spider->need_mons[link_idx]; |
12044 | conn->mta_conn_mutex_lock_already = TRUE; |
12045 | conn->mta_conn_mutex_unlock_later = TRUE; |
12046 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
12047 | { |
12048 | conn->mta_conn_mutex_lock_already = FALSE; |
12049 | conn->mta_conn_mutex_unlock_later = FALSE; |
12050 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12051 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12052 | DBUG_RETURN(error_num); |
12053 | } |
12054 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
12055 | share); |
12056 | if (spider_db_query( |
12057 | conn, |
12058 | str->ptr(), |
12059 | str->length(), |
12060 | -1, |
12061 | &spider->need_mons[link_idx]) |
12062 | ) { |
12063 | conn->mta_conn_mutex_lock_already = FALSE; |
12064 | conn->mta_conn_mutex_unlock_later = FALSE; |
12065 | error_num = spider_db_errorno(conn); |
12066 | DBUG_RETURN(error_num); |
12067 | } |
12068 | conn->mta_conn_mutex_lock_already = FALSE; |
12069 | conn->mta_conn_mutex_unlock_later = FALSE; |
12070 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12071 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12072 | DBUG_RETURN(0); |
12073 | } |
12074 | |
12075 | int spider_oracle_handler::analyze_table( |
12076 | SPIDER_CONN *conn, |
12077 | int link_idx |
12078 | ) { |
12079 | int error_num; |
12080 | SPIDER_SHARE *share = spider->share; |
12081 | spider_string *str = &spider->result_list.sqls[link_idx]; |
12082 | DBUG_ENTER("spider_oracle_handler::analyze_table" ); |
12083 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12084 | str->length(0); |
12085 | if ((error_num = append_analyze_table_part(SPIDER_SQL_TYPE_OTHER_HS, |
12086 | link_idx))) |
12087 | { |
12088 | DBUG_RETURN(error_num); |
12089 | } |
12090 | pthread_mutex_lock(&conn->mta_conn_mutex); |
12091 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12092 | conn->need_mon = &spider->need_mons[link_idx]; |
12093 | conn->mta_conn_mutex_lock_already = TRUE; |
12094 | conn->mta_conn_mutex_unlock_later = TRUE; |
12095 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
12096 | { |
12097 | conn->mta_conn_mutex_lock_already = FALSE; |
12098 | conn->mta_conn_mutex_unlock_later = FALSE; |
12099 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12100 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12101 | DBUG_RETURN(error_num); |
12102 | } |
12103 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
12104 | share); |
12105 | if (spider_db_query( |
12106 | conn, |
12107 | str->ptr(), |
12108 | str->length(), |
12109 | -1, |
12110 | &spider->need_mons[link_idx]) |
12111 | ) { |
12112 | conn->mta_conn_mutex_lock_already = FALSE; |
12113 | conn->mta_conn_mutex_unlock_later = FALSE; |
12114 | error_num = spider_db_errorno(conn); |
12115 | DBUG_RETURN(error_num); |
12116 | } |
12117 | conn->mta_conn_mutex_lock_already = FALSE; |
12118 | conn->mta_conn_mutex_unlock_later = FALSE; |
12119 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12120 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12121 | DBUG_RETURN(0); |
12122 | } |
12123 | |
12124 | int spider_oracle_handler::optimize_table( |
12125 | SPIDER_CONN *conn, |
12126 | int link_idx |
12127 | ) { |
12128 | int error_num; |
12129 | SPIDER_SHARE *share = spider->share; |
12130 | spider_string *str = &spider->result_list.sqls[link_idx]; |
12131 | DBUG_ENTER("spider_oracle_handler::optimize_table" ); |
12132 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12133 | str->length(0); |
12134 | if ((error_num = append_optimize_table_part(SPIDER_SQL_TYPE_OTHER_HS, |
12135 | link_idx))) |
12136 | { |
12137 | DBUG_RETURN(error_num); |
12138 | } |
12139 | pthread_mutex_lock(&conn->mta_conn_mutex); |
12140 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12141 | conn->need_mon = &spider->need_mons[link_idx]; |
12142 | conn->mta_conn_mutex_lock_already = TRUE; |
12143 | conn->mta_conn_mutex_unlock_later = TRUE; |
12144 | if ((error_num = spider_db_set_names(spider, conn, link_idx))) |
12145 | { |
12146 | conn->mta_conn_mutex_lock_already = FALSE; |
12147 | conn->mta_conn_mutex_unlock_later = FALSE; |
12148 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12149 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12150 | DBUG_RETURN(error_num); |
12151 | } |
12152 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
12153 | share); |
12154 | if (spider_db_query( |
12155 | conn, |
12156 | str->ptr(), |
12157 | str->length(), |
12158 | -1, |
12159 | &spider->need_mons[link_idx]) |
12160 | ) { |
12161 | conn->mta_conn_mutex_lock_already = FALSE; |
12162 | conn->mta_conn_mutex_unlock_later = FALSE; |
12163 | error_num = spider_db_errorno(conn); |
12164 | DBUG_RETURN(error_num); |
12165 | } |
12166 | conn->mta_conn_mutex_lock_already = FALSE; |
12167 | conn->mta_conn_mutex_unlock_later = FALSE; |
12168 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12169 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12170 | DBUG_RETURN(0); |
12171 | } |
12172 | |
12173 | int spider_oracle_handler::flush_tables( |
12174 | SPIDER_CONN *conn, |
12175 | int link_idx, |
12176 | bool lock |
12177 | ) { |
12178 | int error_num; |
12179 | SPIDER_SHARE *share = spider->share; |
12180 | spider_string *str = &spider->result_list.sqls[link_idx]; |
12181 | DBUG_ENTER("spider_oracle_handler::flush_tables" ); |
12182 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12183 | str->length(0); |
12184 | if ((error_num = append_flush_tables_part(SPIDER_SQL_TYPE_OTHER_HS, |
12185 | link_idx, lock))) |
12186 | { |
12187 | DBUG_RETURN(error_num); |
12188 | } |
12189 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
12190 | share); |
12191 | if (spider_db_query( |
12192 | conn, |
12193 | str->ptr(), |
12194 | str->length(), |
12195 | -1, |
12196 | &spider->need_mons[link_idx]) |
12197 | ) { |
12198 | error_num = spider_db_errorno(conn); |
12199 | DBUG_RETURN(error_num); |
12200 | } |
12201 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12202 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12203 | DBUG_RETURN(0); |
12204 | } |
12205 | |
12206 | int spider_oracle_handler::flush_logs( |
12207 | SPIDER_CONN *conn, |
12208 | int link_idx |
12209 | ) { |
12210 | int error_num; |
12211 | SPIDER_SHARE *share = spider->share; |
12212 | DBUG_ENTER("spider_oracle_handler::flush_logs" ); |
12213 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12214 | spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, |
12215 | share); |
12216 | if (spider_db_query( |
12217 | conn, |
12218 | SPIDER_SQL_FLUSH_LOGS_STR, |
12219 | SPIDER_SQL_FLUSH_LOGS_LEN, |
12220 | -1, |
12221 | &spider->need_mons[link_idx]) |
12222 | ) { |
12223 | error_num = spider_db_errorno(conn); |
12224 | DBUG_RETURN(error_num); |
12225 | } |
12226 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
12227 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
12228 | DBUG_RETURN(0); |
12229 | } |
12230 | |
12231 | int spider_oracle_handler::insert_opened_handler( |
12232 | SPIDER_CONN *conn, |
12233 | int link_idx |
12234 | ) { |
12235 | spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; |
12236 | SPIDER_LINK_FOR_HASH *tmp_link_for_hash = &link_for_hash[link_idx]; |
12237 | DBUG_ASSERT(tmp_link_for_hash->spider == spider); |
12238 | DBUG_ASSERT(tmp_link_for_hash->link_idx == link_idx); |
12239 | uint old_elements = db_conn->handler_open_array.max_element; |
12240 | DBUG_ENTER("spider_oracle_handler::insert_opened_handler" ); |
12241 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12242 | if (insert_dynamic(&db_conn->handler_open_array, |
12243 | (uchar*) &tmp_link_for_hash)) |
12244 | { |
12245 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12246 | } |
12247 | if (db_conn->handler_open_array.max_element > old_elements) |
12248 | { |
12249 | spider_alloc_calc_mem(spider_current_trx, |
12250 | db_conn->handler_open_array, |
12251 | (db_conn->handler_open_array.max_element - old_elements) * |
12252 | db_conn->handler_open_array.size_of_element); |
12253 | } |
12254 | DBUG_RETURN(0); |
12255 | } |
12256 | |
12257 | int spider_oracle_handler::delete_opened_handler( |
12258 | SPIDER_CONN *conn, |
12259 | int link_idx |
12260 | ) { |
12261 | spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; |
12262 | uint roop_count, elements = db_conn->handler_open_array.elements; |
12263 | SPIDER_LINK_FOR_HASH *tmp_link_for_hash; |
12264 | DBUG_ENTER("spider_oracle_handler::delete_opened_handler" ); |
12265 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12266 | for (roop_count = 0; roop_count < elements; roop_count++) |
12267 | { |
12268 | get_dynamic(&db_conn->handler_open_array, (uchar *) &tmp_link_for_hash, |
12269 | roop_count); |
12270 | if (tmp_link_for_hash == &link_for_hash[link_idx]) |
12271 | { |
12272 | delete_dynamic_element(&db_conn->handler_open_array, roop_count); |
12273 | break; |
12274 | } |
12275 | } |
12276 | DBUG_ASSERT(roop_count < elements); |
12277 | DBUG_RETURN(0); |
12278 | } |
12279 | |
12280 | int spider_oracle_handler::sync_from_clone_source( |
12281 | spider_db_handler *dbton_hdl |
12282 | ) { |
12283 | DBUG_ENTER("spider_oracle_handler::sync_from_clone_source" ); |
12284 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12285 | DBUG_RETURN(0); |
12286 | } |
12287 | |
12288 | bool spider_oracle_handler::support_use_handler( |
12289 | int use_handler |
12290 | ) { |
12291 | DBUG_ENTER("spider_oracle_handler::support_use_handler" ); |
12292 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12293 | DBUG_RETURN(FALSE); |
12294 | } |
12295 | |
12296 | void spider_oracle_handler::minimum_select_bitmap_create() |
12297 | { |
12298 | TABLE *table = spider->get_table(); |
12299 | Field **field_p; |
12300 | DBUG_ENTER("spider_oracle_handler::minimum_select_bitmap_create" ); |
12301 | memset(minimum_select_bitmap, 0, no_bytes_in_map(table->read_set)); |
12302 | if ( |
12303 | spider->use_index_merge || |
12304 | #ifdef HA_CAN_BULK_ACCESS |
12305 | (spider->is_clone && !spider->is_bulk_access_clone) |
12306 | #else |
12307 | spider->is_clone |
12308 | #endif |
12309 | ) { |
12310 | /* need preparing for cmp_ref */ |
12311 | TABLE_SHARE *table_share = table->s; |
12312 | if ( |
12313 | table_share->primary_key == MAX_KEY |
12314 | ) { |
12315 | /* need all columns */ |
12316 | memset(minimum_select_bitmap, 0xFF, no_bytes_in_map(table->read_set)); |
12317 | DBUG_VOID_RETURN; |
12318 | } else { |
12319 | /* need primary key columns */ |
12320 | uint roop_count; |
12321 | KEY *key_info; |
12322 | KEY_PART_INFO *key_part; |
12323 | Field *field; |
12324 | key_info = &table_share->key_info[table_share->primary_key]; |
12325 | key_part = key_info->key_part; |
12326 | for (roop_count = 0; |
12327 | roop_count < spider_user_defined_key_parts(key_info); |
12328 | roop_count++) |
12329 | { |
12330 | field = key_part[roop_count].field; |
12331 | spider_set_bit(minimum_select_bitmap, field->field_index); |
12332 | } |
12333 | } |
12334 | } |
12335 | for (field_p = table->field; *field_p; field_p++) |
12336 | { |
12337 | uint field_index = (*field_p)->field_index; |
12338 | if ( |
12339 | spider_bit_is_set(spider->searched_bitmap, field_index) | |
12340 | bitmap_is_set(table->read_set, field_index) | |
12341 | bitmap_is_set(table->write_set, field_index) |
12342 | ) { |
12343 | spider_set_bit(minimum_select_bitmap, field_index); |
12344 | } |
12345 | } |
12346 | DBUG_VOID_RETURN; |
12347 | } |
12348 | |
12349 | bool spider_oracle_handler::minimum_select_bit_is_set( |
12350 | uint field_index |
12351 | ) { |
12352 | DBUG_ENTER("spider_oracle_handler::minimum_select_bit_is_set" ); |
12353 | DBUG_PRINT("info" ,("spider field_index=%u" , field_index)); |
12354 | DBUG_PRINT("info" ,("spider minimum_select_bitmap=%s" , |
12355 | spider_bit_is_set(minimum_select_bitmap, field_index) ? |
12356 | "TRUE" : "FALSE" )); |
12357 | DBUG_RETURN(spider_bit_is_set(minimum_select_bitmap, field_index)); |
12358 | } |
12359 | |
12360 | void spider_oracle_handler::copy_minimum_select_bitmap( |
12361 | uchar *bitmap |
12362 | ) { |
12363 | int roop_count; |
12364 | TABLE *table = spider->get_table(); |
12365 | DBUG_ENTER("spider_oracle_handler::copy_minimum_select_bitmap" ); |
12366 | for (roop_count = 0; |
12367 | roop_count < (int) ((table->s->fields + 7) / 8); |
12368 | roop_count++) |
12369 | { |
12370 | bitmap[roop_count] = |
12371 | minimum_select_bitmap[roop_count]; |
12372 | DBUG_PRINT("info" ,("spider roop_count=%d" , roop_count)); |
12373 | DBUG_PRINT("info" ,("spider bitmap=%d" , |
12374 | bitmap[roop_count])); |
12375 | } |
12376 | DBUG_VOID_RETURN; |
12377 | } |
12378 | |
12379 | int spider_oracle_handler::init_union_table_name_pos() |
12380 | { |
12381 | DBUG_ENTER("spider_oracle_handler::init_union_table_name_pos" ); |
12382 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12383 | if (!union_table_name_pos_first) |
12384 | { |
12385 | if (!spider_bulk_malloc(spider_current_trx, 238, MYF(MY_WME), |
12386 | &union_table_name_pos_first, sizeof(SPIDER_INT_HLD), |
12387 | NullS) |
12388 | ) { |
12389 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12390 | } |
12391 | union_table_name_pos_first->next = NULL; |
12392 | } |
12393 | union_table_name_pos_current = union_table_name_pos_first; |
12394 | union_table_name_pos_current->tgt_num = 0; |
12395 | DBUG_RETURN(0); |
12396 | } |
12397 | |
12398 | int spider_oracle_handler::set_union_table_name_pos() |
12399 | { |
12400 | DBUG_ENTER("spider_oracle_handler::set_union_table_name_pos" ); |
12401 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12402 | if (union_table_name_pos_current->tgt_num >= SPIDER_INT_HLD_TGT_SIZE) |
12403 | { |
12404 | if (!union_table_name_pos_current->next) |
12405 | { |
12406 | if (!spider_bulk_malloc(spider_current_trx, 239, MYF(MY_WME), |
12407 | &union_table_name_pos_current->next, sizeof(SPIDER_INT_HLD), |
12408 | NullS) |
12409 | ) { |
12410 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12411 | } |
12412 | union_table_name_pos_current->next->next = NULL; |
12413 | } |
12414 | union_table_name_pos_current = union_table_name_pos_current->next; |
12415 | union_table_name_pos_current->tgt_num = 0; |
12416 | } |
12417 | union_table_name_pos_current->tgt[union_table_name_pos_current->tgt_num] = |
12418 | table_name_pos; |
12419 | ++union_table_name_pos_current->tgt_num; |
12420 | DBUG_RETURN(0); |
12421 | } |
12422 | |
12423 | int spider_oracle_handler::reset_union_table_name( |
12424 | spider_string *str, |
12425 | int link_idx, |
12426 | ulong sql_type |
12427 | ) { |
12428 | DBUG_ENTER("spider_oracle_handler::reset_union_table_name" ); |
12429 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12430 | if (!union_table_name_pos_current) |
12431 | DBUG_RETURN(0); |
12432 | |
12433 | SPIDER_INT_HLD *tmp_pos = union_table_name_pos_first; |
12434 | uint cur_num, pos_backup = str->length(); |
12435 | while(TRUE) |
12436 | { |
12437 | for (cur_num = 0; cur_num < tmp_pos->tgt_num; ++cur_num) |
12438 | { |
12439 | str->length(tmp_pos->tgt[cur_num]); |
12440 | append_table_name_with_adjusting(str, link_idx, sql_type); |
12441 | } |
12442 | if (tmp_pos == union_table_name_pos_current) |
12443 | break; |
12444 | tmp_pos = tmp_pos->next; |
12445 | } |
12446 | str->length(pos_backup); |
12447 | DBUG_RETURN(0); |
12448 | } |
12449 | |
12450 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
12451 | int spider_oracle_handler::append_from_and_tables_part( |
12452 | spider_fields *fields, |
12453 | ulong sql_type |
12454 | ) { |
12455 | int error_num; |
12456 | spider_string *str; |
12457 | DBUG_ENTER("spider_oracle_handler::append_from_and_tables_part" ); |
12458 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12459 | switch (sql_type) |
12460 | { |
12461 | case SPIDER_SQL_TYPE_SELECT_SQL: |
12462 | str = &sql; |
12463 | break; |
12464 | default: |
12465 | DBUG_RETURN(0); |
12466 | } |
12467 | error_num = spider_db_oracle_utility.append_from_and_tables(fields, str); |
12468 | DBUG_RETURN(error_num); |
12469 | } |
12470 | |
12471 | int spider_oracle_handler::reappend_tables_part( |
12472 | spider_fields *fields, |
12473 | ulong sql_type |
12474 | ) { |
12475 | int error_num; |
12476 | spider_string *str; |
12477 | DBUG_ENTER("spider_oracle_handler::reappend_tables_part" ); |
12478 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12479 | switch (sql_type) |
12480 | { |
12481 | case SPIDER_SQL_TYPE_SELECT_SQL: |
12482 | str = &sql; |
12483 | break; |
12484 | default: |
12485 | DBUG_RETURN(0); |
12486 | } |
12487 | error_num = spider_db_oracle_utility.reappend_tables(fields, |
12488 | link_idx_chain, str); |
12489 | DBUG_RETURN(error_num); |
12490 | } |
12491 | |
12492 | int spider_oracle_handler::append_where_part( |
12493 | ulong sql_type |
12494 | ) { |
12495 | int error_num; |
12496 | spider_string *str; |
12497 | DBUG_ENTER("spider_oracle_handler::append_where_part" ); |
12498 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12499 | switch (sql_type) |
12500 | { |
12501 | case SPIDER_SQL_TYPE_SELECT_SQL: |
12502 | str = &sql; |
12503 | break; |
12504 | default: |
12505 | DBUG_RETURN(0); |
12506 | } |
12507 | error_num = spider_db_oracle_utility.append_where(str); |
12508 | DBUG_RETURN(error_num); |
12509 | } |
12510 | |
12511 | int spider_oracle_handler::append_having_part( |
12512 | ulong sql_type |
12513 | ) { |
12514 | int error_num; |
12515 | spider_string *str; |
12516 | DBUG_ENTER("spider_oracle_handler::append_having_part" ); |
12517 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12518 | switch (sql_type) |
12519 | { |
12520 | case SPIDER_SQL_TYPE_SELECT_SQL: |
12521 | str = &sql; |
12522 | break; |
12523 | default: |
12524 | DBUG_RETURN(0); |
12525 | } |
12526 | error_num = spider_db_oracle_utility.append_having(str); |
12527 | DBUG_RETURN(error_num); |
12528 | } |
12529 | |
12530 | int spider_oracle_handler::append_item_type_part( |
12531 | Item *item, |
12532 | const char *alias, |
12533 | uint alias_length, |
12534 | bool use_fields, |
12535 | spider_fields *fields, |
12536 | ulong sql_type |
12537 | ) { |
12538 | int error_num; |
12539 | spider_string *str; |
12540 | DBUG_ENTER("spider_oracle_handler::append_item_type_part" ); |
12541 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12542 | switch (sql_type) |
12543 | { |
12544 | case SPIDER_SQL_TYPE_SELECT_SQL: |
12545 | str = &sql; |
12546 | break; |
12547 | default: |
12548 | DBUG_RETURN(0); |
12549 | } |
12550 | error_num = spider_db_print_item_type(item, spider, str, alias, alias_length, |
12551 | spider_dbton_oracle.dbton_id, use_fields, fields); |
12552 | DBUG_RETURN(error_num); |
12553 | } |
12554 | |
12555 | int spider_oracle_handler::append_list_item_select_part( |
12556 | List<Item> *select, |
12557 | const char *alias, |
12558 | uint alias_length, |
12559 | bool use_fields, |
12560 | spider_fields *fields, |
12561 | ulong sql_type |
12562 | ) { |
12563 | int error_num; |
12564 | spider_string *str; |
12565 | DBUG_ENTER("spider_oracle_handler::append_list_item_select_part" ); |
12566 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12567 | switch (sql_type) |
12568 | { |
12569 | case SPIDER_SQL_TYPE_SELECT_SQL: |
12570 | str = &sql; |
12571 | break; |
12572 | default: |
12573 | DBUG_RETURN(0); |
12574 | } |
12575 | error_num = append_list_item_select(select, str, alias, alias_length, |
12576 | use_fields, fields); |
12577 | DBUG_RETURN(error_num); |
12578 | } |
12579 | |
12580 | int spider_oracle_handler::append_list_item_select( |
12581 | List<Item> *select, |
12582 | spider_string *str, |
12583 | const char *alias, |
12584 | uint alias_length, |
12585 | bool use_fields, |
12586 | spider_fields *fields |
12587 | ) { |
12588 | int error_num; |
12589 | uint dbton_id = spider_dbton_oracle.dbton_id, length; |
12590 | List_iterator_fast<Item> it(*select); |
12591 | Item *item; |
12592 | Field **field_ptr; |
12593 | DBUG_ENTER("spider_oracle_handler::append_list_item_select" ); |
12594 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12595 | while ((item = it++)) |
12596 | { |
12597 | if ((error_num = spider_db_print_item_type(item, spider, str, |
12598 | alias, alias_length, dbton_id, use_fields, fields))) |
12599 | { |
12600 | DBUG_RETURN(error_num); |
12601 | } |
12602 | field_ptr = fields->get_next_field_ptr(); |
12603 | length = strlen((*field_ptr)->field_name); |
12604 | if (str->reserve( |
12605 | SPIDER_SQL_COMMA_LEN + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + |
12606 | SPIDER_SQL_SPACE_LEN + length |
12607 | )) |
12608 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12609 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
12610 | if ((error_num = spider_db_oracle_utility.append_name(str, |
12611 | (*field_ptr)->field_name, length))) |
12612 | { |
12613 | DBUG_RETURN(error_num); |
12614 | } |
12615 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
12616 | } |
12617 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
12618 | DBUG_RETURN(0); |
12619 | } |
12620 | |
12621 | int spider_oracle_handler::append_group_by_part( |
12622 | ORDER *order, |
12623 | const char *alias, |
12624 | uint alias_length, |
12625 | bool use_fields, |
12626 | spider_fields *fields, |
12627 | ulong sql_type |
12628 | ) { |
12629 | int error_num; |
12630 | spider_string *str; |
12631 | DBUG_ENTER("spider_oracle_handler::append_group_by_part" ); |
12632 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12633 | switch (sql_type) |
12634 | { |
12635 | case SPIDER_SQL_TYPE_SELECT_SQL: |
12636 | str = &sql; |
12637 | break; |
12638 | default: |
12639 | DBUG_RETURN(0); |
12640 | } |
12641 | error_num = append_group_by(order, str, alias, alias_length, |
12642 | use_fields, fields); |
12643 | DBUG_RETURN(error_num); |
12644 | } |
12645 | |
12646 | int spider_oracle_handler::append_group_by( |
12647 | ORDER *order, |
12648 | spider_string *str, |
12649 | const char *alias, |
12650 | uint alias_length, |
12651 | bool use_fields, |
12652 | spider_fields *fields |
12653 | ) { |
12654 | int error_num; |
12655 | uint dbton_id = spider_dbton_oracle.dbton_id; |
12656 | DBUG_ENTER("spider_oracle_handler::append_group_by" ); |
12657 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12658 | if (order) |
12659 | { |
12660 | if (str->reserve(SPIDER_SQL_GROUP_LEN)) |
12661 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12662 | str->q_append(SPIDER_SQL_GROUP_STR, SPIDER_SQL_GROUP_LEN); |
12663 | for (; order; order = order->next) |
12664 | { |
12665 | if ((error_num = spider_db_print_item_type((*order->item), spider, str, |
12666 | alias, alias_length, dbton_id, use_fields, fields))) |
12667 | { |
12668 | DBUG_RETURN(error_num); |
12669 | } |
12670 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
12671 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12672 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
12673 | } |
12674 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
12675 | } |
12676 | DBUG_RETURN(0); |
12677 | } |
12678 | |
12679 | int spider_oracle_handler::append_order_by_part( |
12680 | ORDER *order, |
12681 | const char *alias, |
12682 | uint alias_length, |
12683 | bool use_fields, |
12684 | spider_fields *fields, |
12685 | ulong sql_type |
12686 | ) { |
12687 | int error_num; |
12688 | spider_string *str; |
12689 | DBUG_ENTER("spider_oracle_handler::append_order_by_part" ); |
12690 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12691 | switch (sql_type) |
12692 | { |
12693 | case SPIDER_SQL_TYPE_SELECT_SQL: |
12694 | str = &sql; |
12695 | break; |
12696 | default: |
12697 | DBUG_RETURN(0); |
12698 | } |
12699 | error_num = append_order_by(order, str, alias, alias_length, |
12700 | use_fields, fields); |
12701 | DBUG_RETURN(error_num); |
12702 | } |
12703 | |
12704 | int spider_oracle_handler::append_order_by( |
12705 | ORDER *order, |
12706 | spider_string *str, |
12707 | const char *alias, |
12708 | uint alias_length, |
12709 | bool use_fields, |
12710 | spider_fields *fields |
12711 | ) { |
12712 | int error_num; |
12713 | uint dbton_id = spider_dbton_oracle.dbton_id; |
12714 | DBUG_ENTER("spider_oracle_handler::append_order_by" ); |
12715 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12716 | if (order) |
12717 | { |
12718 | if (str->reserve(SPIDER_SQL_ORDER_LEN)) |
12719 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12720 | str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
12721 | for (; order; order = order->next) |
12722 | { |
12723 | if ((error_num = spider_db_print_item_type((*order->item), spider, str, |
12724 | alias, alias_length, dbton_id, use_fields, fields))) |
12725 | { |
12726 | DBUG_RETURN(error_num); |
12727 | } |
12728 | #ifdef SPIDER_ORDER_HAS_ENUM_ORDER |
12729 | if (order->direction == ORDER::ORDER_DESC) |
12730 | #else |
12731 | if (!order->asc) |
12732 | #endif |
12733 | { |
12734 | if (str->reserve(SPIDER_SQL_COMMA_LEN + SPIDER_SQL_DESC_LEN)) |
12735 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12736 | str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
12737 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
12738 | } else { |
12739 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
12740 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12741 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
12742 | } |
12743 | } |
12744 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
12745 | } |
12746 | DBUG_RETURN(0); |
12747 | } |
12748 | #endif |
12749 | |
12750 | spider_oracle_copy_table::spider_oracle_copy_table( |
12751 | spider_oracle_share *db_share |
12752 | ) : spider_db_copy_table( |
12753 | db_share |
12754 | ), |
12755 | oracle_share(db_share), |
12756 | pos(0), |
12757 | table_name_pos(0), |
12758 | pos_diff(0), |
12759 | table_lock_mode(0), |
12760 | select_rownum_appended(FALSE), |
12761 | first_str(NULL), |
12762 | current_str(NULL) |
12763 | { |
12764 | DBUG_ENTER("spider_oracle_copy_table::spider_oracle_copy_table" ); |
12765 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12766 | DBUG_VOID_RETURN; |
12767 | } |
12768 | |
12769 | spider_oracle_copy_table::~spider_oracle_copy_table() |
12770 | { |
12771 | DBUG_ENTER("spider_oracle_copy_table::~spider_oracle_copy_table" ); |
12772 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12773 | while (first_str) |
12774 | { |
12775 | current_str = first_str; |
12776 | first_str = first_str->next; |
12777 | delete [] current_str; |
12778 | } |
12779 | DBUG_VOID_RETURN; |
12780 | } |
12781 | |
12782 | int spider_oracle_copy_table::init() |
12783 | { |
12784 | DBUG_ENTER("spider_oracle_copy_table::init" ); |
12785 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12786 | sql.init_calc_mem(213); |
12787 | sql_part.init_calc_mem(215); |
12788 | DBUG_RETURN(0); |
12789 | } |
12790 | |
12791 | void spider_oracle_copy_table::set_sql_charset( |
12792 | CHARSET_INFO *cs |
12793 | ) { |
12794 | DBUG_ENTER("spider_oracle_copy_table::set_sql_charset" ); |
12795 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12796 | sql.set_charset(cs); |
12797 | DBUG_VOID_RETURN; |
12798 | } |
12799 | |
12800 | int spider_oracle_copy_table::append_select_str() |
12801 | { |
12802 | DBUG_ENTER("spider_oracle_copy_table::append_select_str" ); |
12803 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12804 | if (sql.reserve(SPIDER_SQL_SELECT_LEN)) |
12805 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12806 | sql.q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); |
12807 | DBUG_RETURN(0); |
12808 | } |
12809 | |
12810 | int spider_oracle_copy_table::append_insert_str( |
12811 | int insert_flg |
12812 | ) { |
12813 | DBUG_ENTER("spider_oracle_copy_table::append_insert_str" ); |
12814 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12815 | if (sql.reserve(SPIDER_SQL_INSERT_LEN)) |
12816 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12817 | sql.q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); |
12818 | DBUG_RETURN(0); |
12819 | } |
12820 | |
12821 | int spider_oracle_copy_table::append_table_columns( |
12822 | TABLE_SHARE *table_share |
12823 | ) { |
12824 | int error_num; |
12825 | Field **field; |
12826 | DBUG_ENTER("spider_oracle_copy_table::append_table_columns" ); |
12827 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12828 | for (field = table_share->field; *field; field++) |
12829 | { |
12830 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
12831 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12832 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
12833 | if ((error_num = spider_db_append_name_with_quote_str(&sql, |
12834 | (char *) (*field)->field_name.str, spider_dbton_oracle.dbton_id))) |
12835 | DBUG_RETURN(error_num); |
12836 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) |
12837 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12838 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
12839 | sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
12840 | } |
12841 | sql.length(sql.length() - SPIDER_SQL_COMMA_LEN); |
12842 | DBUG_RETURN(0); |
12843 | } |
12844 | |
12845 | int spider_oracle_copy_table::append_from_str() |
12846 | { |
12847 | DBUG_ENTER("spider_oracle_copy_table::append_from_str" ); |
12848 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12849 | if (sql.reserve(SPIDER_SQL_FROM_LEN)) |
12850 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12851 | sql.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); |
12852 | DBUG_RETURN(0); |
12853 | } |
12854 | |
12855 | int spider_oracle_copy_table::append_table_name( |
12856 | int link_idx |
12857 | ) { |
12858 | int error_num; |
12859 | DBUG_ENTER("spider_oracle_copy_table::append_table_name" ); |
12860 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12861 | table_name_pos = sql.length(); |
12862 | error_num = oracle_share->append_table_name(&sql, link_idx); |
12863 | store_link_idx = link_idx; |
12864 | DBUG_RETURN(error_num); |
12865 | } |
12866 | |
12867 | void spider_oracle_copy_table::set_sql_pos() |
12868 | { |
12869 | DBUG_ENTER("spider_oracle_copy_table::set_sql_pos" ); |
12870 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12871 | pos = sql.length(); |
12872 | DBUG_VOID_RETURN; |
12873 | } |
12874 | |
12875 | void spider_oracle_copy_table::set_sql_to_pos() |
12876 | { |
12877 | DBUG_ENTER("spider_oracle_copy_table::set_sql_to_pos" ); |
12878 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12879 | sql.length(pos); |
12880 | DBUG_VOID_RETURN; |
12881 | } |
12882 | |
12883 | int spider_oracle_copy_table::append_copy_where( |
12884 | spider_db_copy_table *source_ct, |
12885 | KEY *key_info, |
12886 | ulong *last_row_pos, |
12887 | ulong *last_lengths |
12888 | ) { |
12889 | int error_num, roop_count, roop_count2; |
12890 | DBUG_ENTER("spider_oracle_copy_table::append_copy_where" ); |
12891 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12892 | if (sql.reserve(SPIDER_SQL_WHERE_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) |
12893 | { |
12894 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12895 | } |
12896 | sql.q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); |
12897 | sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
12898 | Field *field; |
12899 | KEY_PART_INFO *key_part = key_info->key_part; |
12900 | for (roop_count = spider_user_defined_key_parts(key_info) - 1; |
12901 | roop_count >= 0; roop_count--) |
12902 | { |
12903 | for (roop_count2 = 0; roop_count2 < roop_count; roop_count2++) |
12904 | { |
12905 | field = key_part[roop_count2].field; |
12906 | if ((error_num = copy_key_row(source_ct, |
12907 | field, &last_row_pos[field->field_index], |
12908 | &last_lengths[field->field_index], |
12909 | SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN))) |
12910 | { |
12911 | DBUG_RETURN(error_num); |
12912 | } |
12913 | } |
12914 | field = key_part[roop_count2].field; |
12915 | if ((error_num = copy_key_row(source_ct, |
12916 | field, &last_row_pos[field->field_index], |
12917 | &last_lengths[field->field_index], |
12918 | SPIDER_SQL_GT_STR, SPIDER_SQL_GT_LEN))) |
12919 | { |
12920 | DBUG_RETURN(error_num); |
12921 | } |
12922 | sql.length(sql.length() - SPIDER_SQL_AND_LEN); |
12923 | if (sql.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + |
12924 | SPIDER_SQL_OR_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) |
12925 | { |
12926 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12927 | } |
12928 | sql.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
12929 | sql.q_append(SPIDER_SQL_OR_STR, SPIDER_SQL_OR_LEN); |
12930 | sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
12931 | } |
12932 | sql.length(sql.length() - SPIDER_SQL_OR_LEN - SPIDER_SQL_OPEN_PAREN_LEN); |
12933 | DBUG_RETURN(0); |
12934 | } |
12935 | |
12936 | int spider_oracle_copy_table::append_key_order_str( |
12937 | KEY *key_info, |
12938 | int start_pos, |
12939 | bool desc_flg |
12940 | ) { |
12941 | int length, error_num; |
12942 | KEY_PART_INFO *key_part; |
12943 | Field *field; |
12944 | DBUG_ENTER("spider_oracle_copy_table::append_key_order_str" ); |
12945 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
12946 | if (select_rownum_appended) |
12947 | { |
12948 | if (sql.reserve(SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN)) |
12949 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12950 | sql.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
12951 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
12952 | DBUG_RETURN(0); |
12953 | } |
12954 | sql_part.length(0); |
12955 | if (sql_part.reserve(sql.length() + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN + |
12956 | SPIDER_SQL_ROW_NUMBER_HEAD_LEN)) |
12957 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12958 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR, |
12959 | SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN); |
12960 | sql_part.q_append(sql.ptr(), table_name_pos - SPIDER_SQL_FROM_LEN); |
12961 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_HEAD_STR, |
12962 | SPIDER_SQL_ROW_NUMBER_HEAD_LEN); |
12963 | if ((int) spider_user_defined_key_parts(key_info) > start_pos) |
12964 | { |
12965 | if (desc_flg == TRUE) |
12966 | { |
12967 | for ( |
12968 | key_part = key_info->key_part + start_pos, |
12969 | length = 0; |
12970 | length + start_pos < (int) spider_user_defined_key_parts(key_info); |
12971 | key_part++, |
12972 | length++ |
12973 | ) { |
12974 | field = key_part->field; |
12975 | if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
12976 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12977 | sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
12978 | SPIDER_SQL_NAME_QUOTE_LEN); |
12979 | if ((error_num = spider_db_append_name_with_quote_str(&sql_part, |
12980 | (char *) field->field_name.str, spider_dbton_oracle.dbton_id))) |
12981 | DBUG_RETURN(error_num); |
12982 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
12983 | { |
12984 | if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN + |
12985 | SPIDER_SQL_COMMA_LEN)) |
12986 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12987 | sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
12988 | SPIDER_SQL_NAME_QUOTE_LEN); |
12989 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
12990 | } else { |
12991 | if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN + |
12992 | SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) |
12993 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
12994 | sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
12995 | SPIDER_SQL_NAME_QUOTE_LEN); |
12996 | sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
12997 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
12998 | } |
12999 | } |
13000 | } else { |
13001 | for ( |
13002 | key_part = key_info->key_part + start_pos, |
13003 | length = 0; |
13004 | length + start_pos < (int) spider_user_defined_key_parts(key_info); |
13005 | key_part++, |
13006 | length++ |
13007 | ) { |
13008 | field = key_part->field; |
13009 | if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
13010 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13011 | sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13012 | SPIDER_SQL_NAME_QUOTE_LEN); |
13013 | if ((error_num = spider_db_append_name_with_quote_str(&sql_part, |
13014 | (char *) field->field_name.str, spider_dbton_oracle.dbton_id))) |
13015 | DBUG_RETURN(error_num); |
13016 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
13017 | { |
13018 | if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN + |
13019 | SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) |
13020 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13021 | sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13022 | SPIDER_SQL_NAME_QUOTE_LEN); |
13023 | sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
13024 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
13025 | } else { |
13026 | if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN + |
13027 | SPIDER_SQL_COMMA_LEN)) |
13028 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13029 | sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13030 | SPIDER_SQL_NAME_QUOTE_LEN); |
13031 | sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
13032 | } |
13033 | } |
13034 | } |
13035 | } |
13036 | if (desc_flg == TRUE) |
13037 | { |
13038 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + |
13039 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + sql.length() - table_name_pos + |
13040 | SPIDER_SQL_FROM_LEN)) |
13041 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13042 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, |
13043 | SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); |
13044 | } else { |
13045 | if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + |
13046 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + sql.length() - table_name_pos + |
13047 | SPIDER_SQL_FROM_LEN)) |
13048 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13049 | sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, |
13050 | SPIDER_SQL_ROW_NUMBER_TAIL_LEN); |
13051 | } |
13052 | pos_diff = sql_part.length() + SPIDER_SQL_FROM_LEN - table_name_pos; |
13053 | sql_part.q_append(sql.ptr() + table_name_pos - SPIDER_SQL_FROM_LEN, |
13054 | sql.length() - table_name_pos + SPIDER_SQL_FROM_LEN); |
13055 | sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, |
13056 | SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); |
13057 | |
13058 | if ((int) spider_user_defined_key_parts(key_info) > start_pos) |
13059 | { |
13060 | if (sql.reserve(SPIDER_SQL_ORDER_LEN)) |
13061 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13062 | sql.q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); |
13063 | if (desc_flg == TRUE) |
13064 | { |
13065 | for ( |
13066 | key_part = key_info->key_part + start_pos, |
13067 | length = 0; |
13068 | length + start_pos < (int) spider_user_defined_key_parts(key_info); |
13069 | key_part++, |
13070 | length++ |
13071 | ) { |
13072 | field = key_part->field; |
13073 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
13074 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13075 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13076 | SPIDER_SQL_NAME_QUOTE_LEN); |
13077 | if ((error_num = spider_db_append_name_with_quote_str(&sql, |
13078 | (char *) field->field_name.str, spider_dbton_oracle.dbton_id))) |
13079 | DBUG_RETURN(error_num); |
13080 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
13081 | { |
13082 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) |
13083 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13084 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13085 | SPIDER_SQL_NAME_QUOTE_LEN); |
13086 | sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
13087 | } else { |
13088 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_DESC_LEN + |
13089 | SPIDER_SQL_COMMA_LEN)) |
13090 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13091 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13092 | SPIDER_SQL_NAME_QUOTE_LEN); |
13093 | sql.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
13094 | sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
13095 | } |
13096 | } |
13097 | } else { |
13098 | for ( |
13099 | key_part = key_info->key_part + start_pos, |
13100 | length = 0; |
13101 | length + start_pos < (int) spider_user_defined_key_parts(key_info); |
13102 | key_part++, |
13103 | length++ |
13104 | ) { |
13105 | field = key_part->field; |
13106 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
13107 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13108 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13109 | SPIDER_SQL_NAME_QUOTE_LEN); |
13110 | if ((error_num = spider_db_append_name_with_quote_str(&sql, |
13111 | (char *) field->field_name.str, spider_dbton_oracle.dbton_id))) |
13112 | DBUG_RETURN(error_num); |
13113 | if (key_part->key_part_flag & HA_REVERSE_SORT) |
13114 | { |
13115 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_DESC_LEN + |
13116 | SPIDER_SQL_COMMA_LEN)) |
13117 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13118 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13119 | SPIDER_SQL_NAME_QUOTE_LEN); |
13120 | sql.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); |
13121 | sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
13122 | } else { |
13123 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) |
13124 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13125 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, |
13126 | SPIDER_SQL_NAME_QUOTE_LEN); |
13127 | sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
13128 | } |
13129 | } |
13130 | } |
13131 | sql.length(sql.length() - SPIDER_SQL_COMMA_LEN); |
13132 | } |
13133 | DBUG_RETURN(0); |
13134 | } |
13135 | |
13136 | int spider_oracle_copy_table::append_limit( |
13137 | longlong offset, |
13138 | longlong limit |
13139 | ) { |
13140 | char buf[SPIDER_LONGLONG_LEN + 1]; |
13141 | uint32 length; |
13142 | DBUG_ENTER("spider_oracle_copy_table::append_limit" ); |
13143 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13144 | if (offset || limit < 9223372036854775807LL) |
13145 | { |
13146 | if (!select_rownum_appended) |
13147 | { |
13148 | select_rownum_appended = TRUE; |
13149 | table_name_pos = table_name_pos + pos_diff; |
13150 | if (sql.copy(sql_part)) |
13151 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13152 | pos = pos + pos_diff; |
13153 | } |
13154 | if (offset) |
13155 | { |
13156 | if (sql.reserve(SPIDER_SQL_BETWEEN_LEN + SPIDER_SQL_AND_LEN + |
13157 | ((SPIDER_LONGLONG_LEN) * 2))) |
13158 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13159 | sql.q_append(SPIDER_SQL_BETWEEN_STR, SPIDER_SQL_BETWEEN_LEN); |
13160 | length = (uint32) (my_charset_bin.cset->longlong10_to_str)( |
13161 | &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, offset); |
13162 | sql.q_append(buf, length); |
13163 | sql.q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
13164 | length = (uint32) (my_charset_bin.cset->longlong10_to_str)( |
13165 | &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit); |
13166 | sql.q_append(buf, length); |
13167 | } else { |
13168 | if (sql.reserve(SPIDER_SQL_HS_LTEQUAL_LEN + |
13169 | (SPIDER_LONGLONG_LEN))) |
13170 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13171 | sql.q_append(SPIDER_SQL_HS_LTEQUAL_STR, SPIDER_SQL_HS_LTEQUAL_LEN); |
13172 | length = (uint32) (my_charset_bin.cset->longlong10_to_str)( |
13173 | &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit); |
13174 | sql.q_append(buf, length); |
13175 | } |
13176 | } |
13177 | DBUG_RETURN(0); |
13178 | } |
13179 | |
13180 | int spider_oracle_copy_table::append_into_str() |
13181 | { |
13182 | DBUG_ENTER("spider_oracle_copy_table::append_into_str" ); |
13183 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13184 | if (sql.reserve(SPIDER_SQL_INTO_LEN)) |
13185 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13186 | sql.q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); |
13187 | DBUG_RETURN(0); |
13188 | } |
13189 | |
13190 | int spider_oracle_copy_table::append_open_paren_str() |
13191 | { |
13192 | DBUG_ENTER("spider_oracle_copy_table::append_open_paren_str" ); |
13193 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13194 | if (sql.reserve(SPIDER_SQL_OPEN_PAREN_LEN)) |
13195 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13196 | sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
13197 | DBUG_RETURN(0); |
13198 | } |
13199 | |
13200 | int spider_oracle_copy_table::append_values_str() |
13201 | { |
13202 | DBUG_ENTER("spider_oracle_copy_table::append_values_str" ); |
13203 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13204 | if (sql.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_VALUES_LEN + |
13205 | SPIDER_SQL_OPEN_PAREN_LEN)) |
13206 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13207 | sql.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
13208 | sql.q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); |
13209 | sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
13210 | DBUG_RETURN(0); |
13211 | } |
13212 | |
13213 | int spider_oracle_copy_table::append_select_lock_str( |
13214 | int lock_mode |
13215 | ) { |
13216 | DBUG_ENTER("spider_oracle_copy_table::append_select_lock_str" ); |
13217 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13218 | if (select_rownum_appended) |
13219 | { |
13220 | int error_num; |
13221 | table_lock_mode = lock_mode; |
13222 | sql_part.length(0); |
13223 | if (sql_part.reserve(SPIDER_SQL_LOCK_TABLE_LEN)) |
13224 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13225 | sql_part.q_append(SPIDER_SQL_LOCK_TABLE_STR, SPIDER_SQL_LOCK_TABLE_LEN); |
13226 | if ((error_num = oracle_share->append_table_name(&sql_part, |
13227 | store_link_idx))) |
13228 | DBUG_RETURN(error_num); |
13229 | if (lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) |
13230 | { |
13231 | if (sql_part.reserve(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN)) |
13232 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13233 | sql_part.q_append(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR, |
13234 | SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN); |
13235 | } else if (lock_mode == SPIDER_LOCK_MODE_SHARED) |
13236 | { |
13237 | if (sql_part.reserve(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN)) |
13238 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13239 | sql_part.q_append(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR, |
13240 | SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN); |
13241 | } |
13242 | } else { |
13243 | if (lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) |
13244 | { |
13245 | if (sql.reserve(SPIDER_SQL_FOR_UPDATE_LEN)) |
13246 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13247 | sql.q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); |
13248 | } else if (lock_mode == SPIDER_LOCK_MODE_SHARED) |
13249 | { |
13250 | if (sql.reserve(SPIDER_SQL_FOR_UPDATE_LEN)) |
13251 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13252 | sql.q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); |
13253 | } |
13254 | } |
13255 | DBUG_RETURN(0); |
13256 | } |
13257 | |
13258 | int spider_oracle_copy_table::exec_query( |
13259 | SPIDER_CONN *conn, |
13260 | int quick_mode, |
13261 | int *need_mon |
13262 | ) { |
13263 | int error_num = 0; |
13264 | DBUG_ENTER("spider_oracle_copy_table::exec_query" ); |
13265 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13266 | if (current_str) |
13267 | { |
13268 | spider_string *tmp_str = first_str; |
13269 | while (tmp_str && tmp_str != current_str) |
13270 | { |
13271 | if ( |
13272 | (error_num = spider_db_query(conn, tmp_str->ptr(), tmp_str->length(), |
13273 | quick_mode, need_mon)) && |
13274 | error_num != HA_ERR_FOUND_DUPP_KEY |
13275 | ) { |
13276 | break; |
13277 | } |
13278 | tmp_str = tmp_str->next; |
13279 | } |
13280 | if (tmp_str == current_str) |
13281 | { |
13282 | error_num = spider_db_query(conn, tmp_str->ptr(), tmp_str->length(), |
13283 | quick_mode, need_mon); |
13284 | } |
13285 | if (error_num == HA_ERR_FOUND_DUPP_KEY) |
13286 | error_num = 0; |
13287 | current_str = NULL; |
13288 | } else { |
13289 | if (table_lock_mode) |
13290 | { |
13291 | DBUG_PRINT("info" ,("spider table_lock_mode=%d" , table_lock_mode)); |
13292 | spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; |
13293 | db_conn->table_lock_mode = table_lock_mode; |
13294 | db_conn->exec_lock_sql = &sql_part; |
13295 | table_lock_mode = 0; |
13296 | } |
13297 | error_num = spider_db_query(conn, sql.ptr(), sql.length(), quick_mode, |
13298 | need_mon); |
13299 | } |
13300 | DBUG_RETURN(error_num); |
13301 | } |
13302 | |
13303 | int spider_oracle_copy_table::copy_key_row( |
13304 | spider_db_copy_table *source_ct, |
13305 | Field *field, |
13306 | ulong *row_pos, |
13307 | ulong *length, |
13308 | const char *joint_str, |
13309 | const int joint_length |
13310 | ) { |
13311 | int error_num; |
13312 | spider_string *source_str = &((spider_oracle_copy_table *) source_ct)->sql; |
13313 | DBUG_ENTER("spider_oracle_copy_table::copy_key_row" ); |
13314 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13315 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
13316 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13317 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
13318 | if ((error_num = spider_db_append_name_with_quote_str(&sql, |
13319 | (char *) field->field_name.str, spider_dbton_oracle.dbton_id))) |
13320 | DBUG_RETURN(error_num); |
13321 | if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + joint_length + *length + |
13322 | SPIDER_SQL_AND_LEN)) |
13323 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13324 | sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
13325 | sql.q_append(joint_str, joint_length); |
13326 | sql.q_append(source_str->ptr() + *row_pos, *length); |
13327 | sql.q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); |
13328 | DBUG_RETURN(0); |
13329 | } |
13330 | |
13331 | int spider_oracle_copy_table::copy_row( |
13332 | Field *field, |
13333 | SPIDER_DB_ROW *row |
13334 | ) { |
13335 | int error_num; |
13336 | DBUG_ENTER("spider_oracle_copy_table::copy_row" ); |
13337 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13338 | if (row->is_null()) |
13339 | { |
13340 | DBUG_PRINT("info" ,("spider column is null" )); |
13341 | if (current_str->reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) |
13342 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13343 | current_str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); |
13344 | } else if (field->str_needs_quotes()) |
13345 | { |
13346 | DBUG_PRINT("info" ,("spider str_needs_quotes" )); |
13347 | if (current_str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) |
13348 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13349 | current_str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, |
13350 | SPIDER_SQL_VALUE_QUOTE_LEN); |
13351 | if ((error_num = row->append_escaped_to_str(current_str, |
13352 | spider_dbton_oracle.dbton_id))) |
13353 | DBUG_RETURN(error_num); |
13354 | if (current_str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN + |
13355 | SPIDER_SQL_COMMA_LEN)) |
13356 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13357 | current_str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, |
13358 | SPIDER_SQL_VALUE_QUOTE_LEN); |
13359 | } else { |
13360 | DBUG_PRINT("info" ,("spider without_quotes" )); |
13361 | if ((error_num = row->append_to_str(current_str))) |
13362 | DBUG_RETURN(error_num); |
13363 | if (current_str->reserve(SPIDER_SQL_COMMA_LEN)) |
13364 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13365 | } |
13366 | current_str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
13367 | DBUG_RETURN(0); |
13368 | } |
13369 | |
13370 | int spider_oracle_copy_table::copy_rows( |
13371 | TABLE *table, |
13372 | SPIDER_DB_ROW *row, |
13373 | ulong **last_row_pos, |
13374 | ulong **last_lengths |
13375 | ) { |
13376 | int error_num; |
13377 | Field **field; |
13378 | ulong *lengths2, *row_pos2; |
13379 | DBUG_ENTER("spider_oracle_copy_table::copy_rows" ); |
13380 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13381 | if (!current_str) |
13382 | { |
13383 | if (!first_str) |
13384 | { |
13385 | if (!(first_str = new spider_string[1])) |
13386 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13387 | first_str->init_calc_mem(216); |
13388 | first_str->set_charset(sql.charset()); |
13389 | if (first_str->reserve(sql.length())) |
13390 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13391 | first_str->q_append(sql.ptr(), sql.length()); |
13392 | } else { |
13393 | first_str->length(sql.length()); |
13394 | } |
13395 | current_str = first_str; |
13396 | } else { |
13397 | if (!current_str->next) |
13398 | { |
13399 | if (!(current_str->next = new spider_string[1])) |
13400 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13401 | current_str->next->init_calc_mem(217); |
13402 | current_str->next->set_charset(sql.charset()); |
13403 | if (current_str->next->reserve(sql.length())) |
13404 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13405 | current_str->next->q_append(sql.ptr(), sql.length()); |
13406 | } else { |
13407 | current_str->next->length(sql.length()); |
13408 | } |
13409 | current_str = current_str->next; |
13410 | } |
13411 | row_pos2 = *last_row_pos; |
13412 | lengths2 = *last_lengths; |
13413 | |
13414 | for ( |
13415 | field = table->field; |
13416 | *field; |
13417 | field++, |
13418 | lengths2++ |
13419 | ) { |
13420 | *row_pos2 = current_str->length(); |
13421 | if ((error_num = |
13422 | copy_row(*field, row))) |
13423 | DBUG_RETURN(error_num); |
13424 | *lengths2 = current_str->length() - *row_pos2 - SPIDER_SQL_COMMA_LEN; |
13425 | row->next(); |
13426 | row_pos2++; |
13427 | } |
13428 | current_str->length(current_str->length() - SPIDER_SQL_COMMA_LEN); |
13429 | if (current_str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) |
13430 | { |
13431 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13432 | } |
13433 | current_str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
13434 | SPIDER_SQL_CLOSE_PAREN_LEN); |
13435 | DBUG_PRINT("info" ,("spider current_str=%s" , current_str->c_ptr_safe())); |
13436 | DBUG_RETURN(0); |
13437 | } |
13438 | |
13439 | int spider_oracle_copy_table::copy_rows( |
13440 | TABLE *table, |
13441 | SPIDER_DB_ROW *row |
13442 | ) { |
13443 | int error_num; |
13444 | Field **field; |
13445 | DBUG_ENTER("spider_oracle_copy_table::copy_rows" ); |
13446 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13447 | if (!current_str) |
13448 | { |
13449 | if (!first_str) |
13450 | { |
13451 | if (!(first_str = new spider_string[1])) |
13452 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13453 | first_str->init_calc_mem(218); |
13454 | first_str->set_charset(sql.charset()); |
13455 | if (first_str->reserve(sql.length())) |
13456 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13457 | first_str->q_append(sql.ptr(), sql.length()); |
13458 | } else { |
13459 | first_str->length(sql.length()); |
13460 | } |
13461 | current_str = first_str; |
13462 | } else { |
13463 | if (!current_str->next) |
13464 | { |
13465 | if (!(current_str->next = new spider_string[1])) |
13466 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13467 | current_str->next->init_calc_mem(219); |
13468 | current_str->next->set_charset(sql.charset()); |
13469 | if (current_str->next->reserve(sql.length())) |
13470 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13471 | current_str->next->q_append(sql.ptr(), sql.length()); |
13472 | } else { |
13473 | current_str->next->length(sql.length()); |
13474 | } |
13475 | current_str = current_str->next; |
13476 | } |
13477 | |
13478 | for ( |
13479 | field = table->field; |
13480 | *field; |
13481 | field++ |
13482 | ) { |
13483 | if ((error_num = |
13484 | copy_row(*field, row))) |
13485 | DBUG_RETURN(error_num); |
13486 | row->next(); |
13487 | } |
13488 | current_str->length(current_str->length() - SPIDER_SQL_COMMA_LEN); |
13489 | if (current_str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) |
13490 | { |
13491 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13492 | } |
13493 | current_str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
13494 | SPIDER_SQL_CLOSE_PAREN_LEN); |
13495 | DBUG_PRINT("info" ,("spider current_str=%s" , current_str->c_ptr_safe())); |
13496 | DBUG_RETURN(0); |
13497 | } |
13498 | |
13499 | int spider_oracle_copy_table::append_insert_terminator() |
13500 | { |
13501 | DBUG_ENTER("spider_oracle_copy_table::append_insert_terminator" ); |
13502 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13503 | DBUG_RETURN(0); |
13504 | } |
13505 | |
13506 | int spider_oracle_copy_table::copy_insert_values( |
13507 | spider_db_copy_table *source_ct |
13508 | ) { |
13509 | spider_oracle_copy_table *tmp_ct = (spider_oracle_copy_table *) source_ct; |
13510 | spider_string *source_str = &tmp_ct->sql; |
13511 | int values_length = source_str->length() - tmp_ct->pos; |
13512 | const char *values_ptr = source_str->ptr() + tmp_ct->pos; |
13513 | DBUG_ENTER("spider_oracle_copy_table::copy_insert_values" ); |
13514 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
13515 | if (sql.reserve(values_length)) |
13516 | { |
13517 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
13518 | } |
13519 | sql.q_append(values_ptr, values_length); |
13520 | DBUG_RETURN(0); |
13521 | } |
13522 | #endif |
13523 | |