├── .gitignore ├── .gitmodules ├── README.md ├── SCsub ├── capabilities.md ├── compilation.md ├── config.py ├── doc_classes ├── MySQL.xml └── SqlResult.xml ├── icons ├── MySQL.svg └── SqlResult.svg ├── register_types.cpp ├── register_types.h ├── scr ├── constants.h ├── helpers.cpp ├── helpers.h ├── mysql.cpp ├── mysql.h ├── sql_result.cpp └── sql_result.h └── tools ├── __init__.py ├── boost.py ├── boost_rascunho.py ├── helpers.py └── openssl.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | 35 | # C/C++ generated 36 | *.a 37 | *.ax 38 | *.d 39 | *.dll 40 | *.lib 41 | *.lo 42 | *.o 43 | *.os 44 | *.ox 45 | *.Plo 46 | *.so 47 | 48 | # Local editor & project files. 49 | *.*[~] 50 | __pycache__/ 51 | .vscode/ 52 | .code-workspace 53 | .godot/ 54 | dep/ 55 | deb/ 56 | 3party/bin/ 57 | 58 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3party/openssl"] 2 | path = 3party/openssl 3 | url = git@github.com:openssl/openssl.git 4 | [submodule "3party/boost"] 5 | path = 3party/boost 6 | url = git@github.com:boostorg/boost.git 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MySQL Module to Godot 4. 2 | 3 | 4 | ### **This module is a wrapper for Boost.MySQL.** 5 | 6 | Boost.MySQL is a client for MySQL and MariaDB database servers, based on Boost.Asio. 7 | Boost.MySQL is part of Boost. 8 | This module takes advantage of C++20. 9 | Check out the Boost repository: [Boost.MySQL](https://github.com/boostorg/mysql?tab=readme-ov-file). 10 | 11 | 12 | 13 | ##### This module works only with Godot 4. 14 | 15 | I have no plans to back port this module to Godot 3.x, but I will accept help from anyone who wants to port it. 16 | 17 | 18 | ##### If you use this module, let me know it. Leave a star ;). 19 | 20 | ##### Do you have any suggestion? Would you like to share experiences while using the module? Please open a issue. 21 | 22 | ##### Old version note: 23 | 24 | Version 1.0 uses C++ MySQL Connector Library from [Oracle](https://dev.mysql.com/doc/connector-cpp/8.3/en/). You can find it here: [Godot MySQL 2.0](https://github.com/Malkverbena/mysql/releases/tag/V2.0). 25 | 26 | 27 | ## Supported platforms: (Work in progress). 28 | 29 | * MacOS - soon (need help). 30 | * X11/Unix - dev. 31 | * Windows - dev. 32 | * OSX- possibly (need help). 33 | * Android - In the future. 34 | * Web - need help. 35 | 36 | ### [See the full list of features here.](https://github.com/Malkverbena/mysql/blob/3.0/capabilities.md) 37 | 38 | ### [Compilation intruction here!](https://github.com/Malkverbena/mysql/blob/3.0/compilation.md) 39 | 40 | 41 | ## Usage: 42 | 43 | * **[Documentation.](https://github.com/Malkverbena/mysql/wiki)** 44 | * **[Check out some exemples here.](https://github.com/Malkverbena/mysql/wiki)** 45 | 46 | 47 | 48 | # Disclaimer 49 | 50 | > THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 51 | > HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 52 | -------------------------------------------------------------------------------- /SCsub: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #SCsub 3 | 4 | 5 | import os 6 | from tools import helpers, openssl, boost 7 | 8 | 9 | 10 | ##### ENVIROMENT ##### 11 | 12 | Import('env') 13 | mysql_env = env.Clone() 14 | 15 | # You don't have to compile third-party libraries each time you compile the module. 16 | # With the "recompile" option you can recompile just Openssl or just Boost, both of them or none of them. 17 | opts = Variables(["customs.py"], ARGUMENTS) 18 | opts.Add(EnumVariable("recompile_sql", "Recompile third party library", "all", ("all", "openssl", "boost", "none"))) 19 | opts.Update(mysql_env) 20 | 21 | 22 | 23 | ##### FLAGS ##### 24 | 25 | # Enable Boost separate compilation mode 26 | #mysql_env.Append(CPPDEFINES=["BOOST_MYSQL_SEPARATE_COMPILATION"]) 27 | 28 | # Build with exceptions! 29 | #if env["disable_exceptions"]: 30 | # if env.msvc and ("_HAS_EXCEPTIONS", 0) in mysql_env["CPPDEFINES"]: 31 | # mysql_env["CPPDEFINES"].remove(("_HAS_EXCEPTIONS", 0)) 32 | # mysql_env.AppendUnique(CPPFLAGS=["/EHsc"]) 33 | # elif not env.msvc and "-fno-exceptions" in mysql_env["CPPFLAGS"]: 34 | # mysql_env["CPPFLAGS"].remove("-fno-exceptions") 35 | 36 | mysql_env.Append(CPPFLAGS=[ 37 | '-fexceptions', 38 | '-std=c++20', 39 | ]) 40 | 41 | target_bits = "64" if env["arch"] in ["x86_64", "arm64", "rv64", "ppc64"] else "32" 42 | 43 | 44 | 45 | ##### PATHS ##### 46 | 47 | # Use absolut paths to avoid problem between platforms. 48 | # dep_path = os.path.join(os.getcwd(), "3party") 49 | 50 | openssl_path = openssl.get_openssl_install_path(mysql_env) 51 | openssl_include_path = openssl_path + "/include" 52 | openssl_lib_path = openssl_path + "/lib64" 53 | boost_path = boost.get_boost_install_path(mysql_env) 54 | boost_include_path = boost_path + "/include" 55 | boost_lib_path = boost_path + "/stage/lib" 56 | 57 | 58 | ##### THIRDPARTY COMPILATION ##### 59 | 60 | # Update and compile thirdparty. 61 | helpers.apply_config(mysql_env) 62 | 63 | 64 | 65 | ##### GODOT MODULE ##### 66 | 67 | # INCLUDE: 68 | mysql_env.Prepend(CPPPATH=[ 69 | openssl_include_path, 70 | boost_include_path, 71 | # openssl_path 72 | ]) 73 | 74 | # LIB 75 | env.Prepend(LIBPATH=[ 76 | openssl_lib_path, 77 | boost_lib_path, 78 | # openssl_path 79 | ]) 80 | 81 | mysql_env.add_source_files(env.modules_sources, "*.cpp") 82 | mysql_env.add_source_files(env.modules_sources, "scr/**.cpp") 83 | 84 | 85 | env.Prepend(LIBS=["libboost_thread", "libcrypto", "libssl"]) 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /capabilities.md: -------------------------------------------------------------------------------- 1 | ## Capabilities: 2 | 3 | ### Connection: 4 | 5 | * TCP and UNIX socket connections. 6 | * Encrypted connections (TLS). For both, TCP and UNIX socket connections. 7 | * Authentication methods: mysql_native_password and caching_sha2_password. 8 | 9 | ### **Methods:** 10 | 11 | * Supports asynchronous methods using C++20 coroutines. 12 | * Supports Multi-function operations. 13 | * Stored procedures. It can be used within Multi-function operations. 14 | * Text querie: MySQL refers to this as the "text protocol", as all information is passed using text (as opposed to prepared statements). 15 | * Prepared statements: MySQL refers to this as the "binary protocol", as the result of executing a prepared statement is sent in binary format rather than in text. 16 | 17 | ### **EQUIVALENT DATA TYPES:** 18 | 19 | | DATA TYPE | GODOT DATA TYPE | C++ DATA TYPE | MYSQL DATA TYPE | 20 | | :-------: | :---------------: | :--------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: | 21 | | NULL | null | std::nullptr_t | NILL | 22 | | BOOL | bool | bool | TINYINT | 23 | | INT32 | integer 32 | signed char, short, int, long, long long | SIGNED TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT | 24 | | INT64 | integer 64 | unsigned char, unsigned short, unsigned,
int, unsigned long, unsigned long long | UNSIGNED BIGINT, UNSIGNED TINYINT, SMALLINT,
MEDIUMINT, INT, BIGINT, YEAR, BIT | 25 | | FLOAT | float | float | FLOAT | 26 | | DOUBLE | float | double | DOUBLE | 27 | | BINARY | PackedByteArray | std::basic_vector | BINARY, VARBINARY, BLOB (all sizes), GEOMETRY | 28 | | CHAR | String | std::basic_string`, Allocator> (including std::string),
string_view, std::string_view, const char* | CHAR, VARCHAR, TEXT(all sizes),
ENUM, JSON, DECIMAL, NUMERIC | 29 | | DATE | Dictionary | boost::mysql::date AKA std::chrono::time_point
| DATE | 30 | | TIME | Dictionary | boost::mysql::time AKA std::chrono::microseconds | TIME | 31 | | DATETIME | Dictionary | boost::mysql::datetime AKA std::chrono::time_point
> | DATETIME, TIMESTAMP | 32 | | CHAR | PackedStringArray | std::basic_string (including std::string),
string_view, std::string_view, const char* | SET | 33 | -------------------------------------------------------------------------------- /compilation.md: -------------------------------------------------------------------------------- 1 | # Instructions for compilation: 2 | 3 | 4 | This module has two dependencies, Openssl and Boost. 5 | The dependencies will be automatically compiled during engine compilation. 6 | 7 | You do not need to compile dependencies every time you compile the engine, but you must recompile dependencies when updating Boost and/or Openssl or when you are compiling the module for some platform that you haven't compiled before. 8 | 9 | You can use the "recompile_sql" option when invoking scons to compile openssl and Boost or not. 10 | 11 | * All: It will compile BOTH Boost and Openssl. 12 | * openssl: It will only compile Openssl. 13 | * boost: It will only compile Boost. 14 | * none: It will **NOT** compile either Open or Boost. 15 | 16 | 17 | ## Requirements: 18 | 19 | - A C++20 capable compiler as GCC, Clang (x11) , Visual C++ (Windows) or Apple Clang (Apple). 20 | - [**NASM - Only for Windows**](https://www.nasm.us/pub/nasm/releasebuilds/) 21 | - Git 22 | - All requirements to compile Godot. 23 | 24 | 25 | ## Compilation: 26 | 27 | It is necessary recompile the engine together with this module. 28 | 29 | It is highly recommended to compile the engine with the "*precision=double*" option. 30 | 31 | Clone this repository inside the godot modules folder or an external folder with the following command to checkout all the dependencies: Boost and OpenSSL. 32 | 33 | ``` 34 | git clone --recurse-submodules git@github.com:Malkverbena/mysql.git 35 | ``` 36 | 37 | If you already checked out the branch use the following commands to update the dependencies: 38 | 39 | ``` 40 | $ git submodule update --init --recursive 41 | ``` 42 | 43 | In case you use an external folder, you must use "*custom_modules*" when invoke Scons. 44 | 45 | ``` 46 | custom_modules=../path/to/mysql/folder 47 | ``` 48 | 49 | compile the engine normally. 50 | 51 | You can use the command belloww to update the module the submodules at once. 52 | 53 | ``` 54 | git pull --recurse-submodules 55 | ``` 56 | 57 | 58 | ### **Note:** 59 | 60 | At the moment it is only possible to compile this module for Linux and Windows. Support for MacOS is still being developed. 61 | It is perfectly possible to compile the module for other platforms such as Android and OSX, however this support has not yet been added. 62 | Any help adding support for these platforms would be appreciated. 63 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # config.py 2 | 3 | 4 | def can_build(env, platform): 5 | return True 6 | 7 | 8 | def configure(env): 9 | pass 10 | 11 | 12 | def get_doc_path(): 13 | return "doc_classes" 14 | 15 | 16 | def get_doc_classes(): 17 | return [ 18 | "MySQL", 19 | "SqlResult", 20 | ] 21 | 22 | 23 | def get_icons_path(): 24 | return "icons" 25 | -------------------------------------------------------------------------------- /doc_classes/MySQL.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | A wrapper class for an [url=https://www.boost.org/doc/libs/develop/libs/mysql/doc/html/index.html]Boost.MySQL[/url]. 5 | 6 | 7 | This class is client for MySQL and MariaDB database servers. 8 | 9 | 10 | https://github.com/Malkverbena/mysql/tree/Docs-%26-Exemples-3.0 11 | 12 | 13 | 14 | 15 | 16 | 17 | Issue the SQL text query to the server using asynchronous methods.[br] 18 | This method returns a [SqlResult], which contains the result of the query.[br] 19 | [param query]: Statement to be sent. 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Issue the SQL binary query (prepared statements) to the server using asynchronous methods.[br] 28 | This method returns a [SqlResult], which contains the result of the query.[br] 29 | [param query]: Statement to be sent.[br] 30 | [param values]: Values to be bind.[br] 31 | 32 | 33 | 34 | 35 | 36 | Close the connection. 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Defines or redefines and configure a connection. If there is an already active connection to this instance of the MySQL class, it will be disconnected and restarted.[br] 46 | [b]Note:[/b] Resetting the connection does NOT reset the credentials.[br] 47 | [param connection type]: Type of connection to be used.[br] 48 | [param certificate file]: If you use an SSL connection you need to define the path to your CA certificate here. In non-TLS connections the certificate will be ignored.[br] 49 | [param hostname verification]: Certificate's common name. We expect the server certificate's common name to be "mysql". [param hostname verification] 50 | 51 | 52 | 53 | 54 | 55 | 56 | Issue the SQL text query to the server.[br] This method returns a [SqlResult], which contains the result of the query. 57 | [param query]: Statement to be sent. 58 | 59 | 60 | 61 | 62 | 63 | 64 | Execute Multi-function operations.[br] 65 | This function can be used to issue stored procedures.[br] 66 | This method returns an Array of [SqlResult], which contains multiples results.[br] 67 | [b]Note:[/b]This function perform multi-queries. Works only if "multi_queries" option is [code]true[/code].[br] 68 | [b]Note:[/b] Be extremely careful with this function due possible security holes implemented by your script.[br] 69 | [param queries]: String containing multiple SQL statements. 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | Issue the SQL binary query (prepared statements) to the server.[br] 78 | This method returns a [SqlResult], which contains the result of the query.[br] 79 | [param query]: Statement to be sent.[br] 80 | [param values]: Values to be bind. 81 | 82 | 83 | 84 | 85 | 86 | 87 | Execute Multi-function operations from a file .sql.[br] 88 | This function can be used to issue stored procedures.[br] 89 | This method returns an Array of [SqlResult], which contains multiples results.[br] 90 | [b]Note:[/b]This function perform multi-queries. Works only if "multi_queries" option is [code]true[/code].[br] 91 | [b]Note:[/b] Be extremely careful with this function due possible security holes implemented by your .sql file.[br] 92 | [param queries]: Path tp .sql file. 93 | 94 | 95 | 96 | 97 | 98 | Retrieves the connection type. 99 | 100 | 101 | 102 | 103 | 104 | Returns a dictionary with the connection credentials. 105 | 106 | 107 | 108 | 109 | 110 | Returns a dictionary with the last exception that occurred. 111 | 112 | 113 | 114 | 115 | 116 | Checks whether there is an active connection to the server. 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | Configure connection credentials. 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | This method is used to initiate a TCP connection. UNIX connections won't work.[br] 137 | [param hostname]: Host address.[br] 138 | [param port]: Port for connecting to the server. 139 | 140 | 141 | 142 | 143 | 144 | 145 | This method is used to initiate a UNIX connection. TCP connections won't work.[br] 146 | [param socket_path]: Path to socket file. 147 | 148 | 149 | 150 | 151 | 152 | TCP connection. 153 | 154 | 155 | TCP/TLS connection. 156 | 157 | 158 | UNIX connection. 159 | 160 | 161 | UNIX/TLS connection.[br] 162 | [b]Note:[/b] It doesn't make sense to use UNIX/SSL connections since data traffic is local. Nothing leaves the machine where the mysql instance is running. 163 | 164 | 165 | The connection will use TLS. If the server does not support it, the connection will be refused. This is the default for SSL-enabled streams. 166 | 167 | 168 | The connection will use TLS if available, falling back to an unencrypted connection if the server does not support it. 169 | 170 | 171 | The connection will never use TLS. 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | -------------------------------------------------------------------------------- /doc_classes/SqlResult.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Query result. 5 | 6 | 7 | This class holds the query's results 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Returns the number of rows affected by the query that generated this SqlResult. 16 | 17 | 18 | 19 | 20 | 21 | Retrieves the query result with an Array of Arrays. The values of each row will be contained in an Array. 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | Retrieves a specific column by searching for the column name. 30 | [param column]: Name of the column. 31 | [param as_array]: If true, will return the values in an Dictionary. The keys will be the number of the each line. 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | Retrieves a specific column by searching column's ID. 40 | [param column]: ID of the column. 41 | [param as_array]: If true, will return the values in an Dictionary. The keys will be the number of the each line. 42 | 43 | 44 | 45 | 46 | 47 | Retrieves the query result with an Array of Dictionaries. The values of each row will be contained in an Dictionary. 48 | 49 | 50 | 51 | 52 | 53 | Retrieves the last insert id by the query. 54 | 55 | 56 | 57 | 58 | 59 | Retrieves the query's metadata . 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | Retrieves a specific row by searching the row's ID. 68 | [param row]: ID of the column. 69 | [param as_array]:If true, it returns each elemnt of the row as a simple value, otherwise it will return each element as a Dictionary, with the key being the name of the column. 70 | 71 | 72 | 73 | 74 | 75 | Retrieves the number of warnings generated. 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /icons/MySQL.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /icons/SqlResult.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /register_types.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* register_types.cpp */ 3 | 4 | 5 | #include "register_types.h" 6 | 7 | #ifdef BOOST_MYSQL_SEPARATE_COMPILATION 8 | #include 9 | #endif 10 | 11 | #include "scr/constants.h" 12 | #include "scr/helpers.h" 13 | #include "scr/sql_result.h" 14 | #include "scr/mysql.h" 15 | 16 | 17 | void initialize_mysql_module(ModuleInitializationLevel p_level) { 18 | if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { 19 | return; 20 | } 21 | GDREGISTER_CLASS(MySQL); 22 | GDREGISTER_CLASS(SqlResult); 23 | } 24 | 25 | 26 | void uninitialize_mysql_module(ModuleInitializationLevel p_level) { 27 | if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { 28 | return; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /register_types.h: -------------------------------------------------------------------------------- 1 | /* register_types.h */ 2 | 3 | #include "modules/register_module_types.h" 4 | 5 | void initialize_mysql_module(ModuleInitializationLevel p_level); 6 | void uninitialize_mysql_module(ModuleInitializationLevel p_level); 7 | 8 | -------------------------------------------------------------------------------- /scr/constants.h: -------------------------------------------------------------------------------- 1 | 2 | /* constants.h */ 3 | 4 | #ifndef DEFINITIONS_H 5 | #define DEFINITIONS_H 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | #ifdef BOOST_MYSQL_SEPARATE_COMPILATION 13 | #include 14 | #endif 15 | 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | using namespace boost; 23 | 24 | 25 | #ifdef TOOLS_ENABLED 26 | #define FUNCTION_NAME __PRETTY_FUNCTION__ 27 | #else 28 | #define FUNCTION_NAME __FUNCTION__ 29 | #endif 30 | 31 | 32 | enum CONN_TYPE{ 33 | NONE, 34 | TCP, 35 | TCPTLS, 36 | UNIX, 37 | UNIXTLS 38 | }; 39 | 40 | 41 | enum MYSQLCOLLATIONS { 42 | default_collation = mysql::mysql_collations::utf8mb4_general_ci, // 45 43 | big5_chinese_ci = mysql::mysql_collations::big5_chinese_ci, 44 | latin2_czech_cs = mysql::mysql_collations::latin2_czech_cs, 45 | dec8_swedish_ci = mysql::mysql_collations::dec8_swedish_ci, 46 | cp850_general_ci = mysql::mysql_collations::cp850_general_ci, 47 | latin1_german1_ci = mysql::mysql_collations::latin1_german1_ci, 48 | hp8_english_ci = mysql::mysql_collations::hp8_english_ci, 49 | koi8r_general_ci = mysql::mysql_collations::koi8r_general_ci, 50 | latin1_swedish_ci = mysql::mysql_collations::latin1_swedish_ci, 51 | latin2_general_ci = mysql::mysql_collations::latin2_general_ci, 52 | swe7_swedish_ci = mysql::mysql_collations::swe7_swedish_ci, 53 | ascii_general_ci = mysql::mysql_collations::ascii_general_ci, 54 | ujis_japanese_ci = mysql::mysql_collations::ujis_japanese_ci, 55 | sjis_japanese_ci = mysql::mysql_collations::sjis_japanese_ci, 56 | cp1251_bulgarian_ci = mysql::mysql_collations::cp1251_bulgarian_ci, 57 | latin1_danish_ci = mysql::mysql_collations::latin1_danish_ci, 58 | hebrew_general_ci = mysql::mysql_collations::hebrew_general_ci, 59 | tis620_thai_ci = mysql::mysql_collations::tis620_thai_ci, 60 | euckr_korean_ci = mysql::mysql_collations::euckr_korean_ci, 61 | latin7_estonian_cs = mysql::mysql_collations::latin7_estonian_cs, 62 | latin2_hungarian_ci = mysql::mysql_collations::latin2_hungarian_ci, 63 | koi8u_general_ci = mysql::mysql_collations::koi8u_general_ci, 64 | cp1251_ukrainian_ci = mysql::mysql_collations::cp1251_ukrainian_ci, 65 | gb2312_chinese_ci = mysql::mysql_collations::gb2312_chinese_ci, 66 | greek_general_ci = mysql::mysql_collations::greek_general_ci, 67 | cp1250_general_ci = mysql::mysql_collations::cp1250_general_ci, 68 | latin2_croatian_ci = mysql::mysql_collations::latin2_croatian_ci, 69 | gbk_chinese_ci = mysql::mysql_collations::gbk_chinese_ci, 70 | cp1257_lithuanian_ci = mysql::mysql_collations::cp1257_lithuanian_ci, 71 | latin5_turkish_ci = mysql::mysql_collations::latin5_turkish_ci, 72 | latin1_german2_ci = mysql::mysql_collations::latin1_german2_ci, 73 | armscii8_general_ci = mysql::mysql_collations::armscii8_general_ci, 74 | utf8_general_ci = mysql::mysql_collations::utf8_general_ci, 75 | cp1250_czech_cs = mysql::mysql_collations::cp1250_czech_cs, 76 | ucs2_general_ci = mysql::mysql_collations::ucs2_general_ci, 77 | cp866_general_ci = mysql::mysql_collations::cp866_general_ci, 78 | keybcs2_general_ci = mysql::mysql_collations::keybcs2_general_ci, 79 | macce_general_ci = mysql::mysql_collations::macce_general_ci, 80 | macroman_general_ci = mysql::mysql_collations::macroman_general_ci, 81 | cp852_general_ci = mysql::mysql_collations::cp852_general_ci, 82 | latin7_general_ci = mysql::mysql_collations::latin7_general_ci, 83 | latin7_general_cs = mysql::mysql_collations::latin7_general_cs, 84 | macce_bin = mysql::mysql_collations::macce_bin, 85 | cp1250_croatian_ci = mysql::mysql_collations::cp1250_croatian_ci, 86 | utf8mb4_general_ci = mysql::mysql_collations::utf8mb4_general_ci, 87 | utf8mb4_bin = mysql::mysql_collations::utf8mb4_bin, 88 | latin1_bin = mysql::mysql_collations::latin1_bin, 89 | latin1_general_ci = mysql::mysql_collations::latin1_general_ci, 90 | latin1_general_cs = mysql::mysql_collations::latin1_general_cs, 91 | cp1251_bin = mysql::mysql_collations::cp1251_bin, 92 | cp1251_general_ci = mysql::mysql_collations::cp1251_general_ci, 93 | cp1251_general_cs = mysql::mysql_collations::cp1251_general_cs, 94 | macroman_bin = mysql::mysql_collations::macroman_bin, 95 | utf16_general_ci = mysql::mysql_collations::utf16_general_ci, 96 | utf16_bin = mysql::mysql_collations::utf16_bin, 97 | utf16le_general_ci = mysql::mysql_collations::utf16le_general_ci, 98 | cp1256_general_ci = mysql::mysql_collations::cp1256_general_ci, 99 | cp1257_bin = mysql::mysql_collations::cp1257_bin, 100 | cp1257_general_ci = mysql::mysql_collations::cp1257_general_ci, 101 | utf32_general_ci = mysql::mysql_collations::utf32_general_ci, 102 | utf32_bin = mysql::mysql_collations::utf32_bin, 103 | utf16le_bin = mysql::mysql_collations::utf16le_bin, 104 | binary = mysql::mysql_collations::binary, 105 | armscii8_bin = mysql::mysql_collations::armscii8_bin, 106 | ascii_bin = mysql::mysql_collations::ascii_bin, 107 | cp1250_bin = mysql::mysql_collations::cp1250_bin, 108 | cp1256_bin = mysql::mysql_collations::cp1256_bin, 109 | cp866_bin = mysql::mysql_collations::cp866_bin, 110 | dec8_bin = mysql::mysql_collations::dec8_bin, 111 | greek_bin = mysql::mysql_collations::greek_bin, 112 | hebrew_bin = mysql::mysql_collations::hebrew_bin, 113 | hp8_bin = mysql::mysql_collations::hp8_bin, 114 | keybcs2_bin = mysql::mysql_collations::keybcs2_bin, 115 | koi8r_bin = mysql::mysql_collations::koi8r_bin, 116 | koi8u_bin = mysql::mysql_collations::koi8u_bin, 117 | utf8_tolower_ci = mysql::mysql_collations::utf8_tolower_ci, 118 | latin2_bin = mysql::mysql_collations::latin2_bin, 119 | latin5_bin = mysql::mysql_collations::latin5_bin, 120 | latin7_bin = mysql::mysql_collations::latin7_bin, 121 | cp850_bin = mysql::mysql_collations::cp850_bin, 122 | cp852_bin = mysql::mysql_collations::cp852_bin, 123 | swe7_bin = mysql::mysql_collations::swe7_bin, 124 | utf8_bin = mysql::mysql_collations::utf8_bin, 125 | big5_bin = mysql::mysql_collations::big5_bin, 126 | euckr_bin = mysql::mysql_collations::euckr_bin, 127 | gb2312_bin = mysql::mysql_collations::gb2312_bin, 128 | gbk_bin = mysql::mysql_collations::gbk_bin, 129 | sjis_bin = mysql::mysql_collations::sjis_bin, 130 | tis620_bin = mysql::mysql_collations::tis620_bin, 131 | ucs2_bin = mysql::mysql_collations::ucs2_bin, 132 | ujis_bin = mysql::mysql_collations::ujis_bin, 133 | geostd8_general_ci = mysql::mysql_collations::geostd8_general_ci, 134 | geostd8_bin = mysql::mysql_collations::geostd8_bin, 135 | latin1_spanish_ci = mysql::mysql_collations::latin1_spanish_ci, 136 | cp932_japanese_ci = mysql::mysql_collations::cp932_japanese_ci, 137 | cp932_bin = mysql::mysql_collations::cp932_bin, 138 | eucjpms_japanese_ci = mysql::mysql_collations::eucjpms_japanese_ci, 139 | eucjpms_bin = mysql::mysql_collations::eucjpms_bin, 140 | cp1250_polish_ci = mysql::mysql_collations::cp1250_polish_ci, 141 | utf16_unicode_ci = mysql::mysql_collations::utf16_unicode_ci, 142 | utf16_icelandic_ci = mysql::mysql_collations::utf16_icelandic_ci, 143 | utf16_latvian_ci = mysql::mysql_collations::utf16_latvian_ci, 144 | utf16_romanian_ci = mysql::mysql_collations::utf16_romanian_ci, 145 | utf16_slovenian_ci = mysql::mysql_collations::utf16_slovenian_ci, 146 | utf16_polish_ci = mysql::mysql_collations::utf16_polish_ci, 147 | utf16_estonian_ci = mysql::mysql_collations::utf16_estonian_ci, 148 | utf16_spanish_ci = mysql::mysql_collations::utf16_spanish_ci, 149 | utf16_swedish_ci = mysql::mysql_collations::utf16_swedish_ci, 150 | utf16_turkish_ci = mysql::mysql_collations::utf16_turkish_ci, 151 | utf16_czech_ci = mysql::mysql_collations::utf16_czech_ci, 152 | utf16_danish_ci = mysql::mysql_collations::utf16_danish_ci, 153 | utf16_lithuanian_ci = mysql::mysql_collations::utf16_lithuanian_ci, 154 | utf16_slovak_ci = mysql::mysql_collations::utf16_slovak_ci, 155 | utf16_spanish2_ci = mysql::mysql_collations::utf16_spanish2_ci, 156 | utf16_roman_ci = mysql::mysql_collations::utf16_roman_ci, 157 | utf16_persian_ci = mysql::mysql_collations::utf16_persian_ci, 158 | utf16_esperanto_ci = mysql::mysql_collations::utf16_esperanto_ci, 159 | utf16_hungarian_ci = mysql::mysql_collations::utf16_hungarian_ci, 160 | utf16_sinhala_ci = mysql::mysql_collations::utf16_sinhala_ci, 161 | utf16_german2_ci = mysql::mysql_collations::utf16_german2_ci, 162 | utf16_croatian_ci = mysql::mysql_collations::utf16_croatian_ci, 163 | utf16_unicode_520_ci = mysql::mysql_collations::utf16_unicode_520_ci, 164 | utf16_vietnamese_ci = mysql::mysql_collations::utf16_vietnamese_ci, 165 | ucs2_unicode_ci = mysql::mysql_collations::ucs2_unicode_ci, 166 | ucs2_icelandic_ci = mysql::mysql_collations::ucs2_icelandic_ci, 167 | ucs2_latvian_ci = mysql::mysql_collations::ucs2_latvian_ci, 168 | ucs2_romanian_ci = mysql::mysql_collations::ucs2_romanian_ci, 169 | ucs2_slovenian_ci = mysql::mysql_collations::ucs2_slovenian_ci, 170 | ucs2_polish_ci = mysql::mysql_collations::ucs2_polish_ci, 171 | ucs2_estonian_ci = mysql::mysql_collations::ucs2_estonian_ci, 172 | ucs2_spanish_ci = mysql::mysql_collations::ucs2_spanish_ci, 173 | ucs2_swedish_ci = mysql::mysql_collations::ucs2_swedish_ci, 174 | ucs2_turkish_ci = mysql::mysql_collations::ucs2_turkish_ci, 175 | ucs2_czech_ci = mysql::mysql_collations::ucs2_czech_ci, 176 | ucs2_danish_ci = mysql::mysql_collations::ucs2_danish_ci, 177 | ucs2_lithuanian_ci = mysql::mysql_collations::ucs2_lithuanian_ci, 178 | ucs2_slovak_ci = mysql::mysql_collations::ucs2_slovak_ci, 179 | ucs2_spanish2_ci = mysql::mysql_collations::ucs2_spanish2_ci, 180 | ucs2_roman_ci = mysql::mysql_collations::ucs2_roman_ci, 181 | ucs2_persian_ci = mysql::mysql_collations::ucs2_persian_ci, 182 | ucs2_esperanto_ci = mysql::mysql_collations::ucs2_esperanto_ci, 183 | ucs2_hungarian_ci = mysql::mysql_collations::ucs2_hungarian_ci, 184 | ucs2_sinhala_ci = mysql::mysql_collations::ucs2_sinhala_ci, 185 | ucs2_german2_ci = mysql::mysql_collations::ucs2_german2_ci, 186 | ucs2_croatian_ci = mysql::mysql_collations::ucs2_croatian_ci, 187 | ucs2_unicode_520_ci = mysql::mysql_collations::ucs2_unicode_520_ci, 188 | ucs2_vietnamese_ci = mysql::mysql_collations::ucs2_vietnamese_ci, 189 | ucs2_general_mysql500_ci = mysql::mysql_collations::ucs2_general_mysql500_ci, 190 | utf32_unicode_ci = mysql::mysql_collations::utf32_unicode_ci, 191 | utf32_icelandic_ci = mysql::mysql_collations::utf32_icelandic_ci, 192 | utf32_latvian_ci = mysql::mysql_collations::utf32_latvian_ci, 193 | utf32_romanian_ci = mysql::mysql_collations::utf32_romanian_ci, 194 | utf32_slovenian_ci = mysql::mysql_collations::utf32_slovenian_ci, 195 | utf32_polish_ci = mysql::mysql_collations::utf32_polish_ci, 196 | utf32_estonian_ci = mysql::mysql_collations::utf32_estonian_ci, 197 | utf32_spanish_ci = mysql::mysql_collations::utf32_spanish_ci, 198 | utf32_swedish_ci = mysql::mysql_collations::utf32_swedish_ci, 199 | utf32_turkish_ci = mysql::mysql_collations::utf32_turkish_ci, 200 | utf32_czech_ci = mysql::mysql_collations::utf32_czech_ci, 201 | utf32_danish_ci = mysql::mysql_collations::utf32_danish_ci, 202 | utf32_lithuanian_ci = mysql::mysql_collations::utf32_lithuanian_ci, 203 | utf32_slovak_ci = mysql::mysql_collations::utf32_slovak_ci, 204 | utf32_spanish2_ci = mysql::mysql_collations::utf32_spanish2_ci, 205 | utf32_roman_ci = mysql::mysql_collations::utf32_roman_ci, 206 | utf32_persian_ci = mysql::mysql_collations::utf32_persian_ci, 207 | utf32_esperanto_ci = mysql::mysql_collations::utf32_esperanto_ci, 208 | utf32_hungarian_ci = mysql::mysql_collations::utf32_hungarian_ci, 209 | utf32_sinhala_ci = mysql::mysql_collations::utf32_sinhala_ci, 210 | utf32_german2_ci = mysql::mysql_collations::utf32_german2_ci, 211 | utf32_croatian_ci = mysql::mysql_collations::utf32_croatian_ci, 212 | utf32_unicode_520_ci = mysql::mysql_collations::utf32_unicode_520_ci, 213 | utf32_vietnamese_ci = mysql::mysql_collations::utf32_vietnamese_ci, 214 | utf8_unicode_ci = mysql::mysql_collations::utf8_unicode_ci, 215 | utf8_icelandic_ci = mysql::mysql_collations::utf8_icelandic_ci, 216 | utf8_latvian_ci = mysql::mysql_collations::utf8_latvian_ci, 217 | utf8_romanian_ci = mysql::mysql_collations::utf8_romanian_ci, 218 | utf8_slovenian_ci = mysql::mysql_collations::utf8_slovenian_ci, 219 | utf8_polish_ci = mysql::mysql_collations::utf8_polish_ci, 220 | utf8_estonian_ci = mysql::mysql_collations::utf8_estonian_ci, 221 | utf8_spanish_ci = mysql::mysql_collations::utf8_spanish_ci, 222 | utf8_swedish_ci = mysql::mysql_collations::utf8_swedish_ci, 223 | utf8_turkish_ci = mysql::mysql_collations::utf8_turkish_ci, 224 | utf8_czech_ci = mysql::mysql_collations::utf8_czech_ci, 225 | utf8_danish_ci = mysql::mysql_collations::utf8_danish_ci, 226 | utf8_lithuanian_ci = mysql::mysql_collations::utf8_lithuanian_ci, 227 | utf8_slovak_ci = mysql::mysql_collations::utf8_slovak_ci, 228 | utf8_spanish2_ci = mysql::mysql_collations::utf8_spanish2_ci, 229 | utf8_roman_ci = mysql::mysql_collations::utf8_roman_ci, 230 | utf8_persian_ci = mysql::mysql_collations::utf8_persian_ci, 231 | utf8_esperanto_ci = mysql::mysql_collations::utf8_esperanto_ci, 232 | utf8_hungarian_ci = mysql::mysql_collations::utf8_hungarian_ci, 233 | utf8_sinhala_ci = mysql::mysql_collations::utf8_sinhala_ci, 234 | utf8_german2_ci = mysql::mysql_collations::utf8_german2_ci, 235 | utf8_croatian_ci = mysql::mysql_collations::utf8_croatian_ci, 236 | utf8_unicode_520_ci = mysql::mysql_collations::utf8_unicode_520_ci, 237 | utf8_vietnamese_ci = mysql::mysql_collations::utf8_vietnamese_ci, 238 | utf8_general_mysql500_ci = mysql::mysql_collations::utf8_general_mysql500_ci, 239 | utf8mb4_unicode_ci = mysql::mysql_collations::utf8mb4_unicode_ci, 240 | utf8mb4_icelandic_ci = mysql::mysql_collations::utf8mb4_icelandic_ci, 241 | utf8mb4_latvian_ci = mysql::mysql_collations::utf8mb4_latvian_ci, 242 | utf8mb4_romanian_ci = mysql::mysql_collations::utf8mb4_romanian_ci, 243 | utf8mb4_slovenian_ci = mysql::mysql_collations::utf8mb4_slovenian_ci, 244 | utf8mb4_polish_ci = mysql::mysql_collations::utf8mb4_polish_ci, 245 | utf8mb4_estonian_ci = mysql::mysql_collations::utf8mb4_estonian_ci, 246 | utf8mb4_spanish_ci = mysql::mysql_collations::utf8mb4_spanish_ci, 247 | utf8mb4_swedish_ci = mysql::mysql_collations::utf8mb4_swedish_ci, 248 | utf8mb4_turkish_ci = mysql::mysql_collations::utf8mb4_turkish_ci, 249 | utf8mb4_czech_ci = mysql::mysql_collations::utf8mb4_czech_ci, 250 | utf8mb4_danish_ci = mysql::mysql_collations::utf8mb4_danish_ci, 251 | utf8mb4_lithuanian_ci = mysql::mysql_collations::utf8mb4_lithuanian_ci, 252 | utf8mb4_slovak_ci = mysql::mysql_collations::utf8mb4_slovak_ci, 253 | utf8mb4_spanish2_ci = mysql::mysql_collations::utf8mb4_spanish2_ci, 254 | utf8mb4_roman_ci = mysql::mysql_collations::utf8mb4_roman_ci, 255 | utf8mb4_persian_ci = mysql::mysql_collations::utf8mb4_persian_ci, 256 | utf8mb4_esperanto_ci = mysql::mysql_collations::utf8mb4_esperanto_ci, 257 | utf8mb4_hungarian_ci = mysql::mysql_collations::utf8mb4_hungarian_ci, 258 | utf8mb4_sinhala_ci = mysql::mysql_collations::utf8mb4_sinhala_ci, 259 | utf8mb4_german2_ci = mysql::mysql_collations::utf8mb4_german2_ci, 260 | utf8mb4_croatian_ci = mysql::mysql_collations::utf8mb4_croatian_ci, 261 | utf8mb4_unicode_520_ci = mysql::mysql_collations::utf8mb4_unicode_520_ci, 262 | utf8mb4_vietnamese_ci = mysql::mysql_collations::utf8mb4_vietnamese_ci, 263 | gb18030_chinese_ci = mysql::mysql_collations::gb18030_chinese_ci, 264 | gb18030_bin = mysql::mysql_collations::gb18030_bin, 265 | gb18030_unicode_520_ci = mysql::mysql_collations::gb18030_unicode_520_ci, 266 | utf8mb4_0900_ai_ci = mysql::mysql_collations::utf8mb4_0900_ai_ci, 267 | utf8mb4_de_pb_0900_ai_ci = mysql::mysql_collations::utf8mb4_de_pb_0900_ai_ci, 268 | utf8mb4_is_0900_ai_ci = mysql::mysql_collations::utf8mb4_is_0900_ai_ci, 269 | utf8mb4_lv_0900_ai_ci = mysql::mysql_collations::utf8mb4_lv_0900_ai_ci, 270 | utf8mb4_ro_0900_ai_ci = mysql::mysql_collations::utf8mb4_ro_0900_ai_ci, 271 | utf8mb4_sl_0900_ai_ci = mysql::mysql_collations::utf8mb4_sl_0900_ai_ci, 272 | utf8mb4_pl_0900_ai_ci = mysql::mysql_collations::utf8mb4_pl_0900_ai_ci, 273 | utf8mb4_et_0900_ai_ci = mysql::mysql_collations::utf8mb4_et_0900_ai_ci, 274 | utf8mb4_es_0900_ai_ci = mysql::mysql_collations::utf8mb4_es_0900_ai_ci, 275 | utf8mb4_sv_0900_ai_ci = mysql::mysql_collations::utf8mb4_sv_0900_ai_ci, 276 | utf8mb4_tr_0900_ai_ci = mysql::mysql_collations::utf8mb4_tr_0900_ai_ci, 277 | utf8mb4_cs_0900_ai_ci = mysql::mysql_collations::utf8mb4_cs_0900_ai_ci, 278 | utf8mb4_da_0900_ai_ci = mysql::mysql_collations::utf8mb4_da_0900_ai_ci, 279 | utf8mb4_lt_0900_ai_ci = mysql::mysql_collations::utf8mb4_lt_0900_ai_ci, 280 | utf8mb4_sk_0900_ai_ci = mysql::mysql_collations::utf8mb4_sk_0900_ai_ci, 281 | utf8mb4_es_trad_0900_ai_ci = mysql::mysql_collations::utf8mb4_es_trad_0900_ai_ci, 282 | utf8mb4_la_0900_ai_ci = mysql::mysql_collations::utf8mb4_la_0900_ai_ci, 283 | utf8mb4_eo_0900_ai_ci = mysql::mysql_collations::utf8mb4_eo_0900_ai_ci, 284 | utf8mb4_hu_0900_ai_ci = mysql::mysql_collations::utf8mb4_hu_0900_ai_ci, 285 | utf8mb4_hr_0900_ai_ci = mysql::mysql_collations::utf8mb4_hr_0900_ai_ci, 286 | utf8mb4_vi_0900_ai_ci = mysql::mysql_collations::utf8mb4_vi_0900_ai_ci, 287 | utf8mb4_0900_as_cs = mysql::mysql_collations::utf8mb4_0900_as_cs, 288 | utf8mb4_de_pb_0900_as_cs = mysql::mysql_collations::utf8mb4_de_pb_0900_as_cs, 289 | utf8mb4_is_0900_as_cs = mysql::mysql_collations::utf8mb4_is_0900_as_cs, 290 | utf8mb4_lv_0900_as_cs = mysql::mysql_collations::utf8mb4_lv_0900_as_cs, 291 | utf8mb4_ro_0900_as_cs = mysql::mysql_collations::utf8mb4_ro_0900_as_cs, 292 | utf8mb4_sl_0900_as_cs = mysql::mysql_collations::utf8mb4_sl_0900_as_cs, 293 | utf8mb4_pl_0900_as_cs = mysql::mysql_collations::utf8mb4_pl_0900_as_cs, 294 | utf8mb4_et_0900_as_cs = mysql::mysql_collations::utf8mb4_et_0900_as_cs, 295 | utf8mb4_es_0900_as_cs = mysql::mysql_collations::utf8mb4_es_0900_as_cs, 296 | utf8mb4_sv_0900_as_cs = mysql::mysql_collations::utf8mb4_sv_0900_as_cs, 297 | utf8mb4_tr_0900_as_cs = mysql::mysql_collations::utf8mb4_tr_0900_as_cs, 298 | utf8mb4_cs_0900_as_cs = mysql::mysql_collations::utf8mb4_cs_0900_as_cs, 299 | utf8mb4_da_0900_as_cs = mysql::mysql_collations::utf8mb4_da_0900_as_cs, 300 | utf8mb4_lt_0900_as_cs = mysql::mysql_collations::utf8mb4_lt_0900_as_cs, 301 | utf8mb4_sk_0900_as_cs = mysql::mysql_collations::utf8mb4_sk_0900_as_cs, 302 | utf8mb4_es_trad_0900_as_cs = mysql::mysql_collations::utf8mb4_es_trad_0900_as_cs, 303 | utf8mb4_la_0900_as_cs = mysql::mysql_collations::utf8mb4_la_0900_as_cs, 304 | utf8mb4_eo_0900_as_cs = mysql::mysql_collations::utf8mb4_eo_0900_as_cs, 305 | utf8mb4_hu_0900_as_cs = mysql::mysql_collations::utf8mb4_hu_0900_as_cs, 306 | utf8mb4_hr_0900_as_cs = mysql::mysql_collations::utf8mb4_hr_0900_as_cs, 307 | utf8mb4_vi_0900_as_cs = mysql::mysql_collations::utf8mb4_vi_0900_as_cs, 308 | utf8mb4_ja_0900_as_cs = mysql::mysql_collations::utf8mb4_ja_0900_as_cs, 309 | utf8mb4_ja_0900_as_cs_ks = mysql::mysql_collations::utf8mb4_ja_0900_as_cs_ks, 310 | utf8mb4_0900_as_ci = mysql::mysql_collations::utf8mb4_0900_as_ci, 311 | utf8mb4_ru_0900_ai_ci = mysql::mysql_collations::utf8mb4_ru_0900_ai_ci, 312 | utf8mb4_ru_0900_as_cs = mysql::mysql_collations::utf8mb4_ru_0900_as_cs, 313 | utf8mb4_zh_0900_as_cs = mysql::mysql_collations::utf8mb4_zh_0900_as_cs, 314 | utf8mb4_0900_bin = mysql::mysql_collations::utf8mb4_0900_bin 315 | }; 316 | 317 | 318 | 319 | #endif // DEFINITIONS_H 320 | 321 | 322 | 323 | -------------------------------------------------------------------------------- /scr/helpers.cpp: -------------------------------------------------------------------------------- 1 | /* helpers.cpp */ 2 | 3 | 4 | #include "helpers.h" 5 | 6 | 7 | using namespace std; 8 | using namespace std::chrono; 9 | 10 | 11 | char* copy_string(char s[]) { 12 | char* s2; 13 | s2 = (char*)malloc(20); 14 | strcpy(s2, s); 15 | return (char*)s2; 16 | } 17 | 18 | 19 | String SqlStr2GdtStr(mysql::string_view s) { 20 | String str(s.data(), s.size()); 21 | return str; 22 | } 23 | 24 | 25 | mysql::string_view GdtStr2SqlStr(String s) { 26 | boost::mysql::string_view str(s.utf8().get_data()); 27 | return str; 28 | } 29 | 30 | 31 | void boost_dictionary(Dictionary *dic, const char *p_function, const char *p_file, int p_line, const mysql::error_code ec) { 32 | dic->clear(); 33 | (*dic)["FILE"] = String(p_file); 34 | (*dic)["LINE"] = p_line; 35 | (*dic)["FUNCTION"] = String(p_function); 36 | (*dic)["ERROR"] = ec.value(); 37 | (*dic)["DESCRIPTION"] = ec.what().data(); 38 | } 39 | 40 | 41 | void print_boost_exception(const char *p_function, const char *p_file, int p_line, const mysql::error_code ec) { 42 | String exc = \ 43 | String("\n# BOOST Error Caught!\n") + \ 44 | vformat("# ERR: Exception in: %s", p_file) + \ 45 | vformat(" in function: %s", p_function) + \ 46 | vformat("() on line %s\n", p_line)+\ 47 | vformat("# ERR: %s\n", ec.value()); 48 | WARN_PRINT(exc); 49 | } 50 | 51 | 52 | void sql_dictionary(Dictionary *dic, const char *p_function, const char *p_file, int p_line, const mysql::diagnostics diag, const mysql::error_code ec) { 53 | dic->clear(); 54 | (*dic)["FILE"] = String(p_file); 55 | (*dic)["LINE"] = p_line; 56 | (*dic)["FUNCTION"] = String(p_function); 57 | (*dic)["ERROR"] = ec.value(); 58 | (*dic)["DESCRIPTION"] = SqlStr2GdtStr(ec.what()); 59 | (*dic)["SERVER_MESSAGE"] = diag.server_message().data(); 60 | (*dic)["CLIENT_MESSAGE"] = diag.client_message().data(); 61 | } 62 | 63 | 64 | void print_sql_exception(const char *p_function, const char *p_file, int p_line, const mysql::diagnostics diag, const mysql::error_code ec) { 65 | String exc = \ 66 | String("\n# SQL EXCEPTION Caught!\n") +\ 67 | vformat("# ERR: SQLException in: %s", p_file) + vformat(" in function: %s", p_function) + vformat("() on line %s\n", p_line) +\ 68 | vformat("# ERR: Code: %s\n", ec.value()) +\ 69 | vformat("# ERR: Description: %s\n", SqlStr2GdtStr(ec.what())) +\ 70 | vformat("# Server error: %s\n", diag.server_message().data()) +\ 71 | vformat("# Client Error: %s\n", diag.client_message().data()); 72 | WARN_PRINT(exc); 73 | } 74 | 75 | 76 | Dictionary make_metadata_result(mysql::metadata_collection_view meta_collection) { 77 | 78 | Dictionary meta; 79 | 80 | for(auto m:meta_collection) { 81 | Dictionary column; 82 | String column_name = String(m.column_name().data()); 83 | 84 | column["column_collation"] = m.column_collation(); 85 | column["column_length"] = m.column_length(); 86 | column["column_name"] = column_name; 87 | column["database"] = String(m.database().data()); 88 | column["decimals"] = m.decimals(); 89 | column["has_no_default_value"] = m.has_no_default_value(); 90 | column["is_auto_increment"] = m.is_auto_increment(); 91 | column["is_multiple_key"] = m.is_multiple_key(); 92 | column["is_not_null"] = m.is_not_null(); 93 | column["is_primary_key"] = m.is_primary_key(); 94 | column["is_set_to_now_on_update"] = m.is_set_to_now_on_update(); 95 | column["is_unique_key"] = m.is_unique_key(); 96 | column["is_unsigned"] = m.is_unsigned(); 97 | column["is_zerofill"] = m.is_zerofill(); 98 | column["original_column_name"] = String(m.original_column_name().data()); 99 | column["original_table"] = String(m.original_table().data()); 100 | column["table"] = String(m.table().data()); 101 | column["type"] = (int)m.type(); 102 | 103 | meta[column_name] = column; 104 | } 105 | return meta; 106 | } 107 | 108 | 109 | Dictionary make_raw_result(mysql::rows_view batch, mysql::metadata_collection_view meta_coll) { 110 | 111 | Dictionary querty_result; 112 | for(size_t row = 0; row < batch.size(); row++) { 113 | Dictionary line = Dictionary(); 114 | size_t f = 0; 115 | for (auto fv : batch.at(row).as_vector()) { 116 | String column_name = String(meta_coll[f].column_name().data()); 117 | mysql::column_type column_type = meta_coll[f].type(); 118 | line[column_name] = field2Var(fv, column_type); 119 | f++; 120 | } 121 | querty_result[row] = line; 122 | } 123 | return querty_result; 124 | } 125 | 126 | 127 | bool is_date(Dictionary d) { 128 | if (d.has("day") and d["day"].get_type() == Variant::INT) { 129 | return true; 130 | } 131 | if (d.has("month") and d["month"].get_type() == Variant::INT) { 132 | return true; 133 | } 134 | if (d.has("year") and d["year"].get_type() == Variant::INT) { 135 | return true; 136 | } 137 | return false; 138 | } 139 | 140 | 141 | bool is_time(Dictionary t) { 142 | if (t.has("hour") and t["hour"].get_type() == Variant::INT) { 143 | return true; 144 | } 145 | if (t.has("minute") and t["minute"].get_type() == Variant::INT) { 146 | return true; 147 | } 148 | if (t.has("second") and t["second"].get_type() == Variant::INT) { 149 | return true; 150 | } 151 | return false; 152 | } 153 | 154 | 155 | bool is_datetime(Dictionary dt) { 156 | if (not is_date(dt)) { 157 | return false; 158 | } 159 | if (not is_time(dt)) { 160 | return false; 161 | } 162 | return true; 163 | } 164 | 165 | 166 | std::vector binds_to_field(const Array arguments) { 167 | 168 | std::vector ret; 169 | 170 | for (int arg = 0; arg < arguments.size(); arg++) { 171 | 172 | mysql::field a_field; 173 | int type = arguments[arg].get_type(); 174 | 175 | if (type == Variant::NIL) { 176 | a_field = nullptr; 177 | } 178 | else if (type == Variant::BOOL) { 179 | bool val = arguments[arg]; 180 | a_field = val; 181 | } 182 | else if (type == Variant::INT) { 183 | long int val = arguments[arg]; 184 | a_field = val; 185 | } 186 | else if (type == Variant::FLOAT) { 187 | double val = arguments[arg]; 188 | a_field = val; 189 | } 190 | else if (type == Variant::STRING) { 191 | String str = arguments[arg]; 192 | const char * val =str.utf8().get_data(); 193 | a_field = val; 194 | } 195 | else if (type == Variant::PACKED_BYTE_ARRAY) { 196 | Vector input = arguments[arg]; 197 | mysql::blob val; 198 | for (int p = 0; p < input.size(); p++) { 199 | val.push_back((unsigned char)input[p]); 200 | } 201 | a_field = val; 202 | } 203 | 204 | else if (type == Variant::DICTIONARY) { 205 | Dictionary ts = arguments[arg]; 206 | if (is_datetime(ts)) { 207 | uint16_t year = ts.has("year") ? (uint16_t)ts["year"] : 0; 208 | uint8_t month = ts.has("month") ? (uint8_t)ts["month"] : 0; 209 | uint8_t day = ts.has("day") ? (uint8_t)ts["day"] : 0; 210 | uint16_t hour = ts.has("hour") ? (uint16_t)ts["hour"] : 0; 211 | uint16_t minute = ts.has("minute") ? (uint16_t)ts["minute"] : 0; 212 | uint16_t second = ts.has("second") ? (uint16_t)ts["second"] : 0; 213 | mysql::datetime val(year, month, day, hour, minute, second); 214 | a_field = val; 215 | } 216 | else if(is_date(ts)) { 217 | uint16_t year = ts.has("year") ? (uint16_t)ts["year"] : 0; 218 | uint8_t month = ts.has("month") ? (uint8_t)ts["month"] : 0; 219 | uint8_t day = ts.has("day") ? (uint8_t)ts["day"] : 0; 220 | mysql::date val(year, month, day); 221 | a_field = val; 222 | } 223 | else if (is_time(ts)) { 224 | int hour = ts.has("hour") ? (int)ts["hour"] : 0; 225 | int minute = ts.has("minute") ? (int)ts["minute"] : 0; 226 | int second = ts.has("second") ? (int)ts["second"] : 0; 227 | microseconds val = hours(hour) + minutes(minute) + seconds(second); 228 | a_field = val; 229 | } 230 | //TODO: else{Throw error} 231 | } 232 | 233 | ret.push_back(a_field); 234 | 235 | } 236 | 237 | return ret; 238 | 239 | } 240 | 241 | 242 | 243 | Variant field2Var(const mysql::field_view fv, mysql::column_type column_type) { 244 | 245 | if (fv.is_null()) { 246 | Variant n = Variant(); 247 | return n; 248 | } 249 | 250 | else if (column_type == mysql::column_type::tinyint) { 251 | bool b = (bool)fv.get_int64(); 252 | return b; 253 | } 254 | 255 | else if (fv.is_int64()) { 256 | int64_t i = fv.as_int64(); 257 | return i; 258 | } 259 | 260 | else if (fv.is_uint64()) { 261 | uint64_t ui = fv.get_uint64(); 262 | return ui; 263 | } 264 | 265 | else if (fv.is_float()) { 266 | float f = fv.get_float(); 267 | return f; 268 | } 269 | 270 | else if (fv.is_double()) { 271 | double d = fv.get_double(); 272 | return d; 273 | } 274 | 275 | else if (column_type == mysql::column_type::set){ 276 | String s; 277 | s = String(fv.get_string().data()); 278 | return s.split(","); 279 | } 280 | 281 | else if (fv.is_string()) { 282 | String s; 283 | s = String(fv.get_string().data()); 284 | return s; 285 | } 286 | 287 | else if (fv.is_blob()) { 288 | mysql::blob_view bw = fv.get_blob(); 289 | const unsigned char* b = bw.data(); 290 | Vector gdt_blob; 291 | gdt_blob.resize(bw.size()); 292 | memcpy(gdt_blob.ptrw(), b, bw.size()); 293 | return gdt_blob; 294 | } 295 | 296 | else if (fv.is_date()) { 297 | Dictionary gdt_date; 298 | gdt_date["day"] = fv.get_date().day(); 299 | gdt_date["month"] = fv.get_date().month(); 300 | gdt_date["year"] = fv.get_date().year(); 301 | return gdt_date; 302 | } 303 | 304 | else if (fv.is_datetime()) { 305 | Dictionary gdt_datetime; 306 | gdt_datetime["day"] = fv.get_datetime().day(); 307 | gdt_datetime["month"] = fv.get_datetime().month(); 308 | gdt_datetime["year"] = fv.get_datetime().year(); 309 | gdt_datetime["hour"] = fv.get_datetime().hour(); 310 | gdt_datetime["minute"] = fv.get_datetime().minute(); 311 | gdt_datetime["second"] = fv.get_datetime().second(); 312 | return gdt_datetime; 313 | } 314 | 315 | else if (fv.is_time()) { 316 | 317 | Dictionary gdt_time; 318 | time_point point_time = time_point(fv.get_time()); 319 | 320 | auto t_hour = duration_cast(point_time.time_since_epoch()); 321 | point_time -= t_hour; 322 | auto t_minutes = duration_cast(point_time.time_since_epoch()); 323 | point_time -= t_minutes; 324 | auto t_second = duration_cast(point_time.time_since_epoch()); 325 | point_time -= t_second; 326 | 327 | gdt_time["hour"] = t_hour.count(); 328 | gdt_time["minute"] = t_minutes.count(); 329 | gdt_time["second"] = t_second.count(); 330 | return gdt_time; 331 | } 332 | 333 | return Variant(); 334 | 335 | } 336 | 337 | -------------------------------------------------------------------------------- /scr/helpers.h: -------------------------------------------------------------------------------- 1 | /* helpers.h */ 2 | 3 | 4 | #ifndef HELPERS_H 5 | #define HELPERS_H 6 | 7 | 8 | #include "constants.h" 9 | 10 | #include "core/object/ref_counted.h" 11 | #include "core/core_bind.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | void boost_dictionary(Dictionary *dic, const char *p_function, const char *p_file, int p_line, const mysql::error_code ec); 24 | void sql_dictionary(Dictionary *dic, const char *p_function, const char *p_file, int p_line, const mysql::diagnostics diag, const mysql::error_code ec); 25 | void print_boost_exception(const char *p_function, const char *p_file, int p_line, const mysql::error_code ec); 26 | void print_sql_exception(const char *p_function, const char *p_file, int p_line, const mysql::diagnostics diag, const mysql::error_code ec); 27 | void print_std_exception(const char *p_function, const char *p_file, int p_line, std::exception err); 28 | 29 | 30 | char* copy_string(char s[]); 31 | String SqlStr2GdtStr(mysql::string_view s); 32 | mysql::string_view GdtStr2SqlStr(String s); 33 | 34 | 35 | bool is_date(Dictionary d); 36 | bool is_datetime(Dictionary dt); 37 | bool is_time(Dictionary t); 38 | std::vector binds_to_field(const Array args); 39 | Variant field2Var(const mysql::field_view fv, mysql::column_type column_type); 40 | Dictionary make_metadata_result(mysql::metadata_collection_view meta_collection); 41 | Dictionary make_raw_result(mysql::rows_view batch, mysql::metadata_collection_view meta_coll); 42 | 43 | 44 | #define BOOST_EXCEPTION(m_errcode, m_dic, m_ret) \ 45 | if (unlikely(m_errcode)) { \ 46 | boost_dictionary(m_dic, FUNCTION_NAME, __FILE__, __LINE__, m_errcode); \ 47 | print_boost_exception(FUNCTION_NAME, __FILE__, __LINE__, m_errcode); \ 48 | return (Error)-m_errcode.value(); \ 49 | } else \ 50 | ((void)0) 51 | 52 | #define SQL_EXCEPTION(m_errcode, m_diag, m_dic, m_ret) \ 53 | if (unlikely(m_errcode)) { \ 54 | sql_dictionary(m_dic, FUNCTION_NAME, __FILE__, __LINE__, m_diag, m_errcode);\ 55 | print_sql_exception(FUNCTION_NAME, __FILE__, __LINE__, m_diag, m_errcode); \ 56 | return m_ret; \ 57 | } else \ 58 | ((void)0) 59 | 60 | #define CORO_SQL_EXCEPTION(m_errcode, m_diag, m_dic, m_ret) \ 61 | if (unlikely(m_errcode)) { \ 62 | sql_dictionary(m_dic, FUNCTION_NAME, __FILE__, __LINE__, m_diag, m_errcode);\ 63 | print_sql_exception(FUNCTION_NAME, __FILE__, __LINE__, m_diag, m_errcode); \ 64 | } else \ 65 | ((void)0) 66 | 67 | #define CORO_SQL_EXCEPTION_VOID(m_errcode, m_diag, m_dic) \ 68 | if (unlikely(m_errcode)) { \ 69 | sql_dictionary(m_dic, FUNCTION_NAME, __FILE__, __LINE__, m_diag, m_errcode);\ 70 | print_sql_exception(FUNCTION_NAME, __FILE__, __LINE__, m_diag, m_errcode); \ 71 | co_return; \ 72 | } else \ 73 | ((void)0) 74 | 75 | 76 | #endif // HELPERS_H 77 | 78 | -------------------------------------------------------------------------------- /scr/mysql.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* mysql.cpp */ 4 | 5 | 6 | #include "mysql.h" 7 | 8 | 9 | Error MySQL::define(const ConnType _type, const String p_cert_file, const String p_host_name) { 10 | 11 | last_error.clear(); 12 | type = _type; 13 | 14 | tcp_conn.reset(); 15 | tcp_ssl_conn.reset(); 16 | unix_conn.reset(); 17 | unix_ssl_conn.reset(); 18 | resolver.reset(); 19 | ssl_ctx.reset(); 20 | ctx.reset(); 21 | 22 | bool is_ssl = (type == TCPTLS or type == UNIXTLS); 23 | if (is_ssl and not p_cert_file.is_empty()){ 24 | WARN_PRINT("Connection type is not TCPTLS or UNIXTLS! The certificate ill be ignorated."); 25 | } 26 | 27 | if (type == TCP){ 28 | ctx = std::make_shared(); 29 | tcp_conn = std::make_shared(ctx->get_executor()); 30 | resolver = std::make_shared(ctx->get_executor()); 31 | tcp_conn->set_meta_mode(mysql::metadata_mode::full); 32 | } 33 | 34 | else if (type == TCPTLS){ 35 | ctx = std::make_shared(); 36 | ssl_ctx = std::make_shared(asio::ssl::context::tls_client); 37 | if (is_ssl and not p_cert_file.is_empty()){ 38 | Error err = set_certificate(p_cert_file, p_host_name); 39 | if (err){ 40 | return err; 41 | } 42 | } 43 | tcp_ssl_conn = std::make_shared(ctx->get_executor(), *ssl_ctx); 44 | resolver = std::make_shared(ctx->get_executor()); 45 | tcp_ssl_conn->set_meta_mode(mysql::metadata_mode::full); 46 | } 47 | 48 | else if (type == UNIX){ 49 | ctx = std::make_shared(); 50 | unix_conn = std::make_shared(*ctx); 51 | unix_conn->set_meta_mode(mysql::metadata_mode::full); 52 | } 53 | 54 | else if (type == UNIXTLS){ 55 | ctx = std::make_shared(); 56 | ssl_ctx = std::make_shared(asio::ssl::context::tls_client); 57 | if (is_ssl and not p_cert_file.is_empty()){ 58 | Error err = set_certificate(p_cert_file, p_host_name); 59 | if (err){ 60 | return err; 61 | } 62 | } 63 | unix_ssl_conn = std::make_shared(*ctx, *ssl_ctx); 64 | unix_ssl_conn->set_meta_mode(mysql::metadata_mode::full); 65 | } 66 | 67 | return OK; 68 | 69 | } 70 | 71 | 72 | Error MySQL::set_certificate(const String p_cert_file, const String p_host_name){ 73 | 74 | const std::string& cert_path = p_cert_file.utf8().get_data(); 75 | const std::string& host = p_host_name.utf8().get_data(); 76 | last_error.clear(); 77 | mysql::error_code ec; 78 | 79 | ssl_ctx->set_verify_mode(boost::asio::ssl::verify_peer, ec); 80 | BOOST_EXCEPTION(ec, &last_error, FAILED); 81 | ssl_ctx->set_verify_callback(ssl::host_name_verification(host), ec); 82 | BOOST_EXCEPTION(ec, &last_error, FAILED); 83 | ssl_ctx->load_verify_file(cert_path, ec); 84 | BOOST_EXCEPTION(ec, &last_error, FAILED); 85 | return OK; 86 | } 87 | 88 | 89 | Dictionary MySQL::get_credentials() const { 90 | 91 | Dictionary ret; 92 | ret["username"] = String(conn_params.username().data()); 93 | ret["password"] = String(conn_params.password().data()); 94 | ret["database"] = String(conn_params.database().data()); 95 | ret["connection_collation"] = (int)conn_params.connection_collation(); 96 | ret["ssl"] = (SslMode)conn_params.ssl(); 97 | ret["multi_queries"] = conn_params.multi_queries(); 98 | return ret; 99 | } 100 | 101 | 102 | Error MySQL::set_credentials(String p_username, String p_password, String p_database, std::uint16_t collation, SslMode p_ssl, bool multi_queries) { 103 | 104 | username = copy_string(const_cast(p_username.utf8().get_data())); 105 | password = copy_string(const_cast(p_password.utf8().get_data())); 106 | database = copy_string(const_cast(p_database.utf8().get_data())); 107 | 108 | // TODO: Testar se pode ser removido. 109 | conn_params.set_username(username); 110 | conn_params.set_password(password); 111 | conn_params.set_database(database); 112 | //TODO/ 113 | 114 | conn_params.set_connection_collation(collation); 115 | conn_params.set_ssl((mysql::ssl_mode)p_ssl); 116 | conn_params.set_multi_queries(multi_queries); 117 | 118 | return OK; 119 | 120 | } 121 | 122 | 123 | Error MySQL::tcp_connect(const String p_hostname, const String p_port) { 124 | 125 | last_error.clear(); 126 | bool is_tcp = (type == TCP or type == TCPTLS); 127 | ERR_FAIL_COND_V_EDMSG(not is_tcp, ERR_INVALID_PARAMETER,\ 128 | "The tcp_connect function was designed to work with TCP connections only. For UNIX connections use unix_connect method."); 129 | 130 | const char * hostname = p_hostname.utf8().get_data(); 131 | const char * port = p_port.utf8().get_data(); 132 | 133 | mysql::error_code ec; 134 | mysql::diagnostics diag; 135 | 136 | auto endpoints = resolver->resolve(hostname, port, ec); 137 | if (type == TCP){ 138 | tcp_conn->connect(*endpoints.begin(), conn_params, ec, diag); 139 | } 140 | else { 141 | tcp_ssl_conn->connect(*endpoints.begin(), conn_params, ec, diag); 142 | } 143 | SQL_EXCEPTION(ec, diag, &last_error, FAILED); 144 | return OK; 145 | 146 | 147 | } 148 | 149 | 150 | Error MySQL::unix_connect(const String p_socket_path) { 151 | 152 | last_error.clear(); 153 | bool is_unix = (type == UNIX or type == UNIXTLS); 154 | ERR_FAIL_COND_V_EDMSG(not is_unix, ERR_INVALID_PARAMETER, "The unix_connect function was designed to work with UNIX connections only. For TCP connections use tcp_connect method."); 155 | 156 | const char * socket = p_socket_path.utf8().get_data(); 157 | 158 | mysql::error_code ec; 159 | mysql::diagnostics diag; 160 | 161 | local::stream_protocol::endpoint endpoints(socket); 162 | if (type == UNIX){ 163 | unix_conn->connect(endpoints, conn_params, ec, diag); 164 | } 165 | else { 166 | unix_ssl_conn->connect(endpoints, conn_params, ec, diag); 167 | } 168 | SQL_EXCEPTION(ec, diag, &last_error, FAILED); 169 | 170 | return OK; 171 | } 172 | 173 | 174 | Error MySQL::close_connection() { 175 | 176 | last_error.clear(); 177 | mysql::error_code ec; 178 | mysql::diagnostics diag; 179 | 180 | if (type == TCP){ 181 | tcp_conn->close(ec, diag); 182 | } 183 | else if (type == TCPTLS){ 184 | tcp_ssl_conn->close(ec, diag); 185 | } 186 | else if (type == UNIX){ 187 | unix_conn->close(ec, diag); 188 | } 189 | else if (type == UNIXTLS){ 190 | unix_ssl_conn->close(ec, diag); 191 | } 192 | 193 | SQL_EXCEPTION(ec, diag, &last_error, FAILED); 194 | return OK; 195 | } 196 | 197 | 198 | 199 | bool MySQL::is_server_alive() { 200 | 201 | mysql::error_code ec; 202 | mysql::diagnostics diag; 203 | 204 | if (type == TCP){ 205 | tcp_conn->ping(ec, diag); 206 | } 207 | else if (type == TCPTLS){ 208 | tcp_ssl_conn->ping(ec, diag); 209 | } 210 | else if (type == UNIX){ 211 | unix_conn->ping(ec, diag); 212 | } 213 | else if (type == UNIXTLS){ 214 | unix_ssl_conn->ping(ec, diag); 215 | } 216 | 217 | if (ec){ 218 | return false; 219 | } 220 | 221 | return true; 222 | } 223 | 224 | 225 | Ref MySQL::build_godot_result(mysql::results result){ 226 | 227 | Ref gdt_result = Ref(memnew(SqlResult())); 228 | gdt_result->result = make_raw_result(result.rows(), result.meta()); 229 | gdt_result->meta = make_metadata_result(result.meta()); 230 | gdt_result->affected_rows = result.affected_rows(); 231 | gdt_result->last_insert_id = result.last_insert_id(); 232 | gdt_result->warning_count = result.warning_count(); 233 | return gdt_result; 234 | 235 | } 236 | 237 | Ref MySQL::build_godot_result( 238 | mysql::rows_view batch, mysql::metadata_collection_view meta_collection, 239 | std::uint64_t affected_rows, std::uint64_t last_insert_id, unsigned warning_count 240 | ) 241 | { 242 | Ref gdt_result = Ref(memnew(SqlResult())); 243 | gdt_result->result = make_raw_result(batch, meta_collection); 244 | gdt_result->meta = make_metadata_result(meta_collection); 245 | gdt_result->affected_rows = affected_rows; 246 | gdt_result->last_insert_id = last_insert_id; 247 | gdt_result->warning_count = warning_count; 248 | return gdt_result; 249 | } 250 | 251 | 252 | 253 | Ref MySQL::execute(const String p_stmt) { 254 | 255 | const char* query = p_stmt.utf8().get_data(); 256 | boost::mysql::results result; 257 | mysql::error_code ec; 258 | mysql::diagnostics diag; 259 | last_error.clear(); 260 | 261 | if (type == TCP){ 262 | tcp_conn->execute(query, result, ec, diag); 263 | } 264 | else if (type == TCPTLS){ 265 | tcp_ssl_conn->execute(query, result, ec, diag); 266 | } 267 | else if (type == UNIX){ 268 | unix_conn->execute(query, result, ec, diag); 269 | } 270 | else if (type == UNIXTLS){ 271 | unix_ssl_conn->execute(query, result, ec, diag); 272 | } 273 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 274 | 275 | return build_godot_result(result); 276 | 277 | } 278 | 279 | 280 | Ref MySQL::execute_prepared(const String p_stmt, const Array binds) { 281 | 282 | std::vector args = binds_to_field(binds); 283 | const char* query = p_stmt.utf8().get_data(); 284 | mysql::error_code ec; 285 | mysql::diagnostics diag; 286 | mysql::results result; 287 | last_error.clear(); 288 | 289 | if (type == TCP){ 290 | mysql::statement prep_stmt = tcp_conn->prepare_statement(query, ec, diag); 291 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 292 | tcp_conn->execute(prep_stmt.bind(args.begin(), args.end()), result, ec, diag); 293 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 294 | tcp_conn->close_statement(prep_stmt, ec, diag); 295 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 296 | } 297 | else if (type == TCPTLS){ 298 | mysql::statement prep_stmt = tcp_ssl_conn->prepare_statement(query, ec, diag); 299 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 300 | tcp_ssl_conn->execute(prep_stmt.bind(args.begin(), args.end()), result, ec, diag); 301 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 302 | tcp_ssl_conn->close_statement(prep_stmt, ec, diag); 303 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 304 | } 305 | else if (type == UNIX){ 306 | mysql::statement prep_stmt = unix_conn->prepare_statement(query, ec, diag); 307 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 308 | unix_conn->execute(prep_stmt.bind(args.begin(), args.end()), result, ec, diag); 309 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 310 | unix_conn->close_statement(prep_stmt, ec, diag); 311 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 312 | } 313 | else if (type == UNIXTLS){ 314 | mysql::statement prep_stmt = unix_ssl_conn->prepare_statement(query, ec, diag); 315 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 316 | unix_ssl_conn->execute(prep_stmt.bind(args.begin(), args.end()), result, ec, diag); 317 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 318 | unix_ssl_conn->close_statement(prep_stmt, ec, diag); 319 | SQL_EXCEPTION(ec, diag, &last_error, Ref()); 320 | } 321 | 322 | 323 | 324 | return build_godot_result(result); 325 | } 326 | 327 | 328 | boost::asio::awaitable MySQL::coro_execute(const char* query, std::shared_ptr result){ 329 | 330 | mysql::diagnostics diag; 331 | mysql::error_code ec; 332 | 333 | if (type == TCP){ 334 | std::tie(ec) = co_await tcp_conn->async_execute(query, *result, diag, tuple_awaitable); 335 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 336 | } 337 | else if (type == TCPTLS){ 338 | std::tie(ec) = co_await tcp_ssl_conn->async_execute(query, *result, diag, tuple_awaitable); 339 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 340 | } 341 | else if (type == UNIX){ 342 | std::tie(ec) = co_await unix_conn->async_execute(query, *result, diag, tuple_awaitable); 343 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 344 | } 345 | else if (type == UNIXTLS){ 346 | std::tie(ec) = co_await unix_ssl_conn->async_execute(query, *result, diag, tuple_awaitable); 347 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 348 | } 349 | } 350 | 351 | 352 | Ref MySQL::async_execute(const String p_stmt){ 353 | 354 | const char* query = p_stmt.utf8().get_data(); 355 | std::shared_ptr result = std::make_shared(); 356 | 357 | boost::asio::co_spawn( 358 | ctx->get_executor(), 359 | [query, result, this] { return coro_execute(query, result); }, 360 | boost::asio::detached 361 | ); 362 | ctx->run(); 363 | return build_godot_result(*result); 364 | } 365 | 366 | 367 | boost::asio::awaitable MySQL::coro_execute_prepared(const char* query, std::vector args, std::shared_ptr result){ 368 | 369 | mysql::diagnostics diag; 370 | mysql::error_code ec; 371 | mysql::statement prep_stmt; 372 | 373 | if (type == TCP){ 374 | std::tie(ec, prep_stmt) = co_await tcp_conn->async_prepare_statement(query, diag, tuple_awaitable); 375 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 376 | std::tie(ec) = co_await tcp_conn->async_execute(prep_stmt.bind(args.begin(), args.end()), *result, diag, tuple_awaitable); 377 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 378 | std::tie(ec) = co_await tcp_conn->async_close_statement(prep_stmt, diag, tuple_awaitable); 379 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 380 | 381 | } 382 | else if (type == TCPTLS){ 383 | std::tie(ec, prep_stmt) = co_await tcp_ssl_conn->async_prepare_statement(query, diag, tuple_awaitable); 384 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 385 | std::tie(ec) = co_await tcp_ssl_conn->async_execute(prep_stmt.bind(args.begin(), args.end()), *result, diag, tuple_awaitable); 386 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 387 | std::tie(ec) = co_await tcp_ssl_conn->async_close_statement(prep_stmt, diag, tuple_awaitable); 388 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 389 | } 390 | else if (type == UNIX){ 391 | std::tie(ec, prep_stmt) = co_await unix_conn->async_prepare_statement(query, diag, tuple_awaitable); 392 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 393 | std::tie(ec) = co_await unix_conn->async_execute(prep_stmt.bind(args.begin(), args.end()), *result, diag, tuple_awaitable); 394 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 395 | std::tie(ec) = co_await unix_conn->async_close_statement(prep_stmt, diag, tuple_awaitable); 396 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 397 | } 398 | else if (type == UNIXTLS){ 399 | std::tie(ec, prep_stmt) = co_await unix_ssl_conn->async_prepare_statement(query, diag, tuple_awaitable); 400 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 401 | std::tie(ec) = co_await unix_ssl_conn->async_execute(prep_stmt.bind(args.begin(), args.end()), *result, diag, tuple_awaitable); 402 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 403 | std::tie(ec) = co_await unix_ssl_conn->async_close_statement(prep_stmt, diag, tuple_awaitable); 404 | CORO_SQL_EXCEPTION_VOID(ec, diag, &last_error); 405 | } 406 | 407 | } 408 | 409 | 410 | Ref MySQL::async_execute_prepared(const String p_stmt, const Array binds){ 411 | 412 | const char* query = p_stmt.utf8().get_data(); 413 | std::vector args = binds_to_field(binds); 414 | std::shared_ptr result = std::make_shared(); 415 | 416 | boost::asio::co_spawn( 417 | ctx->get_executor(), 418 | [query, args, result, this] { return coro_execute_prepared(query, args, result); }, 419 | boost::asio::detached 420 | ); 421 | ctx->run(); 422 | return build_godot_result(*result); 423 | } 424 | 425 | 426 | 427 | Array MySQL::execute_sql(const String p_path_to_file){ 428 | 429 | ERR_FAIL_COND_V_EDMSG(not conn_params.multi_queries(), Array(), "This function requires that credentials.multi_queries be enable, once it's uses using multi-queries"); 430 | 431 | ProjectSettings &ps = *ProjectSettings::get_singleton(); 432 | const char *path_to_file = ps.globalize_path(p_path_to_file).utf8().get_data(); 433 | std::ifstream ifs(path_to_file); 434 | ERR_FAIL_COND_V_EDMSG(not ifs, Array(), "Cannot open file: " + p_path_to_file); 435 | std::string script_contents = std::string(std::istreambuf_iterator(ifs), std::istreambuf_iterator()); 436 | 437 | return multiqueries(script_contents); 438 | 439 | } 440 | 441 | 442 | Array MySQL::execute_multi(const String p_queries){ 443 | 444 | ERR_FAIL_COND_V_EDMSG(not conn_params.multi_queries(), Array(), "This function requires that credentials.multi_queries be enable, once it's uses using multi-queries"); 445 | std::string q(p_queries.utf8().get_data()); 446 | return multiqueries(q); 447 | } 448 | 449 | 450 | 451 | Array MySQL::multiqueries(std::string queries){ 452 | 453 | mysql::execution_state st; 454 | mysql::diagnostics diag; 455 | mysql::error_code ec; 456 | last_error.clear(); 457 | Array ret; 458 | 459 | if (type == TCP){ 460 | tcp_conn->start_execution(queries, st, ec, diag); 461 | SQL_EXCEPTION(ec, diag, &last_error, ret); 462 | } 463 | else if (type == TCPTLS){ 464 | tcp_ssl_conn->start_execution(queries, st, ec, diag); 465 | SQL_EXCEPTION(ec, diag, &last_error, ret); 466 | } 467 | else if (type == UNIX){ 468 | unix_conn->start_execution(queries, st, ec, diag); 469 | SQL_EXCEPTION(ec, diag, &last_error, ret); 470 | } 471 | else if (type == UNIXTLS){ 472 | unix_ssl_conn->start_execution(queries, st, ec, diag); 473 | SQL_EXCEPTION(ec, diag, &last_error, ret); 474 | } 475 | 476 | for (std::size_t resultset_number = 0; !st.complete(); ++resultset_number) { 477 | if (st.should_read_head()) { 478 | if (type == TCP){ 479 | tcp_conn->read_resultset_head(st, ec, diag); 480 | SQL_EXCEPTION(ec, diag, &last_error, ret); 481 | mysql::rows_view batch = tcp_conn->read_some_rows(st, ec, diag); 482 | SQL_EXCEPTION(ec, diag, &last_error, ret); 483 | ret.append(build_godot_result(batch, st.meta(), st.affected_rows(), st.last_insert_id(), st.warning_count())); 484 | } 485 | else if (type == TCPTLS){ 486 | tcp_ssl_conn->read_resultset_head(st, ec, diag); 487 | SQL_EXCEPTION(ec, diag, &last_error, ret); 488 | mysql::rows_view batch = tcp_ssl_conn->read_some_rows(st, ec, diag); 489 | SQL_EXCEPTION(ec, diag, &last_error, ret); 490 | ret.append(build_godot_result(batch, st.meta(), st.affected_rows(), st.last_insert_id(), st.warning_count())); 491 | } 492 | else if (type == UNIX){ 493 | unix_conn->read_resultset_head(st, ec, diag); 494 | SQL_EXCEPTION(ec, diag, &last_error, ret); 495 | mysql::rows_view batch = unix_conn->read_some_rows(st, ec, diag); 496 | SQL_EXCEPTION(ec, diag, &last_error, ret); 497 | ret.append(build_godot_result(batch, st.meta(), st.affected_rows(), st.last_insert_id(), st.warning_count())); 498 | } 499 | else if (type == UNIXTLS){ 500 | unix_ssl_conn->read_resultset_head(st, ec, diag); 501 | SQL_EXCEPTION(ec, diag, &last_error, ret); 502 | mysql::rows_view batch = unix_ssl_conn->read_some_rows(st, ec, diag); 503 | SQL_EXCEPTION(ec, diag, &last_error, ret); 504 | ret.append(build_godot_result(batch, st.meta(), st.affected_rows(), st.last_insert_id(), st.warning_count())); 505 | } 506 | } 507 | } 508 | return ret; 509 | 510 | } 511 | 512 | 513 | void MySQL::_bind_methods() { 514 | 515 | ClassDB::bind_method(D_METHOD("define", "connection type", "certificate file", "hostname verification"), &MySQL::define, DEFVAL(ConnType::TCPTLS), DEFVAL(""), DEFVAL("mysql")); 516 | ClassDB::bind_method(D_METHOD("get_credentials"), &MySQL::get_credentials); 517 | ClassDB::bind_method(D_METHOD("set_credentials", "username", "password", "database", "collation", "ssl_mode", "multi_queries"),\ 518 | &MySQL::set_credentials, DEFVAL(""), DEFVAL(default_collation), DEFVAL(ssl_enable), DEFVAL(false)); 519 | 520 | ClassDB::bind_method(D_METHOD("tcp_connect", "hostname", "port"), &MySQL::tcp_connect, DEFVAL("127.0.0.1"), DEFVAL("3306")); 521 | ClassDB::bind_method(D_METHOD("unix_connect", "socket_path"), &MySQL::unix_connect, DEFVAL("/var/run/mysqld/mysqld.sock")); 522 | ClassDB::bind_method(D_METHOD("close_connection"), &MySQL::close_connection); 523 | ClassDB::bind_method(D_METHOD("is_server_alive"), &MySQL::is_server_alive); 524 | 525 | ClassDB::bind_method(D_METHOD("get_connection_type"), &MySQL::get_connection_type); 526 | ClassDB::bind_method(D_METHOD("get_last_error"), &MySQL::get_last_error); 527 | 528 | ClassDB::bind_method(D_METHOD("execute", "query"), &MySQL::execute); 529 | ClassDB::bind_method(D_METHOD("execute_prepared", "statement", "values"), &MySQL::execute_prepared, DEFVAL(Array())); 530 | ClassDB::bind_method(D_METHOD("execute_sql", "sql path"), &MySQL::execute_sql); 531 | ClassDB::bind_method(D_METHOD("execute_multi", "queries"), &MySQL::execute_multi); 532 | 533 | ClassDB::bind_method(D_METHOD("async_execute", "query"), &MySQL::async_execute); 534 | ClassDB::bind_method(D_METHOD("async_execute_prepared", "query", "values"), &MySQL::async_execute_prepared, DEFVAL(Array())); 535 | 536 | 537 | BIND_ENUM_CONSTANT(TCP); 538 | BIND_ENUM_CONSTANT(TCPTLS); 539 | BIND_ENUM_CONSTANT(UNIX); 540 | BIND_ENUM_CONSTANT(UNIXTLS); 541 | 542 | BIND_ENUM_CONSTANT(ssl_disable); 543 | BIND_ENUM_CONSTANT(ssl_enable); 544 | BIND_ENUM_CONSTANT(ssl_require); 545 | 546 | BIND_ENUM_CONSTANT(default_collation); 547 | BIND_ENUM_CONSTANT(big5_chinese_ci); 548 | BIND_ENUM_CONSTANT(latin2_czech_cs); 549 | BIND_ENUM_CONSTANT(dec8_swedish_ci); 550 | BIND_ENUM_CONSTANT(cp850_general_ci); 551 | BIND_ENUM_CONSTANT(latin1_german1_ci); 552 | BIND_ENUM_CONSTANT(hp8_english_ci); 553 | BIND_ENUM_CONSTANT(koi8r_general_ci); 554 | BIND_ENUM_CONSTANT(latin1_swedish_ci); 555 | BIND_ENUM_CONSTANT(latin2_general_ci); 556 | BIND_ENUM_CONSTANT(swe7_swedish_ci); 557 | BIND_ENUM_CONSTANT(ascii_general_ci); 558 | BIND_ENUM_CONSTANT(ujis_japanese_ci); 559 | BIND_ENUM_CONSTANT(sjis_japanese_ci); 560 | BIND_ENUM_CONSTANT(cp1251_bulgarian_ci); 561 | BIND_ENUM_CONSTANT(latin1_danish_ci); 562 | BIND_ENUM_CONSTANT(hebrew_general_ci); 563 | BIND_ENUM_CONSTANT(tis620_thai_ci); 564 | BIND_ENUM_CONSTANT(euckr_korean_ci); 565 | BIND_ENUM_CONSTANT(latin7_estonian_cs); 566 | BIND_ENUM_CONSTANT(latin2_hungarian_ci); 567 | BIND_ENUM_CONSTANT(koi8u_general_ci); 568 | BIND_ENUM_CONSTANT(cp1251_ukrainian_ci); 569 | BIND_ENUM_CONSTANT(gb2312_chinese_ci); 570 | BIND_ENUM_CONSTANT(greek_general_ci); 571 | BIND_ENUM_CONSTANT(cp1250_general_ci); 572 | BIND_ENUM_CONSTANT(latin2_croatian_ci); 573 | BIND_ENUM_CONSTANT(gbk_chinese_ci); 574 | BIND_ENUM_CONSTANT(cp1257_lithuanian_ci); 575 | BIND_ENUM_CONSTANT(latin5_turkish_ci); 576 | BIND_ENUM_CONSTANT(latin1_german2_ci); 577 | BIND_ENUM_CONSTANT(armscii8_general_ci); 578 | BIND_ENUM_CONSTANT(utf8_general_ci); 579 | BIND_ENUM_CONSTANT(cp1250_czech_cs); 580 | BIND_ENUM_CONSTANT(ucs2_general_ci); 581 | BIND_ENUM_CONSTANT(cp866_general_ci); 582 | BIND_ENUM_CONSTANT(keybcs2_general_ci); 583 | BIND_ENUM_CONSTANT(macce_general_ci); 584 | BIND_ENUM_CONSTANT(macroman_general_ci); 585 | BIND_ENUM_CONSTANT(cp852_general_ci); 586 | BIND_ENUM_CONSTANT(latin7_general_ci); 587 | BIND_ENUM_CONSTANT(latin7_general_cs); 588 | BIND_ENUM_CONSTANT(macce_bin); 589 | BIND_ENUM_CONSTANT(cp1250_croatian_ci); 590 | BIND_ENUM_CONSTANT(utf8mb4_general_ci); 591 | BIND_ENUM_CONSTANT(utf8mb4_bin); 592 | BIND_ENUM_CONSTANT(latin1_bin); 593 | BIND_ENUM_CONSTANT(latin1_general_ci); 594 | BIND_ENUM_CONSTANT(latin1_general_cs); 595 | BIND_ENUM_CONSTANT(cp1251_bin); 596 | BIND_ENUM_CONSTANT(cp1251_general_ci); 597 | BIND_ENUM_CONSTANT(cp1251_general_cs); 598 | BIND_ENUM_CONSTANT(macroman_bin); 599 | BIND_ENUM_CONSTANT(utf16_general_ci); 600 | BIND_ENUM_CONSTANT(utf16_bin); 601 | BIND_ENUM_CONSTANT(utf16le_general_ci); 602 | BIND_ENUM_CONSTANT(cp1256_general_ci); 603 | BIND_ENUM_CONSTANT(cp1257_bin); 604 | BIND_ENUM_CONSTANT(cp1257_general_ci); 605 | BIND_ENUM_CONSTANT(utf32_general_ci); 606 | BIND_ENUM_CONSTANT(utf32_bin); 607 | BIND_ENUM_CONSTANT(utf16le_bin); 608 | BIND_ENUM_CONSTANT(binary); 609 | BIND_ENUM_CONSTANT(armscii8_bin); 610 | BIND_ENUM_CONSTANT(ascii_bin); 611 | BIND_ENUM_CONSTANT(cp1250_bin); 612 | BIND_ENUM_CONSTANT(cp1256_bin); 613 | BIND_ENUM_CONSTANT(cp866_bin); 614 | BIND_ENUM_CONSTANT(dec8_bin); 615 | BIND_ENUM_CONSTANT(greek_bin); 616 | BIND_ENUM_CONSTANT(hebrew_bin); 617 | BIND_ENUM_CONSTANT(hp8_bin); 618 | BIND_ENUM_CONSTANT(keybcs2_bin); 619 | BIND_ENUM_CONSTANT(koi8r_bin); 620 | BIND_ENUM_CONSTANT(koi8u_bin); 621 | BIND_ENUM_CONSTANT(utf8_tolower_ci); 622 | BIND_ENUM_CONSTANT(latin2_bin); 623 | BIND_ENUM_CONSTANT(latin5_bin); 624 | BIND_ENUM_CONSTANT(latin7_bin); 625 | BIND_ENUM_CONSTANT(cp850_bin); 626 | BIND_ENUM_CONSTANT(cp852_bin); 627 | BIND_ENUM_CONSTANT(swe7_bin); 628 | BIND_ENUM_CONSTANT(utf8_bin); 629 | BIND_ENUM_CONSTANT(big5_bin); 630 | BIND_ENUM_CONSTANT(euckr_bin); 631 | BIND_ENUM_CONSTANT(gb2312_bin); 632 | BIND_ENUM_CONSTANT(gbk_bin); 633 | BIND_ENUM_CONSTANT(sjis_bin); 634 | BIND_ENUM_CONSTANT(tis620_bin); 635 | BIND_ENUM_CONSTANT(ucs2_bin); 636 | BIND_ENUM_CONSTANT(ujis_bin); 637 | BIND_ENUM_CONSTANT(geostd8_general_ci); 638 | BIND_ENUM_CONSTANT(geostd8_bin); 639 | BIND_ENUM_CONSTANT(latin1_spanish_ci); 640 | BIND_ENUM_CONSTANT(cp932_japanese_ci); 641 | BIND_ENUM_CONSTANT(cp932_bin); 642 | BIND_ENUM_CONSTANT(eucjpms_japanese_ci); 643 | BIND_ENUM_CONSTANT(eucjpms_bin); 644 | BIND_ENUM_CONSTANT(cp1250_polish_ci); 645 | BIND_ENUM_CONSTANT(utf16_unicode_ci); 646 | BIND_ENUM_CONSTANT(utf16_icelandic_ci); 647 | BIND_ENUM_CONSTANT(utf16_latvian_ci); 648 | BIND_ENUM_CONSTANT(utf16_romanian_ci); 649 | BIND_ENUM_CONSTANT(utf16_slovenian_ci); 650 | BIND_ENUM_CONSTANT(utf16_polish_ci); 651 | BIND_ENUM_CONSTANT(utf16_estonian_ci); 652 | BIND_ENUM_CONSTANT(utf16_spanish_ci); 653 | BIND_ENUM_CONSTANT(utf16_swedish_ci); 654 | BIND_ENUM_CONSTANT(utf16_turkish_ci); 655 | BIND_ENUM_CONSTANT(utf16_czech_ci); 656 | BIND_ENUM_CONSTANT(utf16_danish_ci); 657 | BIND_ENUM_CONSTANT(utf16_lithuanian_ci); 658 | BIND_ENUM_CONSTANT(utf16_slovak_ci); 659 | BIND_ENUM_CONSTANT(utf16_spanish2_ci); 660 | BIND_ENUM_CONSTANT(utf16_roman_ci); 661 | BIND_ENUM_CONSTANT(utf16_persian_ci); 662 | BIND_ENUM_CONSTANT(utf16_esperanto_ci); 663 | BIND_ENUM_CONSTANT(utf16_hungarian_ci); 664 | BIND_ENUM_CONSTANT(utf16_sinhala_ci); 665 | BIND_ENUM_CONSTANT(utf16_german2_ci); 666 | BIND_ENUM_CONSTANT(utf16_croatian_ci); 667 | BIND_ENUM_CONSTANT(utf16_unicode_520_ci); 668 | BIND_ENUM_CONSTANT(utf16_vietnamese_ci); 669 | BIND_ENUM_CONSTANT(ucs2_unicode_ci); 670 | BIND_ENUM_CONSTANT(ucs2_icelandic_ci); 671 | BIND_ENUM_CONSTANT(ucs2_latvian_ci); 672 | BIND_ENUM_CONSTANT(ucs2_romanian_ci); 673 | BIND_ENUM_CONSTANT(ucs2_slovenian_ci); 674 | BIND_ENUM_CONSTANT(ucs2_polish_ci); 675 | BIND_ENUM_CONSTANT(ucs2_estonian_ci); 676 | BIND_ENUM_CONSTANT(ucs2_spanish_ci); 677 | BIND_ENUM_CONSTANT(ucs2_swedish_ci); 678 | BIND_ENUM_CONSTANT(ucs2_turkish_ci); 679 | BIND_ENUM_CONSTANT(ucs2_czech_ci); 680 | BIND_ENUM_CONSTANT(ucs2_danish_ci); 681 | BIND_ENUM_CONSTANT(ucs2_lithuanian_ci); 682 | BIND_ENUM_CONSTANT(ucs2_slovak_ci); 683 | BIND_ENUM_CONSTANT(ucs2_spanish2_ci); 684 | BIND_ENUM_CONSTANT(ucs2_roman_ci); 685 | BIND_ENUM_CONSTANT(ucs2_persian_ci); 686 | BIND_ENUM_CONSTANT(ucs2_esperanto_ci); 687 | BIND_ENUM_CONSTANT(ucs2_hungarian_ci); 688 | BIND_ENUM_CONSTANT(ucs2_sinhala_ci); 689 | BIND_ENUM_CONSTANT(ucs2_german2_ci); 690 | BIND_ENUM_CONSTANT(ucs2_croatian_ci); 691 | BIND_ENUM_CONSTANT(ucs2_unicode_520_ci); 692 | BIND_ENUM_CONSTANT(ucs2_vietnamese_ci); 693 | BIND_ENUM_CONSTANT(ucs2_general_mysql500_ci); 694 | BIND_ENUM_CONSTANT(utf32_unicode_ci); 695 | BIND_ENUM_CONSTANT(utf32_icelandic_ci); 696 | BIND_ENUM_CONSTANT(utf32_latvian_ci); 697 | BIND_ENUM_CONSTANT(utf32_romanian_ci); 698 | BIND_ENUM_CONSTANT(utf32_slovenian_ci); 699 | BIND_ENUM_CONSTANT(utf32_polish_ci); 700 | BIND_ENUM_CONSTANT(utf32_estonian_ci); 701 | BIND_ENUM_CONSTANT(utf32_spanish_ci); 702 | BIND_ENUM_CONSTANT(utf32_swedish_ci); 703 | BIND_ENUM_CONSTANT(utf32_turkish_ci); 704 | BIND_ENUM_CONSTANT(utf32_czech_ci); 705 | BIND_ENUM_CONSTANT(utf32_danish_ci); 706 | BIND_ENUM_CONSTANT(utf32_lithuanian_ci); 707 | BIND_ENUM_CONSTANT(utf32_slovak_ci); 708 | BIND_ENUM_CONSTANT(utf32_spanish2_ci); 709 | BIND_ENUM_CONSTANT(utf32_roman_ci); 710 | BIND_ENUM_CONSTANT(utf32_persian_ci); 711 | BIND_ENUM_CONSTANT(utf32_esperanto_ci); 712 | BIND_ENUM_CONSTANT(utf32_hungarian_ci); 713 | BIND_ENUM_CONSTANT(utf32_sinhala_ci); 714 | BIND_ENUM_CONSTANT(utf32_german2_ci); 715 | BIND_ENUM_CONSTANT(utf32_croatian_ci); 716 | BIND_ENUM_CONSTANT(utf32_unicode_520_ci); 717 | BIND_ENUM_CONSTANT(utf32_vietnamese_ci); 718 | BIND_ENUM_CONSTANT(utf8_unicode_ci); 719 | BIND_ENUM_CONSTANT(utf8_icelandic_ci); 720 | BIND_ENUM_CONSTANT(utf8_latvian_ci); 721 | BIND_ENUM_CONSTANT(utf8_romanian_ci); 722 | BIND_ENUM_CONSTANT(utf8_slovenian_ci); 723 | BIND_ENUM_CONSTANT(utf8_polish_ci); 724 | BIND_ENUM_CONSTANT(utf8_estonian_ci); 725 | BIND_ENUM_CONSTANT(utf8_spanish_ci); 726 | BIND_ENUM_CONSTANT(utf8_swedish_ci); 727 | BIND_ENUM_CONSTANT(utf8_turkish_ci); 728 | BIND_ENUM_CONSTANT(utf8_czech_ci); 729 | BIND_ENUM_CONSTANT(utf8_danish_ci); 730 | BIND_ENUM_CONSTANT(utf8_lithuanian_ci); 731 | BIND_ENUM_CONSTANT(utf8_slovak_ci); 732 | BIND_ENUM_CONSTANT(utf8_spanish2_ci); 733 | BIND_ENUM_CONSTANT(utf8_roman_ci); 734 | BIND_ENUM_CONSTANT(utf8_persian_ci); 735 | BIND_ENUM_CONSTANT(utf8_esperanto_ci); 736 | BIND_ENUM_CONSTANT(utf8_hungarian_ci); 737 | BIND_ENUM_CONSTANT(utf8_sinhala_ci); 738 | BIND_ENUM_CONSTANT(utf8_german2_ci); 739 | BIND_ENUM_CONSTANT(utf8_croatian_ci); 740 | BIND_ENUM_CONSTANT(utf8_unicode_520_ci); 741 | BIND_ENUM_CONSTANT(utf8_vietnamese_ci); 742 | BIND_ENUM_CONSTANT(utf8_general_mysql500_ci); 743 | BIND_ENUM_CONSTANT(utf8mb4_unicode_ci); 744 | BIND_ENUM_CONSTANT(utf8mb4_icelandic_ci); 745 | BIND_ENUM_CONSTANT(utf8mb4_latvian_ci); 746 | BIND_ENUM_CONSTANT(utf8mb4_romanian_ci); 747 | BIND_ENUM_CONSTANT(utf8mb4_slovenian_ci); 748 | BIND_ENUM_CONSTANT(utf8mb4_polish_ci); 749 | BIND_ENUM_CONSTANT(utf8mb4_estonian_ci); 750 | BIND_ENUM_CONSTANT(utf8mb4_spanish_ci); 751 | BIND_ENUM_CONSTANT(utf8mb4_swedish_ci); 752 | BIND_ENUM_CONSTANT(utf8mb4_turkish_ci); 753 | BIND_ENUM_CONSTANT(utf8mb4_czech_ci); 754 | BIND_ENUM_CONSTANT(utf8mb4_danish_ci); 755 | BIND_ENUM_CONSTANT(utf8mb4_lithuanian_ci); 756 | BIND_ENUM_CONSTANT(utf8mb4_slovak_ci); 757 | BIND_ENUM_CONSTANT(utf8mb4_spanish2_ci); 758 | BIND_ENUM_CONSTANT(utf8mb4_roman_ci); 759 | BIND_ENUM_CONSTANT(utf8mb4_persian_ci); 760 | BIND_ENUM_CONSTANT(utf8mb4_esperanto_ci); 761 | BIND_ENUM_CONSTANT(utf8mb4_hungarian_ci); 762 | BIND_ENUM_CONSTANT(utf8mb4_sinhala_ci); 763 | BIND_ENUM_CONSTANT(utf8mb4_german2_ci); 764 | BIND_ENUM_CONSTANT(utf8mb4_croatian_ci); 765 | BIND_ENUM_CONSTANT(utf8mb4_unicode_520_ci); 766 | BIND_ENUM_CONSTANT(utf8mb4_vietnamese_ci); 767 | BIND_ENUM_CONSTANT(gb18030_chinese_ci); 768 | BIND_ENUM_CONSTANT(gb18030_bin); 769 | BIND_ENUM_CONSTANT(gb18030_unicode_520_ci); 770 | BIND_ENUM_CONSTANT(utf8mb4_0900_ai_ci); 771 | BIND_ENUM_CONSTANT(utf8mb4_de_pb_0900_ai_ci); 772 | BIND_ENUM_CONSTANT(utf8mb4_is_0900_ai_ci); 773 | BIND_ENUM_CONSTANT(utf8mb4_lv_0900_ai_ci); 774 | BIND_ENUM_CONSTANT(utf8mb4_ro_0900_ai_ci); 775 | BIND_ENUM_CONSTANT(utf8mb4_sl_0900_ai_ci); 776 | BIND_ENUM_CONSTANT(utf8mb4_pl_0900_ai_ci); 777 | BIND_ENUM_CONSTANT(utf8mb4_et_0900_ai_ci); 778 | BIND_ENUM_CONSTANT(utf8mb4_es_0900_ai_ci); 779 | BIND_ENUM_CONSTANT(utf8mb4_sv_0900_ai_ci); 780 | BIND_ENUM_CONSTANT(utf8mb4_tr_0900_ai_ci); 781 | BIND_ENUM_CONSTANT(utf8mb4_cs_0900_ai_ci); 782 | BIND_ENUM_CONSTANT(utf8mb4_da_0900_ai_ci); 783 | BIND_ENUM_CONSTANT(utf8mb4_lt_0900_ai_ci); 784 | BIND_ENUM_CONSTANT(utf8mb4_sk_0900_ai_ci); 785 | BIND_ENUM_CONSTANT(utf8mb4_es_trad_0900_ai_ci); 786 | BIND_ENUM_CONSTANT(utf8mb4_la_0900_ai_ci); 787 | BIND_ENUM_CONSTANT(utf8mb4_eo_0900_ai_ci); 788 | BIND_ENUM_CONSTANT(utf8mb4_hu_0900_ai_ci); 789 | BIND_ENUM_CONSTANT(utf8mb4_hr_0900_ai_ci); 790 | BIND_ENUM_CONSTANT(utf8mb4_vi_0900_ai_ci); 791 | BIND_ENUM_CONSTANT(utf8mb4_0900_as_cs); 792 | BIND_ENUM_CONSTANT(utf8mb4_de_pb_0900_as_cs); 793 | BIND_ENUM_CONSTANT(utf8mb4_is_0900_as_cs); 794 | BIND_ENUM_CONSTANT(utf8mb4_lv_0900_as_cs); 795 | BIND_ENUM_CONSTANT(utf8mb4_ro_0900_as_cs); 796 | BIND_ENUM_CONSTANT(utf8mb4_sl_0900_as_cs); 797 | BIND_ENUM_CONSTANT(utf8mb4_pl_0900_as_cs); 798 | BIND_ENUM_CONSTANT(utf8mb4_et_0900_as_cs); 799 | BIND_ENUM_CONSTANT(utf8mb4_es_0900_as_cs); 800 | BIND_ENUM_CONSTANT(utf8mb4_sv_0900_as_cs); 801 | BIND_ENUM_CONSTANT(utf8mb4_tr_0900_as_cs); 802 | BIND_ENUM_CONSTANT(utf8mb4_cs_0900_as_cs); 803 | BIND_ENUM_CONSTANT(utf8mb4_da_0900_as_cs); 804 | BIND_ENUM_CONSTANT(utf8mb4_lt_0900_as_cs); 805 | BIND_ENUM_CONSTANT(utf8mb4_sk_0900_as_cs); 806 | BIND_ENUM_CONSTANT(utf8mb4_es_trad_0900_as_cs); 807 | BIND_ENUM_CONSTANT(utf8mb4_la_0900_as_cs); 808 | BIND_ENUM_CONSTANT(utf8mb4_eo_0900_as_cs); 809 | BIND_ENUM_CONSTANT(utf8mb4_hu_0900_as_cs); 810 | BIND_ENUM_CONSTANT(utf8mb4_hr_0900_as_cs); 811 | BIND_ENUM_CONSTANT(utf8mb4_vi_0900_as_cs); 812 | BIND_ENUM_CONSTANT(utf8mb4_ja_0900_as_cs); 813 | BIND_ENUM_CONSTANT(utf8mb4_ja_0900_as_cs_ks); 814 | BIND_ENUM_CONSTANT(utf8mb4_0900_as_ci); 815 | BIND_ENUM_CONSTANT(utf8mb4_ru_0900_ai_ci); 816 | BIND_ENUM_CONSTANT(utf8mb4_ru_0900_as_cs); 817 | BIND_ENUM_CONSTANT(utf8mb4_zh_0900_as_cs); 818 | BIND_ENUM_CONSTANT(utf8mb4_0900_bin); 819 | 820 | } 821 | -------------------------------------------------------------------------------- /scr/mysql.h: -------------------------------------------------------------------------------- 1 | /* mysql.h */ 2 | 3 | 4 | /* 5 | SOME NICE THINGS TO TAKE A LOOK: 6 | 7 | Query formatting: 8 | https://github.com/boostorg/mysql/pull/213#pullrequestreview-1890118842 9 | 10 | */ 11 | 12 | #ifndef MYSQL_H 13 | #define MYSQL_H 14 | 15 | 16 | #include "helpers.h" 17 | #include "sql_result.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | 44 | using namespace boost::asio; 45 | 46 | constexpr auto tuple_awaitable = as_tuple(use_awaitable); 47 | 48 | 49 | class MySQL : public RefCounted { 50 | GDCLASS(MySQL, RefCounted); 51 | 52 | 53 | protected: 54 | 55 | static void _bind_methods(); 56 | 57 | 58 | public: 59 | 60 | using ConnType = CONN_TYPE; 61 | using MysqlCollations = MYSQLCOLLATIONS; 62 | 63 | enum SslMode { 64 | ssl_disable = (int)mysql::ssl_mode::disable, 65 | ssl_enable = (int)mysql::ssl_mode::enable, 66 | ssl_require = (int)mysql::ssl_mode::require, 67 | }; 68 | 69 | 70 | private: 71 | 72 | //Error 73 | Dictionary last_error; 74 | 75 | // Status 76 | ConnType type = TCPTLS; 77 | 78 | // Params 79 | char *username; 80 | char *password; 81 | char *database; 82 | mysql::handshake_params conn_params; 83 | 84 | // Aux 85 | std::shared_ptr ctx = nullptr; 86 | std::shared_ptr ssl_ctx = nullptr; 87 | std::shared_ptr resolver = nullptr; 88 | 89 | // Connection 90 | std::shared_ptr tcp_conn = nullptr; 91 | std::shared_ptr tcp_ssl_conn = nullptr; 92 | std::shared_ptr unix_conn = nullptr; 93 | std::shared_ptr unix_ssl_conn = nullptr; 94 | 95 | asio::awaitable coro_execute(const char* query, std::shared_ptr result); 96 | asio::awaitable coro_execute_prepared(const char* query, std::vector args, std::shared_ptr result); 97 | 98 | 99 | private: 100 | 101 | Error set_certificate(const String p_cert_file, const String p_host_name); 102 | 103 | void build_result(mysql::results raw_result, Ref *gdt_result); 104 | 105 | Dictionary get_metadata(mysql::results result); 106 | 107 | Dictionary get_raw(mysql::results result); 108 | 109 | Array multiqueries(std::string queries); 110 | 111 | Ref build_godot_result(mysql::results result); 112 | 113 | Ref build_godot_result( 114 | mysql::rows_view batch, mysql::metadata_collection_view meta_collection, 115 | std::uint64_t affected_rows, std::uint64_t last_insert_id, unsigned warning_count 116 | ); 117 | 118 | 119 | public: 120 | 121 | // The define method will configure a connection. 122 | // If there is already an active connection, it will be disconnected and reseted. 123 | // The path to the certificate and hostname are intended for use with TLS connections only. 124 | // In non-TLS connections the certificate and the hostname will be ignored. 125 | // If the user wishes to modify the certificate, the connection must be reseted. 126 | // Resetting the connection does not reset the credentials. 127 | Error define(const ConnType _type = TCPTLS, const String p_cert_file = "", const String p_host_name = "mysql"); 128 | 129 | // Retrieves the connection type. 130 | ConnType get_connection_type() const { return type;}; 131 | 132 | // Method used to initiate a TCP connection. 133 | // It will not work with UNIX-type connections. 134 | Error tcp_connect(const String p_hostname = "127.0.0.1", const String p_port = "3306"); 135 | 136 | // Method used to connect to the database via Socket. 137 | // It will not work with TCP-type connections. 138 | Error unix_connect(const String p_socket_path = "/var/run/mysqld/mysqld.sock"); 139 | 140 | // Close the connection. 141 | Error close_connection(); 142 | 143 | // Returns a dictionary with the last exception that occurred. 144 | Dictionary get_last_error() const {return last_error.duplicate(true);}; 145 | 146 | // Checks whether there is an active connection to the server. 147 | bool is_server_alive(); 148 | 149 | // Execute queries. 150 | Ref execute(const String p_stmt); 151 | 152 | // Execute prepared queries. 153 | Ref execute_prepared(const String p_stmt, const Array binds = Array()); 154 | 155 | // Execute sql scripts. 156 | // This function perform multi-queries, because this the "multi_queries" option must be true in the connection credentials, 157 | // otherwise this function won't be executed. 158 | // Be extremely careful with this function. 159 | Array execute_sql(const String p_path_to_file); 160 | 161 | // Execute Multi-function operations. 162 | // You can use multi-function operations to execute several function text queries. 163 | // This function return an Array with a SqlResult for each query executed. 164 | Array execute_multi(const String p_queries); 165 | 166 | // Returns a dictionary with the connection credentials. 167 | Dictionary get_credentials() const; 168 | 169 | // Configure connection credentials. 170 | Error set_credentials( 171 | String p_username, 172 | String p_password, 173 | String p_database = String(), 174 | std::uint16_t collation = default_collation, 175 | SslMode p_ssl = ssl_enable, 176 | bool multi_queries = false 177 | ); 178 | 179 | // Execute queries on asynchronous connections. 180 | Ref async_execute(const String p_stmt); 181 | 182 | // Execute prepared queries on asynchronous connections. 183 | Ref async_execute_prepared(const String p_stmt, const Array binds = Array()); 184 | 185 | MySQL(): 186 | conn_params((const char *)&username, (const char *)&password, (const char *)&database) 187 | {} 188 | ~MySQL(){ 189 | close_connection(); 190 | } 191 | 192 | }; 193 | 194 | VARIANT_ENUM_CAST(MySQL::MysqlCollations); 195 | VARIANT_ENUM_CAST(MySQL::ConnType); 196 | VARIANT_ENUM_CAST(MySQL::SslMode); 197 | 198 | 199 | #endif // MYSQL_H -------------------------------------------------------------------------------- /scr/sql_result.cpp: -------------------------------------------------------------------------------- 1 | /* sql_result.cpp */ 2 | 3 | #include "sql_result.h" 4 | 5 | 6 | Array SqlResult::get_array() const { 7 | Array ret; 8 | for (int col = 0; col < result.size(); col++) { 9 | Dictionary dic_row = result[col]; 10 | Array row = dic_row.values(); 11 | ret.push_back(row); 12 | } 13 | return ret; 14 | } 15 | 16 | 17 | Variant SqlResult::get_row(int row, bool as_array) const { 18 | if(as_array) { 19 | Array ret = Array(); 20 | Dictionary line = result[row]; 21 | for (int col = 0; col < line.size(); col++) { 22 | ret.push_back(line[col]); 23 | } 24 | return ret; 25 | } 26 | return result[row]; 27 | } 28 | 29 | 30 | Array SqlResult::get_column(String column, bool as_array) const { 31 | Array ret; 32 | for (int col = 0; col < result.size(); col++) { 33 | Dictionary dic_row = result[col]; 34 | if (as_array) { 35 | ret.push_back(dic_row[column]); 36 | } 37 | else { 38 | Dictionary b = Dictionary(); 39 | b[dic_row.keys()[col]]=dic_row[column]; 40 | ret.push_back(b); 41 | } 42 | } 43 | return ret; 44 | } 45 | 46 | 47 | Array SqlResult::get_column_by_id(int column, bool as_array) const { 48 | Array ret; 49 | for (int col = 0; col < result.size(); col++) { 50 | Dictionary dic_row = result[col]; 51 | if (as_array) { 52 | ret.push_back(dic_row[column]); 53 | } 54 | else { 55 | Dictionary b = Dictionary(); 56 | b[dic_row.keys()[col]]=dic_row[column]; 57 | ret.push_back(b); 58 | } 59 | } 60 | return ret; 61 | } 62 | 63 | 64 | void SqlResult::_bind_methods() { 65 | 66 | /* ===== QUERY ===== */ 67 | ClassDB::bind_method(D_METHOD("get_array"), &SqlResult::get_array); 68 | ClassDB::bind_method(D_METHOD("get_dictionary"), &SqlResult::get_dictionary); 69 | ClassDB::bind_method(D_METHOD("get_row", "row", "as_array"), &SqlResult::get_row, DEFVAL(true)); 70 | ClassDB::bind_method(D_METHOD("get_column", "column", "as_array"), &SqlResult::get_column, DEFVAL(true)); 71 | ClassDB::bind_method(D_METHOD("get_column_by_id", "column", "as_array"), &SqlResult::get_column, DEFVAL(true)); 72 | 73 | /* ===== META ===== */ 74 | ClassDB::bind_method(D_METHOD("get_metadata"), &SqlResult::get_metadata); 75 | ClassDB::bind_method(D_METHOD("get_affected_rows"), &SqlResult::get_affected_rows); 76 | ClassDB::bind_method(D_METHOD("get_last_insert_id"), &SqlResult::get_last_insert_id); 77 | ClassDB::bind_method(D_METHOD("get_warning_count"), &SqlResult::get_warning_count); 78 | 79 | } 80 | 81 | 82 | SqlResult::SqlResult(){ 83 | } 84 | 85 | 86 | SqlResult::~SqlResult(){ 87 | } 88 | 89 | -------------------------------------------------------------------------------- /scr/sql_result.h: -------------------------------------------------------------------------------- 1 | /* sql_result.h */ 2 | 3 | #ifndef SQLRESULT_H 4 | #define SQLRESULT_H 5 | 6 | 7 | #include "core/object/ref_counted.h" 8 | #include "core/core_bind.h" 9 | 10 | 11 | class SqlResult : public RefCounted { 12 | GDCLASS(SqlResult, RefCounted); 13 | 14 | friend class MySQL; 15 | 16 | private: 17 | 18 | Dictionary result; 19 | Dictionary meta; 20 | int affected_rows; 21 | int last_insert_id; 22 | int warning_count; 23 | 24 | 25 | protected: 26 | 27 | static void _bind_methods(); 28 | 29 | 30 | public: 31 | 32 | Array get_array() const; 33 | 34 | Variant get_row(int row, bool as_array = true) const; 35 | 36 | Array get_column(String column, bool as_array = true) const; 37 | 38 | Array get_column_by_id(int column, bool as_array = true) const; 39 | 40 | Dictionary get_metadata() const {return meta;}; 41 | 42 | Dictionary get_dictionary() const {return result;}; 43 | 44 | int get_affected_rows() const {return affected_rows;}; 45 | 46 | int get_last_insert_id() const {return last_insert_id;}; 47 | 48 | int get_warning_count() const {return warning_count;}; 49 | 50 | SqlResult(); 51 | ~SqlResult(); 52 | 53 | }; 54 | 55 | 56 | #endif // SQLRESULT_H -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Malkverbena/mysql/8c69f583962b6fe766c83d6587634dc0a968b375/tools/__init__.py -------------------------------------------------------------------------------- /tools/boost.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # boost.py 3 | 4 | 5 | # https://www.boost.org/build/tutorial.html 6 | 7 | 8 | import os, subprocess 9 | from tools import helpers 10 | 11 | 12 | def compile_boost(env): 13 | 14 | jobs = "-j" + str(env.GetOption("num_jobs")) 15 | boost_path = f"{os.getcwd()}/3party/boost" 16 | 17 | boost_prefix = get_boost_install_path(env) # --exec-prefix= 18 | boost_stage_dir = f"{boost_prefix}/stage" # --exec-prefix= 19 | boost_lib_dir = f"{boost_stage_dir}/lib" # --libdir= 20 | boost_include_dir = f"{boost_prefix}/include" # --includedir= 21 | build_dir = f"{boost_prefix}/build" # --build-dir= 22 | 23 | 24 | is_win_host = (helpers.get_host() == "windows") 25 | bootstrap = "bootstrap.bat" if is_win_host else "bootstrap.sh" 26 | b2 = "b2.exe" if is_win_host else "b2" 27 | cmd_b2 = [b2] 28 | 29 | bootstrap_command = [ 30 | "bash", bootstrap, 31 | f"--prefix={boost_prefix}", 32 | f"--libdir={boost_lib_dir}", 33 | f"--includedir={boost_include_dir}" 34 | ] 35 | compiller = helpers.get_compiller(env) 36 | if compiller == "clang": 37 | bootstrap_command.append("--with-toolset=clang") 38 | 39 | if not os.path.exists(boost_prefix): 40 | os.makedirs(boost_prefix) 41 | 42 | 43 | try: 44 | subprocess.check_call(bootstrap_command, cwd=boost_path, env={"PATH": f"{boost_path}:{os.environ['PATH']}"}) 45 | except subprocess.CalledProcessError as e: 46 | print(f"Error trying configure Boost: {e}") 47 | exit(1) 48 | 49 | 50 | 51 | is_cross_compilation = is_cross_compile(env) 52 | if is_cross_compilation: 53 | project_comp = get_project_set(env) 54 | with open('project-config.jam', 'a') as arquivo: 55 | arquivo.write(project_comp + "\n") 56 | 57 | 58 | target_bits = "64" if env["arch"] in ["x86_64", "arm64", "rv64", "ppc64"] else "32" 59 | 60 | 61 | cmd_b2 += [ 62 | jobs, 63 | "-a", 64 | "link=static", 65 | "threading=multi", 66 | "runtime-link=static", 67 | "variant=release", 68 | f"--build-dir={build_dir}", 69 | f"--exec-prefix={boost_prefix}", 70 | f"--stagedir={boost_stage_dir}", 71 | f"toolset={get_toolset(env)}", 72 | f"address-model={target_bits}", 73 | f"architecture={get_architecture(env)}", 74 | f"target-os={get_target_os(env)}", 75 | "headers" 76 | ] 77 | 78 | print(cmd_b2) 79 | 80 | subprocess.check_call(cmd_b2, cwd=boost_path, env={"PATH": f"{boost_path}:{os.environ['PATH']}"}) 81 | cmd_b2.pop() 82 | subprocess.check_call(cmd_b2, cwd=boost_path, env={"PATH": f"{boost_path}:{os.environ['PATH']}"}) 83 | 84 | 85 | return 0 86 | 87 | 88 | 89 | def get_project_set(env): 90 | target_platform = env["platform"] 91 | host_platform = helpers.get_host() 92 | target_bits = "64" if env["arch"] in ["x86_64", "arm64", "rv64", "ppc64"] else "32" 93 | compiller = helpers.get_compiller(env) 94 | 95 | if host_platform == "linuxbsd": 96 | if target_platform == "windows": 97 | if compiller == "gcc": 98 | if target_bits == "64": 99 | "using gcc : mingw : x86_64-w64-mingw32-g++ ;" 100 | else: 101 | "using gcc : mingw : i686-w64-mingw32-g++ ;" 102 | elif compiller == "clang": 103 | if target_bits == "64": 104 | "using clang : : x86_64-w64-mingw32-clang++ ;" 105 | else: 106 | "using clang : : i686-w64-mingw32-clang++ ;" 107 | 108 | if host_platform == "windows": 109 | #TODO: 110 | pass 111 | 112 | 113 | 114 | 115 | def is_cross_compile(env): 116 | host_bits = helpers.get_host_bits() 117 | host_platform = helpers.get_host() 118 | target_platform = env["platform"] 119 | target_bits = "64" if env["arch"] in ["x86_64", "arm64", "rv64", "ppc64"] else "32" 120 | return (host_platform != target_platform or host_bits != target_bits) 121 | 122 | 123 | 124 | def get_target_os(env): 125 | if env["platform"] == "windows": 126 | return "windows" 127 | elif env["platform"] == "linuxbsd": 128 | return "linux" 129 | elif env["platform"] == "macos": 130 | return "darwin" 131 | else: 132 | return "" 133 | 134 | 135 | 136 | 137 | def get_toolset(env): 138 | compiller = helpers.get_compiller(env) 139 | if compiller == "": 140 | return "" 141 | 142 | if env["platform"] == "windows": 143 | if compiller == "gcc": 144 | return "gcc-mingw" 145 | elif compiller == "clang": 146 | return "clang-mingw" 147 | else: 148 | return "" 149 | 150 | if env["platform"] == "linuxbsd": 151 | return compiller 152 | 153 | return "" 154 | 155 | 156 | 157 | # Supports ["x86", "arm", "power", riscv"] for now 158 | def get_architecture(env): 159 | godot_target = env["arch"] 160 | if "x86" in godot_target: 161 | return "x86" 162 | elif "arm" in godot_target: 163 | return "arm" 164 | elif "ppc" in godot_target: 165 | return "power" 166 | elif "rv" in godot_target: 167 | return "riscv" 168 | elif "wasm" in godot_target: 169 | return "????" 170 | 171 | 172 | 173 | def get_boost_install_path(env): 174 | bin_path = f"{os.getcwd()}/3party/bin" 175 | _lib_path = [bin_path, env["platform"], env["arch"]] 176 | if env["use_llvm"]: 177 | _lib_path.append("llvm") 178 | _lib_path.append("boost") 179 | lib_path = "/".join(_lib_path) 180 | return lib_path 181 | 182 | -------------------------------------------------------------------------------- /tools/boost_rascunho.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # boost.py 3 | 4 | 5 | # https://www.boost.org/build/tutorial.html 6 | 7 | import os, subprocess, sys 8 | 9 | 10 | boost_cmd = [ 11 | "-a", 12 | "link=static", 13 | "threading=multi", 14 | "runtime-link=static", 15 | ] 16 | 17 | 18 | # Allowed platforms: ["linuxbsd", "macos", "windows"] 19 | def get_host(): 20 | 21 | if sys.platform in ["win32", "msys", "cygwin"]: 22 | return "windows" 23 | 24 | elif sys.platform in ["macos", "osx", "darwin"]: 25 | return "macos" 26 | 27 | elif ( sys.platform in ["linux", "linux2"] 28 | or sys.platform.startswith("linux") 29 | or sys.platform.startswith("dragonfly") 30 | or sys.platform.startswith("freebsd") 31 | or sys.platform.startswith("netbsd") 32 | or sys.platform.startswith("openbsd")): 33 | return "linuxbsd" 34 | 35 | return "unknown" 36 | 37 | 38 | 39 | def update_boost(): 40 | git_cmd = ["git pull", "--recurse-submodules"] 41 | subprocess.run(git_cmd, shell=True, cwd="3party/boost") 42 | 43 | 44 | def get_variant(env): 45 | if env["target"] == "editor": 46 | return "debug" 47 | elif env["target"] == "template_debug": 48 | return "profile" 49 | elif env["target"] == "template_release": 50 | return "release" 51 | 52 | 53 | 54 | def get_lto(env): 55 | if env["lto"] == "none": 56 | return "fat" 57 | elif env["lto"] == "thin": 58 | return "thin" 59 | elif env["lto"] == "full": 60 | return "full" 61 | 62 | 63 | # Allowed boot values: x86, ia64, sparc, power, mips, mips1, mips2, mips3, mips4, mips32, mips32r2, mips64, parisc, arm, s390x, loongarch. 64 | # Supports ["x86", "arm", "power", riscv"] for now 65 | def get_architecture(env): 66 | godot_target = env["arch"] 67 | if "x86" in godot_target: 68 | return "x86" 69 | elif "arm" in godot_target: 70 | return "arm" 71 | elif "ppc" in godot_target: 72 | return "power" 73 | elif "rv" in godot_target: 74 | return "riscv" 75 | elif "wasm" in godot_target: 76 | return "????" 77 | 78 | 79 | def execute(env, commands, tool): 80 | 81 | # comp = f"--with-toolset={tool}" 82 | 83 | caminho_executavel = f"{os.getcwd()}/3party/boost" 84 | os.chdir(caminho_executavel) 85 | 86 | is_win_host = sys.platform in ["win32", "msys", "cygwin"] 87 | 88 | bootstrap = "bootstrap.bat" if is_win_host else "bootstrap.sh" 89 | b2 = "b2.exe" if is_win_host else "./b2" 90 | 91 | configure_command = [ 92 | "bash", os.path.join(caminho_executavel, bootstrap), 93 | f"--with-toolset={tool}", 94 | ] 95 | 96 | try: 97 | subprocess.check_call(configure_command) 98 | except subprocess.CalledProcessError as e: 99 | print(f"Erro ao configurar o Boost: {e}") 100 | exit(1) 101 | 102 | 103 | cmd_b2 = [b2] + commands 104 | 105 | os.chdir(caminho_executavel) 106 | subprocess.run(cmd_b2) 107 | 108 | cmd_b2.append("headers") 109 | subprocess.run(cmd_b2) 110 | subprocess.run([b2, "headers"]) 111 | 112 | 113 | 114 | # Allowed platforms: ["linuxbsd", "macos", "windows", "ios", "android", "web"] 115 | def get_target_platform(plat): 116 | if plat == "linuxbsd": 117 | return "linux" 118 | elif plat == "macos" or plat == "ios": 119 | return "darwin" 120 | elif plat == "windows": 121 | return "windows" 122 | elif plat == "android": 123 | return "android" 124 | 125 | 126 | 127 | 128 | def compile_boost(env): 129 | 130 | jobs = "30" 131 | target_bits = "64" if "64" in env["arch"] else "32" 132 | target_architecture = get_architecture(env) 133 | target_variant = get_variant(env) 134 | 135 | lto_mode = get_lto(env) 136 | 137 | target_platform = get_target_platform(env["platform"]) 138 | 139 | host = get_host() 140 | 141 | tool = "" 142 | b2tool = "" 143 | 144 | commands = [f"-j{jobs}"] 145 | 146 | 147 | if host == "linuxbsd": 148 | 149 | if env["platform"] == "linuxbsd": 150 | tool = "clang" if env["use_llvm"] else "gcc" 151 | b2tool = "clang" if env["use_llvm"] else "gcc" 152 | 153 | elif env["platform"] == "windows": 154 | tool = "clang" if env["use_llvm"] else "gcc" 155 | b2tool = "clang" if env["use_llvm"] else "gcc" 156 | 157 | elif env["platform"] == "macos": 158 | pass 159 | 160 | if host == "windows": 161 | if env["platform"] == "linuxbsd": 162 | tool = "clang" if env["use_llvm"] else "gcc" 163 | b2tool = "clang-linux" if env["use_llvm"] else "gcc" 164 | 165 | elif env["platform"] == "windows": 166 | tool = "clang" if env["use_llvm"] else "gcc" 167 | b2tool = "clang-win" if env["use_llvm"] else "gcc-mingw" 168 | 169 | elif env["platform"] == "macos": 170 | pass 171 | 172 | 173 | 174 | 175 | 176 | 177 | architecture = f"architecture={target_architecture}" 178 | address_model = f"address-model={target_bits}" 179 | variant = f"variant={target_variant}" 180 | target_os = f"target-os={target_platform}" 181 | #user_config = "--user-config=../godot-config.jam" 182 | jobs = env.GetOption("num_jobs") 183 | 184 | 185 | 186 | print(target_os) 187 | 188 | commands.extend([ 189 | target_os, 190 | architecture, 191 | address_model, 192 | variant, 193 | # user_config, 194 | f"toolset={tool}", 195 | f"-j{jobs}", 196 | ]) 197 | 198 | commands += boost_cmd 199 | 200 | 201 | execute(env, commands, tool) 202 | 203 | 204 | 205 | -------------------------------------------------------------------------------- /tools/helpers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # helpers.py 3 | 4 | import platform, sys 5 | from tools import boost, openssl 6 | 7 | 8 | 9 | def get_host_bits(): 10 | my_arch = platform.architecture() 11 | bits = "64" if my_arch[0] == "64bit" else "32" 12 | return bits 13 | 14 | 15 | 16 | # Allowed platforms: ["linuxbsd", "macos", "windows"] 17 | def get_host(): 18 | 19 | if sys.platform in ["win32", "msys", "cygwin"]: 20 | return "windows" 21 | 22 | elif sys.platform in ["macos", "osx", "darwin"]: 23 | return "macos" 24 | 25 | elif ( sys.platform in ["linux", "linux2"] 26 | or sys.platform.startswith("linux") 27 | or sys.platform.startswith("dragonfly") 28 | or sys.platform.startswith("freebsd") 29 | or sys.platform.startswith("netbsd") 30 | or sys.platform.startswith("openbsd")): 31 | return "linuxbsd" 32 | 33 | return "unknown" 34 | 35 | 36 | def apply_config(env): 37 | 38 | if env["recompile_sql"] in ["all", "openssl"]: 39 | openssl.compile_openssl(env) 40 | 41 | if env["recompile_sql"] in ["all", "boost"]: 42 | boost.compile_boost(env) 43 | 44 | 45 | 46 | def get_compiller(env): 47 | 48 | host_platform = get_host() 49 | if env["platform"] == "linuxbsd": 50 | return "clang" if env["use_llvm"] else "gcc" 51 | if env["platform"] == "windows": 52 | if not env["use_mingw"]: 53 | return "msvc" 54 | else: 55 | if host_platform == "linuxbsd": 56 | return "clang" if env["use_llvm"] else "gcc" 57 | else: 58 | # Compilador rodando no MacOS 59 | pass 60 | 61 | return "" 62 | 63 | -------------------------------------------------------------------------------- /tools/openssl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # openssl.py 3 | 4 | 5 | import os, subprocess, sys 6 | from tools import helpers 7 | 8 | 9 | 10 | def compile_openssl(env): 11 | 12 | target_platform = env["platform"] 13 | win_host = is_win_host(env) 14 | jobs = str(env.GetOption("num_jobs")) 15 | 16 | cmd_config = ["perl", "Configure"] if win_host else ["Configure"] 17 | cmd_depend = ["nmake", "test"] if win_host else ["make", "depend"] 18 | cmd_compile = ['nmake'] if win_host else ["make", "-j" + jobs] 19 | cmd_install = ["nmake install"] if win_host else ["make", "install"] 20 | 21 | cross_compilation_param = get_cross_compilation_param(env) 22 | if cross_compilation_param != []: 23 | cmd_config += cross_compilation_param 24 | 25 | target = get_target(env) 26 | cmd_config.append(target) 27 | 28 | options = ssl_options(target_platform) 29 | cmd_config.extend(options) 30 | 31 | openssl_path = get_openssl_path(env) 32 | lib_path = get_openssl_install_path(env) 33 | cmd_config.append("--prefix=" + lib_path) 34 | cmd_config.append("--openssldir=" + lib_path) 35 | cmd_config.append("-Wl,-rpath=" + lib_path + "/lib64") 36 | 37 | if not os.path.exists(lib_path): 38 | os.makedirs(lib_path) 39 | 40 | 41 | print(cmd_config) 42 | print(cmd_depend) 43 | print(cmd_compile) 44 | print(cmd_install) 45 | 46 | subprocess.check_call(cmd_config, cwd=openssl_path, env={"PATH": f"{openssl_path}:{os.environ['PATH']}"}) 47 | subprocess.check_call(cmd_depend, cwd=openssl_path, env={"PATH": f"{openssl_path}:{os.environ['PATH']}"}) 48 | subprocess.check_call(cmd_compile, cwd=openssl_path, env={"PATH": f"{openssl_path}:{os.environ['PATH']}"}) 49 | subprocess.check_call(cmd_install, cwd=openssl_path, env={"PATH": f"{openssl_path}:{os.environ['PATH']}"}) 50 | 51 | return 0 52 | 53 | 54 | 55 | 56 | def is_win_host(env): 57 | return sys.platform in ["win32", "msys", "cygwin"] 58 | 59 | 60 | def get_cross_compilation_param(env): 61 | 62 | platform = env["platform"] 63 | host = helpers.get_host() 64 | target_bits = "64" if env["arch"] in ["x86_64", "arm64", "rv64", "ppc64"] else "32" 65 | host_bits = helpers.get_host_bits() 66 | is_cross_compile = (host != platform or host_bits != target_bits) 67 | llvm = env["use_llvm"] 68 | 69 | if platform == "windows": 70 | if not (is_win_host(env) or env.get("is_msvc", False)): 71 | if llvm: 72 | if target_bits == "64": 73 | return ["--cross-compile-prefix=x86_64-w64-mingw32-"] 74 | else: 75 | return ["--cross-compile-prefix=i686-w64-mingw32-"] 76 | else: 77 | if target_bits == "64": 78 | return ["--cross-compile-prefix=mingw-w64-x86_64-gcc"] 79 | else: 80 | return ["--cross-compile-prefix=mingw-w64-i686-gcc"] 81 | 82 | 83 | 84 | 85 | 86 | elif platform == "linuxbsd": 87 | if is_cross_compile: 88 | if target_bits == "64": 89 | return ["--cross-compile-prefix=x86_64-linux-gnu-"] 90 | else: 91 | return ["--cross-compile-prefix=i686-linux-gnu-"] 92 | 93 | elif platform == "macos": 94 | args =[] 95 | if sys.platform != "darwin" and "OSXCROSS_ROOT" in os.environ: 96 | for k in ["CC", "CXX", "AR", "AS", "RANLIB"]: 97 | args.append("%s=%s" % (k, env[k])) 98 | return args 99 | 100 | 101 | return [] 102 | 103 | 104 | 105 | def get_openssl_install_path(env): 106 | _lib_path = [os.getcwd(), "3party", "bin", env["platform"], env["arch"]] 107 | if env["use_llvm"]: 108 | _lib_path.append("llvm") 109 | _lib_path.append("openssl") 110 | lib_path = "" 111 | if is_win_host(env): 112 | lib_path = "\\-=-".join(_lib_path) 113 | lib_path = lib_path.replace("-=-", "") 114 | else: 115 | lib_path = "/".join(_lib_path) 116 | return lib_path 117 | 118 | 119 | def get_openssl_path(env): 120 | _openssl_path = [os.getcwd(), "3party", "openssl"] 121 | openssl_path = "" 122 | if is_win_host(env): 123 | openssl_path = "\\-=-".join(_openssl_path) 124 | openssl_path = openssl_path.replace("-=-", "") 125 | else: 126 | openssl_path = "/".join(_openssl_path) 127 | return openssl_path 128 | 129 | 130 | 131 | 132 | def get_target(env): 133 | 134 | platform = env["platform"] 135 | arch = env["arch"] 136 | compiller = helpers.get_compiller(env) 137 | 138 | if platform == "linuxbsd": 139 | if compiller == "gcc": 140 | if arch == "x86_32": 141 | return "linux-x86" 142 | elif arch == "x86_64": 143 | return "linux-x86_64" 144 | elif arch == "arm32": 145 | return "linux-armv4" 146 | elif arch == "arm64": 147 | return "linux-aarch64" 148 | elif arch == "rv64": 149 | return "linux64-riscv64" 150 | elif arch == "ppc32": 151 | return "linux-ppc" 152 | elif arch == "ppc64": 153 | return "linux-ppc64" 154 | elif arch == "ppc64": 155 | return "linux-ppc64" 156 | 157 | elif compiller == "clang": 158 | if arch == "x86_32": 159 | return "linux-x86-clang" 160 | elif arch == "x86_64": 161 | return "linux-x86_64-clang" 162 | elif arch == "arm32": 163 | return "linux-armv4" 164 | elif arch == "arm64": 165 | return "linux-aarch64" 166 | elif arch == "rv64": 167 | return "linux64-riscv64" 168 | elif arch == "ppc32": 169 | return "linux-ppc" 170 | elif arch == "ppc64": 171 | return "linux-ppc64" 172 | elif arch == "ppc64": 173 | return "linux-ppc64" 174 | 175 | elif platform == "windows": 176 | if env.msvc: 177 | if arch == "x86_32": 178 | return "VC-WIN32" 179 | if arch == "x86_64": 180 | return "VC-WIN64A" 181 | if arch == "arm32": 182 | return "VC-WIN64-ARM" 183 | else: 184 | if arch == "x86_32": 185 | return "mingw" 186 | if arch == "x86_64": 187 | return "mingw" 188 | 189 | elif platform == "macos": 190 | llvm = env["use_llvm"] == True 191 | darwin_target = "" 192 | 193 | if arch == "x86_64": 194 | darwin_target = "darwin64-x86_64" 195 | elif arch == "x86_32": 196 | darwin_target = "darwin-i386" 197 | elif arch == "arm64": 198 | darwin_target = "darwin64-arm64" 199 | elif arch == "ppc32": 200 | darwin_target = "darwin-ppc" 201 | elif arch == "ppc64": 202 | darwin_target = "darwin64-ppc" 203 | 204 | if llvm: 205 | darwin_target += "-clang" 206 | 207 | return darwin_target 208 | 209 | 210 | 211 | 212 | # https://wiki.openssl.org/index.php/Compilation_and_Installation#Supported_Platforms 213 | 214 | print("FALHA:" + arch + " -> " + platform) 215 | raise ValueError("Architecture '%s' not supported for platform: '%s'" % (arch, platform)) 216 | return "" 217 | 218 | 219 | 220 | def get_architecture(env): 221 | architecture = "" 222 | if env["arch"] in ["x86_32", "x86_64"]: 223 | return "x86" 224 | elif env["arch"] in ["arm32", "arm64"]: 225 | return "arm" 226 | elif env["arch"] in ["rv64"]: 227 | return "riscv" 228 | elif env["arch"] in ["ppc32", "ppc64"]: 229 | return "power" 230 | elif env["arch"] in ["wasm32"]: 231 | return "wasm" 232 | 233 | raise ValueError("Architecture '%s' not supported for platform: '%s'" % (env["arch"], env["platform"])) 234 | return architecture 235 | 236 | 237 | 238 | 239 | # https://wiki.openssl.org/index.php/Compilation_and_Installation 240 | # Olhar antes de adicionar novas plataformas 241 | def ssl_options(platform): 242 | ssl_config_options = [ 243 | "no-ssl3", 244 | "no-weak-ssl-ciphers", 245 | "no-legacy", 246 | "no-shared", 247 | "shared", 248 | "no-tests", 249 | "no-docs", 250 | ] 251 | 252 | if platform == "windows": 253 | ssl_config_options.append("enable-capieng") 254 | 255 | return ssl_config_options 256 | 257 | 258 | 259 | 260 | def update_openssl(): 261 | git_cmd = ["git pull", "--recurse-submodules"] 262 | subprocess.run(git_cmd, shell=True, cwd="3party/openssl") 263 | 264 | --------------------------------------------------------------------------------