xlang v5.1 Release
程序设计语言基础库文档
载入中...
搜索中...
未找到
Mysql.xcsm
浏览该文件的文档.
1//xlang Source, Name:Mysql.xcsm
2//Date: Tue Jul 16:06:32 2019
3
4class Mysql : Sql.Connection {
5 public static const int CLIENT_LONG_PASSWORD = 1; /* new more secure passwords */
6 public static const int CLIENT_FOUND_ROWS = 2; /* Found instead of affected rows */
7 public static const int CLIENT_LONG_FLAG = 4; /* Get all column flags */
8 public static const int CLIENT_CONNECT_WITH_DB = 8; /* One can specify db on connect */
9 public static const int CLIENT_NO_SCHEMA = 16; /* Don't allow database.table.column */
10 public static const int CLIENT_COMPRESS = 32; /* Can use compression protocol */
11 public static const int CLIENT_ODBC = 64; /* Odbc client */
12 public static const int CLIENT_LOCAL_FILES = 128; /* Can use LOAD DATA LOCAL */
13 public static const int CLIENT_IGNORE_SPACE = 256; /* Ignore spaces before '(' */
14 public static const int CLIENT_PROTOCOL_41 = 512; /* New 4.1 protocol */
15 public static const int CLIENT_INTERACTIVE = 1024; /* This is an interactive client */
16 public static const int CLIENT_SSL = 2048; /* Switch to SSL after handshake */
17 public static const int CLIENT_IGNORE_SIGPIPE = 4096; /* IGNORE sigpipes */
18 public static const int CLIENT_TRANSACTIONS = 8192; /* Client knows about transactions */
19 public static const int CLIENT_RESERVED = 16384; /* Old flag for 4.1 protocol */
20 public static const int CLIENT_RESERVED2 = 32768; /* Old flag for 4.1 authentication */
21 public static const int CLIENT_MULTI_STATEMENTS = (1 << 16); /* Enable/disable multi-stmt support */
22 public static const int CLIENT_MULTI_RESULTS = (1 << 17); /* Enable/disable multi-results */
23 public static const int CLIENT_PS_MULTI_RESULTS = (1 << 18); /* Multi-results in PS-protocol */
24
25 public static const int CLIENT_PLUGIN_AUTH = (1 << 19); /* Client supports plugin authentication */
26 public static const int CLIENT_CONNECT_ATTRS = (1 << 20); /* Client supports connection attributes */
27
28 /* Enable authentication response packet to be larger than 255 bytes. */
29 public static const int CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA = (1 << 21);
30
31 /* Don't close the connection for a connection with expired password. */
32 public static const int CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = (1 << 22);
33
38 public static const int CLIENT_SESSION_TRACK = (1 << 23);
39 /* Client no longer needs EOF packet */
40 public static const int CLIENT_DEPRECATE_EOF = (1 << 24);
41
42 public static const int CLIENT_SSL_VERIFY_SERVER_CERT = (1 << 30);
43 public static const int CLIENT_REMEMBER_OPTIONS = (1 << 31);
44
45
46
47 /* Gather all possible capabilites (flags) supported by the server */
48 public static const int CLIENT_ALL_FLAGS = (CLIENT_LONG_PASSWORD
75 );
76
77 /*
78 Switch off the flags that are optional and depending on build flags
79 If any of the optional flags is supported by the build it will be switched
80 on before sending to the client during the connection handshake.
81 */
82 public static const int CLIENT_BASIC_FLAGS = ( ( (CLIENT_ALL_FLAGS & ~CLIENT_SSL)
84 & ~CLIENT_SSL_VERIFY_SERVER_CERT);
85
86 static const String DRIVERNAME = "mysql";
87 byte [] _mysql ;
88
89 int port = 3306;
90 int timeout = 0;
91 int return_option = MysqlOption.RET_ERRCODE;
92 int client_flags = 0;
93
94 public enum MysqlOption {
101 CLIENT_FLAGS
102 };
103
104 static class MysqlRegister : Sql.ConnectionRegister {
105 Sql.Connection allocConnection (String drivername) override {
106 if (drivername.equals ("mysql") ) {
107 return new Mysql();
108 }
109
110 return nilptr;
111 }
112 };
113
114 public static bool registry() {
115 if (Helper.init() ) {
116 Sql.Database.reigstry (DRIVERNAME, new MysqlRegister() );
117 return true;
118 }
119
120 return false;
121 }
122
123 static class Helper : Library {
124 static bool bloaded = false;
125
126 public static bool init() {
127 if (bloaded == false) {
128 try {
129 loadLibrary ("mysql_helper");
130 bloaded = true;
131 } catch (Exception e) {
132 _system_.output (e.getMessage() );
133 }
134 }
135
136 return bloaded;
137 }
138
139 public import {
140 Pointer cdecl rs_create (Pointer);
141 void cdecl rs_free (Pointer);
142 bool cdecl rs_next (Pointer);
143 bool cdecl rs_first (Pointer);
144 int cdecl rs_label2Index (Pointer, String);
145 long cdecl rs_getRowCount (Pointer);
146 bool cdecl rs_last (Pointer);
147 bool cdecl rs_isValid (Pointer);
148 bool cdecl statement_res_isValid (Pointer);
149 bool cdecl rs_isLast (Pointer);
150 bool cdecl next_statement_res_4x (Pointer);
151
152 String cdecl rs_getValue (Pointer, String);
153 int cdecl rs_getValueI (Pointer, String);
154 long cdecl rs_getValueL (Pointer, String);
155 double cdecl rs_getValueD (Pointer, String);
156
157 String cdecl rs_getIValue (Pointer, int);
158 int cdecl rs_getIValueI (Pointer, int);
159 long cdecl rs_getIValueL (Pointer, int);
160 double cdecl rs_getIValueD (Pointer, int);
161
162 String cdecl stmt_getValue (Pointer, String);
163 int cdecl stmt_getValueI (Pointer, String);
164 long cdecl stmt_getValueL (Pointer, String);
165 double cdecl stmt_getValueD (Pointer, String);
166
167 String cdecl stmt_getIValue (Pointer, int);
168 int cdecl stmt_getIValueI (Pointer, int);
169 long cdecl stmt_getIValueL (Pointer, int);
170 double cdecl stmt_getIValueD (Pointer, int);
171
172
173 Pointer cdecl x_mysql_init (ObjectPtr );
174
175 int cdecl x_mysql_options (ObjectPtr, int option, ObjectPtr );
176
177 Pointer cdecl x_mysql_real_connect (ObjectPtr, String host,
178 String user,
179 String passwd,
180 String db,
181 int port,
182 String unix_socket,
183 int clientflag);
184
185 int cdecl x_mysql_set_character_set (ObjectPtr, String csname);
186
187 int cdecl x_mysql_select_db (ObjectPtr, String db);
188 int cdecl stmt_column_type (Pointer, int);
189 int cdecl stmt_find_column (Pointer, String key);
190 String cdecl stmt_get_column (Pointer, int id);
191 long cdecl create_statement_4x (ObjectPtr);
192 long cdecl store_statement_res_4x (Pointer);
193 long cdecl stmt_row_count (Pointer);
194 bool cdecl close_statement_4x (Pointer);
195 bool cdecl bind_statement_param_4x (Pointer, int n, ObjectPtr data, int len, int type);
196 bool cdecl reset_statement_4x (Pointer);
197 int cdecl statement__prepare_4x (Pointer, String sql, int len);
199 long cdecl get_lastinserted_id_4x (ObjectPtr);
200 long cdecl get_affected_rows_4x (ObjectPtr);
201 long cdecl stmt_lastinserted_id_4x (Pointer);
202 long cdecl stmt_affected_rows_4x (Pointer);
203 int cdecl statement_execute_4x (Pointer);
204
205 int cdecl x_mysql_errno (ObjectPtr );
206 String cdecl x_mysql_info (ObjectPtr );
207 String cdecl x_mysql_state (ObjectPtr );
208 String cdecl x_mysql_error (ObjectPtr );
209
210 int cdecl x_mysql_query (ObjectPtr, String );
211
212 void cdecl x_mysql_close (ObjectPtr);
213
214 Pointer cdecl x_mysql_store_result (ObjectPtr);
215
216 void cdecl x_mysql_data_seek (Pointer result,
217 long offset);
218
219 Pointer cdecl x_mysql_row_seek (Pointer result,
220 long offset);
221
222 Pointer cdecl x_mysql_row_tell (Pointer res);
223
224 Pointer cdecl x_mysql_fetch_row (Pointer result);
225
226 long cdecl x_mysql_num_rows (Pointer res);
227
228 void cdecl x_mysql_free_result (Pointer result);
229
230 int cdecl x_mysql_num_fields (Pointer res);
231 };
232 };
233
234 static bool registried = registry();
235
236 public static class MysqlResultSet : Sql.ResultSet {
237 long hres;
238
239 public MysqlResultSet (long r) {
240 hres = Helper.rs_create (r);
241 }
242
243 public bool first() override {
244 return Helper.rs_first (hres);
245 }
246
247 public bool last() override {
248 return Helper.rs_last (hres);
249 }
250
251 public bool next() override {
252 return Helper.rs_next (hres);
253 }
254
255 public bool isEof() override {
256 throw new Sql.DatabaseNotSupportException ("isEof");
257 return false;
258 }
259
260 public bool previous() override {
261 throw new Sql.DatabaseNotSupportException ("previous");
262 return false;
263 }
264
265 public bool isFirst() override {
266 throw new Sql.DatabaseNotSupportException ("isFirst");
267 return false;
268 }
269
270 public bool isLast() override {
271 return Helper.rs_isLast (hres);
272 }
273
274 public bool isValid() override {
275 return Helper.rs_isValid (hres);
276 }
277
278 public int getInt (String columnlabel) override {
279 return Helper.rs_getValueI (hres, columnlabel);
280 }
281
282 public long getLong (String columnlabel) override {
283 return Helper.rs_getValueL (hres, columnlabel);
284 }
285
286 public float getFloat(String columnlabel) override {
287 return getString(columnlabel).parseFloat();
288 }
289
290 public double getDouble (String columnlabel) override {
291 return Helper.rs_getValueD (hres, columnlabel);
292 }
293
294 public byte getByte (String columnlabel) override {
295 return Helper.rs_getValueI (hres, columnlabel);
296 }
297
298 public bool getBoolean (String columnlabel) override {
299 return Helper.rs_getValueI (hres, columnlabel) != 0;
300 }
301
302 public String getString (String columnlabel) override {
303 return Helper.rs_getValue (hres, columnlabel);
304 }
305
306 public int getInt (int columnIndex) override {
307 return Helper.rs_getIValueI (hres, columnIndex);
308 }
309
310 public long getLong (int columnIndex) override {
311 return Helper.rs_getIValueL (hres, columnIndex);
312 }
313
314 public double getDouble (int columnIndex) override {
315 return Helper.rs_getIValueD (hres, columnIndex);
316 }
317
318 public float getFloat(int columnIndex) override {
319 return getString(columnIndex).parseFloat();
320 }
321
322 public byte getByte (int columnIndex) override {
323 return Helper.rs_getIValueI (hres, columnIndex);
324 }
325
326 public bool getBoolean (int columnIndex) override {
327 return Helper.rs_getIValueI (hres, columnIndex) != 0;
328 }
329
330 public String getString (int columnIndex) override {
331 return Helper.rs_getIValue (hres, columnIndex);
332 }
333
334 public int findColumn (String) override {
335 throw new Sql.DatabaseNotSupportException ("findColumn");
336 return -1;
337 }
338
339 public String getColumnName (int i) override {
340 throw new Sql.DatabaseNotSupportException ("getColumnName");
341 return nilptr;
342 }
343
344 public int getColumnCount() override {
345 throw new Sql.DatabaseNotSupportException ("getColumnCount");
346 return -1;
347 }
348
349 public long getRowCount() override {
350 return Helper.rs_getRowCount (hres);
351 }
352
353 public int getRow() override {
354 throw new Sql.DatabaseNotSupportException ("getRow");
355 return 0;
356 }
357
358 public void close() override {
359 if (hres != 0) {
360 Helper.rs_free (hres);
361 hres = 0;
362 }
363 }
364
365 void finalize() {
366 close();
367 }
368 };
369
370 public static class MysqlStatement : Sql.Statement {
372
374 mysql = m;
375 }
376
377 public int execute (String sql) override {
378 if (0 != Helper.x_mysql_query (mysql._mysql, sql) ) {
379 throw new Sql.SqlException (mysql.getErrorCode(), mysql.getError() );
380 }
381
382 if (mysql.return_option == MysqlOption.RET_CHANGES) {
383 return Helper.get_affected_rows_4x (mysql._mysql);
384 }
385
386 return 0;
387 }
388
389 public Sql.ResultSet executeQuery (String sql) override {
390 if (0 != Helper.x_mysql_query (mysql._mysql, sql) ) {
391 throw new Sql.SqlException (mysql.getErrorCode(), mysql.getError() );
392 }
393
394 return getResult();
395 }
396
397 public int executeUpdate (String sql) override {
398 if (0 != Helper.x_mysql_query (mysql._mysql, sql) ) {
399 throw new Sql.SqlException (mysql.getErrorCode(), mysql.getError() );
400 }
401
402 if (mysql.return_option == MysqlOption.RET_CHANGES) {
403 return Helper.get_affected_rows_4x (mysql._mysql);
404 }
405
406 return 0;
407 }
408
409 public Sql.ResultSet getResult() override {
410 long res = Helper.x_mysql_store_result (mysql._mysql);
411
412 if (res != 0) {
413 return new MysqlResultSet (res);
414 }
415
416 return nilptr;
417 }
418
419 public int get_changes() override {
420 return Helper.get_affected_rows_4x (mysql._mysql);
421 }
422
423 public int get_lastInsertId() override {
424 return Helper.get_lastinserted_id_4x (mysql._mysql);
425 }
426
427 public void close() override {
428
429 }
430 };
431
432
433
434 public static class MysqlPreparedResultSet : Sql.ResultSet {
435 long hres;
437 int field_count = 0;
439 stmt = _stmt;
440 hres = r;
441 field_count = Helper.store_statement_res_4x (r);
442 }
443
444 public bool first() override {
445 throw new Sql.DatabaseNotSupportException ("first");
446 return false;
447 }
448
449 public bool last() override {
450 throw new Sql.DatabaseNotSupportException ("last");
451 return false;
452 }
453
454 public bool next() override {
455 return Helper.next_statement_res_4x (hres);
456 }
457
458 public bool isEof() override {
459 throw new Sql.DatabaseNotSupportException ("isEof");
460 return false;
461 }
462
463 public bool previous() override {
464 throw new Sql.DatabaseNotSupportException ("previous");
465 return false;
466 }
467
468 public bool isFirst() override {
469 throw new Sql.DatabaseNotSupportException ("isFirst");
470 return false;
471 }
472
473 public bool isLast() override {
474 throw new Sql.DatabaseNotSupportException ("isLast");
475 return false;
476 }
477
478 public bool isValid() override {
479 return Helper.rs_isValid (hres);
480 }
481
482 public int getInt (String columnlabel) override {
483 return Helper.stmt_getValueI (hres, columnlabel);
484 }
485
486 public long getLong (String columnlabel) override {
487 return Helper.stmt_getValueL (hres, columnlabel);
488 }
489
490 public float getFloat(String columnlabel) override {
491 return getString(columnlabel).parseFloat();
492 }
493
494 public double getDouble (String columnlabel) override {
495 return Helper.stmt_getValueD (hres, columnlabel);
496 }
497
498 public byte getByte (String columnlabel) override {
499 return Helper.stmt_getValueI (hres, columnlabel);
500 }
501
502 public bool getBoolean (String columnlabel) override {
503 return Helper.stmt_getValueI (hres, columnlabel) != 0;
504 }
505
506 public String getString (String columnlabel) override {
507 return Helper.stmt_getValue (hres, columnlabel);
508 }
509
510 public int getInt (int columnIndex) override {
511 return Helper.stmt_getIValueI (hres, columnIndex);
512 }
513
514 public long getLong (int columnIndex) override {
515 return Helper.stmt_getIValueL (hres, columnIndex);
516 }
517
518 public float getFloat(int columnIndex) override {
519 return getString(columnIndex).parseFloat();
520 }
521
522 public double getDouble (int columnIndex) override {
523 return Helper.stmt_getIValueD (hres, columnIndex);
524 }
525
526 public byte getByte (int columnIndex) override {
527 return Helper.stmt_getIValueI (hres, columnIndex);
528 }
529
530 public bool getBoolean (int columnIndex) override {
531 return Helper.stmt_getIValueI (hres, columnIndex) != 0;
532 }
533
534 public String getString (int columnIndex) override {
535 return Helper.stmt_getIValue (hres, columnIndex);
536 }
537
538 public int findColumn (String name) override {
539 return Helper.stmt_find_column (hres, name);
540 }
541
542 public String getColumnName (int i) override {
543 return Helper.stmt_get_column (hres, i - 1);
544 }
545
546 public int getColumnCount() override {
547 return field_count;
548 }
549
550 public long getRowCount() override {
551 return Helper.stmt_row_count (hres);
552 }
553
554 public int getRow() override {
555 throw new Sql.DatabaseNotSupportException ("getRow");
556 return 0;
557 }
558
559 public void close() override {
560 if (stmt != nilptr) {
561 stmt = nilptr;
562 hres = 0;
563 }
564 }
565
566 public int getColumnType (int id) override {
567 if (id > 0 && id < (field_count + 1) ) {
568 return Helper.stmt_column_type (hres, id - 1);
569 } else {
570 throw new Sql.SqlException (-1, "out of argc ");
571 }
572
573 return 0;
574 }
575
576 void finalize() {
577 close();
578 }
579 };
580
581 public class MysqlPreparedStatement : Sql.PreparedStatement {
584 int param_index = 0;
585
586 int argc = 0;
588 mysql = m;
589 hprepare_handle = Helper.create_statement_4x (m._mysql);
590
591 if (hprepare_handle != 0) {
592 argc = Helper.statement__prepare_4x (hprepare_handle, sql, sql.length() );
593
594 } else {
595 throw new Sql.SqlException (mysql.getErrorCode(), mysql.getError() );
596 }
597 }
598 public int execute() override {
599 if (0 != Helper.statement_execute_4x (hprepare_handle) ) {
600 throw new Sql.SqlException (mysql.getErrorCode(), Helper.get_statement_error_4x (hprepare_handle) );
601 }
602
603 if (mysql.return_option == MysqlOption.RET_CHANGES) {
604 return Helper.stmt_affected_rows_4x (hprepare_handle);
605 }
606
607 return 0;
608 }
609
610 public Sql.ResultSet executeQuery() override {
611 if (0 != Helper.statement_execute_4x (hprepare_handle) ) {
612 throw new Sql.SqlException (mysql.getErrorCode(), Helper.get_statement_error_4x (hprepare_handle) );
613 }
614
615 return new MysqlPreparedResultSet (this, hprepare_handle);
616 }
617
618 public int execute (String sql) override {
619 if (0 != Helper.x_mysql_query (mysql._mysql, sql) ) {
620 throw new Sql.SqlException (mysql.getErrorCode(), mysql.getError() );
621 }
622
623 if (mysql.return_option == MysqlOption.RET_CHANGES) {
624 return Helper.get_affected_rows_4x (mysql._mysql);
625 }
626
627 return 0;
628 }
629
630 public Sql.ResultSet executeQuery (String sql) override {
631 if (0 != Helper.x_mysql_query (mysql._mysql, sql) ) {
632 throw new Sql.SqlException (mysql.getErrorCode(), mysql.getError() );
633 }
634
635 return getResult();
636 }
637 public int executeUpdate() override {
638 if (0 != Helper.statement_execute_4x (hprepare_handle) ) {
639 throw new Sql.SqlException (mysql.getErrorCode(), Helper.get_statement_error_4x (hprepare_handle) );
640 }
641
642 if (mysql.return_option == MysqlOption.RET_CHANGES) {
643 return Helper.stmt_affected_rows_4x (hprepare_handle);
644 }
645
646 return 0;
647 }
648 public int executeUpdate (String sql) override {
649 if (0 != Helper.x_mysql_query (mysql._mysql, sql) ) {
650 throw new Sql.SqlException (mysql.getErrorCode(), mysql.getError() );
651 }
652
653 if (mysql.return_option == MysqlOption.RET_CHANGES) {
654 return Helper.get_affected_rows_4x (mysql._mysql);
655 }
656
657 return 0;
658 }
659
660 public Sql.ResultSet getResult() override {
661 long res = Helper.x_mysql_store_result (mysql._mysql);
662
663 if (res != 0) {
664 return new MysqlResultSet (res);
665 }
666
667 return nilptr;
668 }
669
670 public void setValue (String value) override {
671 if (param_index < argc) {
672 if (value == nilptr) {
673 if (!Helper.bind_statement_param_4x (hprepare_handle, param_index++, value, 0, 0xf) ) {
674 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
675 }
676 } else {
677 if (!Helper.bind_statement_param_4x (hprepare_handle, param_index++, value, value.length(), 0) ) {
678 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
679 }
680 }
681 } else {
682 throw new Sql.SqlException (-1, "out of argc value:" + value);
683 }
684 }
685
686 public void setValue (int value) override {
687 if (param_index < argc) {
688 if (!Helper.bind_statement_param_4x (hprepare_handle, param_index++, value, 0, 1) ) {
689 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
690 }
691 } else {
692 throw new Sql.SqlException (-1, "out of argc value:" + value);
693 }
694 }
695
696 public void setValue (long value) override {
697 if (param_index < argc) {
698 if (!Helper.bind_statement_param_4x (hprepare_handle, param_index++, value, 0, 2) ) {
699 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
700 }
701 } else {
702 throw new Sql.SqlException (-1, "out of argc value:" + value);
703 }
704 }
705
706 public void setValue (byte value) override {
707 if (param_index < argc) {
708 if (!Helper.bind_statement_param_4x (hprepare_handle, param_index++, value, 0, 3) ) {
709 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
710 }
711 } else {
712 throw new Sql.SqlException (-1, "out of argc value:" + value);
713 }
714 }
715
716 public void setValue (double value) override {
717 if (param_index < argc) {
718 if (!Helper.bind_statement_param_4x (hprepare_handle, param_index++, value, 0, 4) ) {
719 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
720 }
721 } else {
722 throw new Sql.SqlException (-1, "out of argc value:" + value);
723 }
724 }
725
726
727 public void setValue (int id, String value) override {
728 if (id > 0 && id < (argc + 1) ) {
729 if (value == nilptr) {
730 if (!Helper.bind_statement_param_4x (hprepare_handle, id - 1, nilptr, 0, 0xf) ) {
731 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
732 }
733 } else {
734 if (!Helper.bind_statement_param_4x (hprepare_handle, id - 1, value, value.length(), 0) ) {
735 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
736 }
737 }
738 } else {
739 throw new Sql.SqlException (-1, "out of argc value:" + value);
740 }
741 }
742
743 public void setValue (int id, int value) override {
744 if (id > 0 && id < (argc + 1) ) {
745 if (!Helper.bind_statement_param_4x (hprepare_handle, id - 1, value, 0, 1) ) {
746 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
747 }
748 } else {
749 throw new Sql.SqlException (-1, "out of argc value:" + value);
750 }
751 }
752
753 public void setValue (int id, long value) override {
754 if (id > 0 && id < (argc + 1) ) {
755 if (!Helper.bind_statement_param_4x (hprepare_handle, id - 1, value, 0, 2) ) {
756 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
757 }
758 } else {
759 throw new Sql.SqlException (-1, "out of argc value:" + value);
760 }
761 }
762
763 public void setValue (int id, byte value) override {
764 if (id > 0 && id < (argc + 1) ) {
765 if (!Helper.bind_statement_param_4x (hprepare_handle, id - 1, value, 0, 3) ) {
766 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
767 }
768 } else {
769 throw new Sql.SqlException (-1, "out of argc value:" + value);
770 }
771 }
772
773 public void setValue (int id, double value) override {
774 if (id > 0 && id < (argc + 1) ) {
775 if (!Helper.bind_statement_param_4x (hprepare_handle, id - 1, value, 0, 4) ) {
776 throw new Sql.SqlException (-1, Helper.get_statement_error_4x (hprepare_handle) );
777 }
778 } else {
779 throw new Sql.SqlException (-1, "out of argc value:" + value);
780 }
781 }
782
783
784 public void setValues (Object [] args) override {
785 for (int i = 0; i < args.length; i++) {
786 if (args[i] == nilptr) {
787 setValue ( (String) nilptr);
788 } else if (args[i].instanceOf (String) ) {
789 setValue ( (String) args[i]);
790 } else if (args[i].instanceOf (int) ) {
791 setValue ( (int) args[i]);
792 } else if (args[i].instanceOf (long) ) {
793 setValue ( (long) args[i]);
794 } else if (args[i].instanceOf (byte) ) {
795 setValue ( (byte) args[i]);
796 } else if (args[i].instanceOf (double) ) {
797 setValue ( (double) args[i]);
798 } else {
799 throw new Sql.SqlException (-1, "sql unknow type:" + i);
800 }
801 }
802 }
803
804 public int get_changes() override {
805 return Helper.stmt_affected_rows_4x (hprepare_handle);
806 }
807
808 public int get_lastInsertId() override {
809 return Helper.stmt_lastinserted_id_4x (hprepare_handle);
810 }
811
812 public void close() override {
813 if (hprepare_handle != 0) {
814 Helper.close_statement_4x (hprepare_handle);
815 hprepare_handle = 0;
816 }
817 }
818 };
819
820
821 public void close() override {
822 //TODO:
823 if (_mysql != nilptr) {
824 Helper.x_mysql_close (_mysql);
825 _mysql = nilptr;
826 }
827 }
828
829 void finalize() {
830 close();
831 }
832
833 public void create (String uri, String username, String pwd) override {
834 //TODO:
835 byte [] __mysql = new byte[2048];
836
837
838 if (0l == Helper.x_mysql_init (__mysql) ) {
839 throw new Sql.SqlException (Helper.x_mysql_errno (__mysql), Helper.x_mysql_error (__mysql) );
840 }
841
842 if (timeout != 0) {
843 if (0 == Helper.x_mysql_options (__mysql, 0, timeout) ) {
844 throw new Sql.SqlException (Helper.x_mysql_errno (__mysql), Helper.x_mysql_error (__mysql) );
845 }
846 }
847
848 if (0l == Helper.x_mysql_real_connect (__mysql, uri, username, pwd, nilptr, port, nilptr, client_flags) ) {
849 throw new Sql.SqlException (Helper.x_mysql_errno (__mysql), Helper.x_mysql_error (__mysql) );
850 }
851
852 _mysql = __mysql;
853 }
854
855 public bool isClosed() override {
856 //TODO:
857 return _mysql != nilptr;
858 }
859
860
861 public int getErrorCode() override {
862 return Helper.x_mysql_errno (_mysql);
863 }
864
865 public String getError() override {
866 return Helper.x_mysql_error (_mysql);
867 }
868
870 return Helper.x_mysql_state (_mysql);
871 }
872
873 public String getInfo() {
874 return Helper.x_mysql_info (_mysql);
875 }
876
877 public Object getOption (int opt) override {
878 //TODO:
879 throw new Sql.DatabaseNotSupportException ("getOption");
880 return nilptr;
881 }
882
883 public void setOption (int opt, Object option) override {
884 switch (opt) {
885 case MysqlOption.PORT:
886 port = (int) option;
887 break;
888
889 case MysqlOption.TIMEOUT:
890 timeout = (int) option;
891 break;
892
893 case MysqlOption.CHARSET:
894 if (_mysql == nilptr) {
895 throw new Sql.SqlException (-1, "mysql not connected!");
896 }
897
898 if (0 != Helper.x_mysql_set_character_set (_mysql, (String) option) ) {
899 throw new Sql.SqlException (Helper.x_mysql_errno (_mysql), Helper.x_mysql_error (_mysql) );
900 }
901
902 break;
903
904 case MysqlOption.SELECTDB:
905 if (_mysql == nilptr) {
906 throw new Sql.SqlException (-1, "mysql not connected!");
907 }
908
909 if (0 != Helper.x_mysql_select_db (_mysql, (String) option) ) {
910 throw new Sql.SqlException (Helper.x_mysql_errno (_mysql), Helper.x_mysql_error (_mysql) );
911 }
912
913 break;
914
915 case MysqlOption.RET_ERRCODE:
916 return_option = MysqlOption.RET_ERRCODE;
917 break;
918
919 case MysqlOption.RET_CHANGES:
920 return_option = MysqlOption.RET_CHANGES;
921 break;
922
923 case MysqlOption.CLIENT_FLAGS:
924 client_flags = (int) option;
925 break;
926
927 default:
928 throw new Sql.DatabaseNotSupportException ("setOption:" + opt);
929 break;
930 }
931 }
932
933 public Sql.Statement createStatement() override {
934 return new MysqlStatement (this);
935 }
936
938 return new MysqlPreparedStatement (this, sql);
939 }
940
941
942};
final String getMessage()
static final void loadLibrary(String)
long cdecl stmt_affected_rows_4x(Pointer)
long cdecl stmt_getIValueL(Pointer, int)
void cdecl x_mysql_close(ObjectPtr)
int cdecl stmt_find_column(Pointer, String key)
int cdecl x_mysql_options(ObjectPtr, int option, ObjectPtr )
long cdecl create_statement_4x(ObjectPtr)
Pointer cdecl x_mysql_row_seek(Pointer result, long offset)
void cdecl rs_free(Pointer)
int cdecl statement_execute_4x(Pointer)
bool cdecl next_statement_res_4x(Pointer)
long cdecl rs_getIValueL(Pointer, int)
int cdecl x_mysql_errno(ObjectPtr )
void cdecl x_mysql_data_seek(Pointer result, long offset)
int cdecl stmt_column_type(Pointer, int)
double cdecl stmt_getIValueD(Pointer, int)
Pointer cdecl x_mysql_real_connect(ObjectPtr, String host, String user, String passwd, String db, int port, String unix_socket, int clientflag)
bool cdecl close_statement_4x(Pointer)
void cdecl x_mysql_free_result(Pointer result)
String cdecl rs_getIValue(Pointer, int)
int cdecl rs_getIValueI(Pointer, int)
long cdecl rs_getValueL(Pointer, String)
long cdecl stmt_getValueL(Pointer, String)
long cdecl get_lastinserted_id_4x(ObjectPtr)
long cdecl x_mysql_num_rows(Pointer res)
int cdecl x_mysql_set_character_set(ObjectPtr, String csname)
String cdecl x_mysql_state(ObjectPtr )
double cdecl stmt_getValueD(Pointer, String)
long cdecl store_statement_res_4x(Pointer)
double cdecl rs_getValueD(Pointer, String)
String cdecl x_mysql_error(ObjectPtr )
int cdecl stmt_getValueI(Pointer, String)
String cdecl stmt_get_column(Pointer, int id)
long cdecl rs_getRowCount(Pointer)
int cdecl rs_getValueI(Pointer, String)
bool cdecl rs_first(Pointer)
long cdecl get_affected_rows_4x(ObjectPtr)
bool cdecl rs_next(Pointer)
bool cdecl reset_statement_4x(Pointer)
Pointer cdecl x_mysql_fetch_row(Pointer result)
Pointer cdecl x_mysql_store_result(ObjectPtr)
int cdecl x_mysql_query(ObjectPtr, String )
int cdecl x_mysql_select_db(ObjectPtr, String db)
long cdecl stmt_lastinserted_id_4x(Pointer)
String cdecl stmt_getValue(Pointer, String)
double cdecl rs_getIValueD(Pointer, int)
Pointer cdecl x_mysql_init(ObjectPtr )
int cdecl rs_label2Index(Pointer, String)
static bool init()
Definition Mysql.xcsm:126
long cdecl stmt_row_count(Pointer)
bool cdecl rs_isValid(Pointer)
static bool bloaded
Definition Mysql.xcsm:124
bool cdecl rs_last(Pointer)
int cdecl stmt_getIValueI(Pointer, int)
bool cdecl statement_res_isValid(Pointer)
int cdecl statement__prepare_4x(Pointer, String sql, int len)
String cdecl rs_getValue(Pointer, String)
String cdecl x_mysql_info(ObjectPtr )
String cdecl stmt_getIValue(Pointer, int)
String cdecl get_statement_error_4x(Pointer)
int cdecl x_mysql_num_fields(Pointer res)
Pointer cdecl x_mysql_row_tell(Pointer res)
bool cdecl rs_isLast(Pointer)
bool cdecl bind_statement_param_4x(Pointer, int n, ObjectPtr data, int len, int type)
String getString(int columnIndex) override
Definition Mysql.xcsm:534
String getString(String columnlabel) override
Definition Mysql.xcsm:506
bool getBoolean(int columnIndex) override
Definition Mysql.xcsm:530
bool isFirst() override
Definition Mysql.xcsm:468
bool next() override
Definition Mysql.xcsm:454
int getRow() override
Definition Mysql.xcsm:554
void close() override
Definition Mysql.xcsm:559
bool isValid() override
Definition Mysql.xcsm:478
bool isLast() override
Definition Mysql.xcsm:473
int getColumnCount() override
Definition Mysql.xcsm:546
double getDouble(String columnlabel) override
Definition Mysql.xcsm:494
float getFloat(String columnlabel) override
Definition Mysql.xcsm:490
long getRowCount() override
Definition Mysql.xcsm:550
int getInt(String columnlabel) override
Definition Mysql.xcsm:482
float getFloat(int columnIndex) override
Definition Mysql.xcsm:518
bool isEof() override
Definition Mysql.xcsm:458
int findColumn(String name) override
Definition Mysql.xcsm:538
int getColumnType(int id) override
Definition Mysql.xcsm:566
long getLong(int columnIndex) override
Definition Mysql.xcsm:514
bool first() override
Definition Mysql.xcsm:444
String getColumnName(int i) override
Definition Mysql.xcsm:542
double getDouble(int columnIndex) override
Definition Mysql.xcsm:522
bool previous() override
Definition Mysql.xcsm:463
MysqlPreparedResultSet(Mysql.MysqlPreparedStatement _stmt, long r)
Definition Mysql.xcsm:438
bool last() override
Definition Mysql.xcsm:449
byte getByte(String columnlabel) override
Definition Mysql.xcsm:498
long getLong(String columnlabel) override
Definition Mysql.xcsm:486
bool getBoolean(String columnlabel) override
Definition Mysql.xcsm:502
byte getByte(int columnIndex) override
Definition Mysql.xcsm:526
int getInt(int columnIndex) override
Definition Mysql.xcsm:510
Mysql.MysqlPreparedStatement stmt
Definition Mysql.xcsm:436
void setValue(int id, byte value) override
Definition Mysql.xcsm:763
MysqlPreparedStatement(Mysql m, String sql)
Definition Mysql.xcsm:587
int get_changes() override
Definition Mysql.xcsm:804
int get_lastInsertId() override
Definition Mysql.xcsm:808
void close() override
Definition Mysql.xcsm:812
void setValue(int value) override
Definition Mysql.xcsm:686
void setValue(int id, long value) override
Definition Mysql.xcsm:753
void setValue(int id, int value) override
Definition Mysql.xcsm:743
int execute() override
Definition Mysql.xcsm:598
int execute(String sql) override
Definition Mysql.xcsm:618
void setValue(long value) override
Definition Mysql.xcsm:696
Sql.ResultSet executeQuery() override
Definition Mysql.xcsm:610
void setValue(int id, String value) override
Definition Mysql.xcsm:727
void setValue(int id, double value) override
Definition Mysql.xcsm:773
Sql.ResultSet executeQuery(String sql) override
Definition Mysql.xcsm:630
int executeUpdate() override
Definition Mysql.xcsm:637
int executeUpdate(String sql) override
Definition Mysql.xcsm:648
void setValue(String value) override
Definition Mysql.xcsm:670
void setValues(Object [] args) override
Definition Mysql.xcsm:784
Sql.ResultSet getResult() override
Definition Mysql.xcsm:660
void setValue(byte value) override
Definition Mysql.xcsm:706
void setValue(double value) override
Definition Mysql.xcsm:716
Sql.Connection allocConnection(String drivername) override
Definition Mysql.xcsm:105
String getString(int columnIndex) override
Definition Mysql.xcsm:330
String getString(String columnlabel) override
Definition Mysql.xcsm:302
bool getBoolean(int columnIndex) override
Definition Mysql.xcsm:326
bool isFirst() override
Definition Mysql.xcsm:265
bool next() override
Definition Mysql.xcsm:251
int getRow() override
Definition Mysql.xcsm:353
void close() override
Definition Mysql.xcsm:358
bool isValid() override
Definition Mysql.xcsm:274
bool isLast() override
Definition Mysql.xcsm:270
int getColumnCount() override
Definition Mysql.xcsm:344
double getDouble(String columnlabel) override
Definition Mysql.xcsm:290
float getFloat(String columnlabel) override
Definition Mysql.xcsm:286
long getRowCount() override
Definition Mysql.xcsm:349
int getInt(String columnlabel) override
Definition Mysql.xcsm:278
float getFloat(int columnIndex) override
Definition Mysql.xcsm:318
bool isEof() override
Definition Mysql.xcsm:255
MysqlResultSet(long r)
Definition Mysql.xcsm:239
long getLong(int columnIndex) override
Definition Mysql.xcsm:310
int findColumn(String) override
Definition Mysql.xcsm:334
bool first() override
Definition Mysql.xcsm:243
String getColumnName(int i) override
Definition Mysql.xcsm:339
double getDouble(int columnIndex) override
Definition Mysql.xcsm:314
bool previous() override
Definition Mysql.xcsm:260
bool last() override
Definition Mysql.xcsm:247
byte getByte(String columnlabel) override
Definition Mysql.xcsm:294
long getLong(String columnlabel) override
Definition Mysql.xcsm:282
bool getBoolean(String columnlabel) override
Definition Mysql.xcsm:298
byte getByte(int columnIndex) override
Definition Mysql.xcsm:322
int getInt(int columnIndex) override
Definition Mysql.xcsm:306
int get_changes() override
Definition Mysql.xcsm:419
int get_lastInsertId() override
Definition Mysql.xcsm:423
void close() override
Definition Mysql.xcsm:427
int execute(String sql) override
Definition Mysql.xcsm:377
Sql.ResultSet executeQuery(String sql) override
Definition Mysql.xcsm:389
MysqlStatement(Mysql m)
Definition Mysql.xcsm:373
int executeUpdate(String sql) override
Definition Mysql.xcsm:397
Sql.ResultSet getResult() override
Definition Mysql.xcsm:409
int getErrorCode() override
Definition Mysql.xcsm:861
static const int CLIENT_PLUGIN_AUTH
Definition Mysql.xcsm:25
static const int CLIENT_INTERACTIVE
Definition Mysql.xcsm:15
void close() override
Definition Mysql.xcsm:821
void create(String uri, String username, String pwd) override
Definition Mysql.xcsm:833
Object getOption(int opt) override
Definition Mysql.xcsm:877
String getInfo()
Definition Mysql.xcsm:873
static const int CLIENT_NO_SCHEMA
Definition Mysql.xcsm:9
static const int CLIENT_TRANSACTIONS
Definition Mysql.xcsm:18
static const int CLIENT_PS_MULTI_RESULTS
Definition Mysql.xcsm:23
static const int CLIENT_LONG_FLAG
Definition Mysql.xcsm:7
static const int CLIENT_MULTI_STATEMENTS
Definition Mysql.xcsm:21
static const int CLIENT_CONNECT_WITH_DB
Definition Mysql.xcsm:8
int timeout
Definition Mysql.xcsm:90
int return_option
Definition Mysql.xcsm:91
bool isClosed() override
Definition Mysql.xcsm:855
static const String DRIVERNAME
Definition Mysql.xcsm:86
static const int CLIENT_SSL
Definition Mysql.xcsm:16
int port
Definition Mysql.xcsm:89
static const int CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA
Definition Mysql.xcsm:29
static const int CLIENT_BASIC_FLAGS
Definition Mysql.xcsm:82
static const int CLIENT_ODBC
Definition Mysql.xcsm:11
void finalize()
Definition Mysql.xcsm:829
static const int CLIENT_MULTI_RESULTS
Definition Mysql.xcsm:22
byte [] _mysql
Definition Mysql.xcsm:87
static const int CLIENT_COMPRESS
Definition Mysql.xcsm:10
static const int CLIENT_IGNORE_SIGPIPE
Definition Mysql.xcsm:17
static const int CLIENT_DEPRECATE_EOF
Definition Mysql.xcsm:40
static const int CLIENT_RESERVED
Definition Mysql.xcsm:19
static const int CLIENT_LONG_PASSWORD
Definition Mysql.xcsm:5
static const int CLIENT_REMEMBER_OPTIONS
Definition Mysql.xcsm:43
static const int CLIENT_FOUND_ROWS
Definition Mysql.xcsm:6
String getSqlState()
Definition Mysql.xcsm:869
static const int CLIENT_ALL_FLAGS
Definition Mysql.xcsm:48
int client_flags
Definition Mysql.xcsm:92
static const int CLIENT_CONNECT_ATTRS
Definition Mysql.xcsm:26
static const int CLIENT_PROTOCOL_41
Definition Mysql.xcsm:14
Sql.Statement createStatement() override
Definition Mysql.xcsm:933
Sql.PreparedStatement prepareStatement(String sql) override
Definition Mysql.xcsm:937
static const int CLIENT_IGNORE_SPACE
Definition Mysql.xcsm:13
static const int CLIENT_RESERVED2
Definition Mysql.xcsm:20
static const int CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS
Definition Mysql.xcsm:32
void setOption(int opt, Object option) override
Definition Mysql.xcsm:883
String getError() override
Definition Mysql.xcsm:865
static const int CLIENT_LOCAL_FILES
Definition Mysql.xcsm:12
static bool registry()
Definition Mysql.xcsm:114
static bool registried
Definition Mysql.xcsm:234
static const int CLIENT_SESSION_TRACK
Definition Mysql.xcsm:38
static const int CLIENT_SSL_VERIFY_SERVER_CERT
Definition Mysql.xcsm:42
Definition Object.x:1
Definition String.x:5
float parseFloat()
int length()
bool equals(String)
Definition xsql.xcs:3