├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── _config.yml ├── easy-mysql.inc └── login-register.pwn /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pwn linguist-language=Pawn 2 | *.inc linguist-language=Pawn 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2015 Freddy Borja AKA ThePhenix(ThreeKingz) 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Easy - MySQL V3.8 2 | 3 | This include allows you to handle MySQL queries in a simplified way. This means that you won't need to write queries for the most part. 4 | 5 | 6 | ## Installation: 7 | 8 | In order to use this include, you need the latest version of the MySQL plugin by BlueG, which can be obtained through the following link: 9 | 10 | https://github.com/pBlueG/SA-MP-MySQL/releases 11 | 12 | You simply need to place the latest release of easy-mysql.inc into your includes folder and include it in your script. 13 | 14 | ```pawn 15 | #include 16 | ``` 17 | 18 | ## Functions: 19 | 20 | ### SQL::Open and SQL::OpenEx 21 | 22 | The only difference between those two functions is that SQL::Open takes an integer for argument as row_identifier and SQL::OpenEx a string (could be a player's name). 23 | 24 | This function allows to execute a defined type of MySQL command (SQL::qtypes). 25 | The following MySQL instructions are available (SQL::qtypes) 26 | ```pawn 27 | SQL::UPDATE 28 | SQL::UPDATE2 29 | SQL::TUPDATE 30 | SQL::CREATE 31 | SQL::INSERT 32 | SQL::READ 33 | SQL::READ2 34 | SQL::TREAD 35 | SQL::CALLBACK 36 | SQL::MREAD 37 | SQL::MREAD2 38 | SQL::MTREAD 39 | ``` 40 | 41 | ```pawn 42 | SQL::Open(SQL::qtypes:type, const table[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", limit = -1, limit2 = -1, const desc[] = "", MySQL:connectionHandle = MYSQL_DEFAULT_HANDLE) 43 | ``` 44 | 45 | #### Parameters 46 | ```pawn 47 | SQL::qtypes:type 48 | ``` 49 | ##### Specifies the MySQL instruction you want to perform 50 | ```pawn 51 | const table[] 52 | ``` 53 | ##### Specifies the name of the table the instruction will be executed at. 54 | ```pawn 55 | const column_where[] = "" 56 | ``` 57 | ##### If you're using the right type of instruction, specifies the name of the column for which you know the right row identifier value, could be the name of the field of player's database ID for instance. ("db_id) 58 | ```pawn 59 | row_identifier 60 | ``` 61 | ##### Specifies the row identifier, namely: Execute some MySQL instruction (WHERE column_where = row_identifer), if it's a player then it could be the player's database ID for example. 62 | 63 | #### Example 64 | 65 | ##### Checking if a table exists and if not creating a new table: 66 | ```pawn 67 | //Checking if the table '"samp_users"' exists 68 | if(!SQL::ExistsTable("samp_users")) 69 | { 70 | //If not, then create a table called '"samp_users"'. 71 | new handle = SQL::Open(SQL::CREATE, "samp_users"); //Opening a valid handle to create the table 72 | SQL::AddTableColumn(handle, "p_id", SQL_TYPE_INT, 11, false, true); 73 | SQL::AddTableColumn(handle, "p_name", SQL_TYPE_VCHAR, 24, .setindex = true); 74 | SQL::AddTableColumn(handle, "p_password", SQL_TYPE_VCHAR, 64); 75 | SQL::AddTableColumn(handle, "p_score", SQL_TYPE_INT); 76 | SQL::AddTableColumn(handle, "p_posx", SQL_TYPE_FLOAT); 77 | SQL::AddTableColumn(handle, "p_posy", SQL_TYPE_FLOAT); 78 | SQL::AddTableColumn(handle, "p_posz", SQL_TYPE_FLOAT); 79 | SQL::Close(handle);//Closing the previous opened handle. 80 | } 81 | ``` 82 | 83 | ##### Inserting data: 84 | ```pawn 85 | new handle = SQL::Open(SQL::INSERT, "samp_users"); 86 | SQL::ToggleAutoIncrement(handle, true);//Toggles auto increment, SQL::Close will return cache_insert_id(); 87 | SQL::WriteString(handle, "p_name", ret_pName(playerid)); 88 | SQL::WriteString(handle, "p_password", UserInfo[playerid][p_password]); 89 | SQL::WriteInt(handle, "p_score", 0); 90 | SQL::WriteFloat(handle, "p_posx", 0.0); 91 | SQL::WriteFloat(handle, "p_posy", 0.0); 92 | SQL::WriteFloat(handle, "p_posz", 0.0); 93 | SQL::Close(handle); 94 | ``` 95 | 96 | ##### Updating data: 97 | ```pawn 98 | new handle = SQL::Open(SQL::UPDATE, "samp_users", "p_id", UserInfo[playerid][p_id]); 99 | SQL::WriteInt(handle, "p_score", GetPlayerScore(playerid)); 100 | SQL::WriteFloat(handle, "p_posx", UserInfo[playerid][p_posx]); 101 | SQL::WriteFloat(handle, "p_posy", UserInfo[playerid][p_posy]); 102 | SQL::WriteFloat(handle, "p_posz", UserInfo[playerid][p_posz]); 103 | SQL::Close(handle); 104 | ``` 105 | ##### Reading data from a SINGLE row: 106 | ```pawn 107 | new handle = SQL::Open(SQL::READ, "samp_users", "p_id", UserInfo[playerid][p_id]); 108 | SQL::ReadInt(handle, "p_score", UserInfo[playerid][p_score]); 109 | SQL::ReadFloat(handle, "p_posx", UserInfo[playerid][p_posx]); 110 | SQL::ReadFloat(handle, "p_posy", UserInfo[playerid][p_posy]); 111 | SQL::ReadFloat(handle, "p_posz", UserInfo[playerid][p_posz]); 112 | SQL::Close(handle); 113 | ``` 114 | 115 | ##### Reading all rows in a table: 116 | ###### Example: reading all the rows in a faction system: 117 | ```pawn 118 | new handle = SQL::Open(SQL::MTREAD, "samp_factions"); 119 | SQL::ReadRetrievedRows(handle, i) //i represents the row number that's being read 120 | { 121 | SQL::ReadInt(handle, "f_dbID", FactionInfo[i][f_dbID], i); 122 | SQL::ReadInt(handle, "f_hasLeader", FactionInfo[i][f_hasLeader], i); 123 | SQL::ReadInt(handle, "f_ranks", FactionInfo[i][f_ranks], i); 124 | SQL::ReadInt(handle, "f_budget", FactionInfo[i][f_budget], i); 125 | SQL::ReadInt(handle, "f_color", FactionInfo[i][f_color], i); 126 | SQL::ReadInt(handle, "f_dbID", FactionInfo[i][f_dbID], i); 127 | SQL::ReadString(handle, "f_acronym", FactionInfo[i][f_acronym], MAX_FAC_ACRO_LEN, i); 128 | SQL::ReadString(handle, "f_name", FactionInfo[i][f_name], MAX_FAC_LEN, i); 129 | SQL::ReadString(handle, "f_leaderName", FactionInfo[i][f_leaderName], MAX_PLAYER_NAME, i); 130 | for(new l = 0; l < MAX_FAC_RANKS; l++) 131 | { 132 | format(strf, sizeof(strf), "f_rankname%d", l); 133 | SQL::ReadString(handle, "f_leaderName", f_rankname[i][l], MAX_FAC_RANK_LEN, i); 134 | } 135 | FactionInfo[i][f_valid] = 1; 136 | } 137 | new rows = SQL::Close(handle); //returns the number of rows 138 | printf("[MYSQL] Factions loaded: %d", rows); 139 | ``` 140 | ##### For more information you can check the script and look at the available functions. 141 | 142 | ### SQL::RowExists and SQL::RowExistsEx 143 | 144 | Returns 1 if the specific row exists and 0 if not. 145 | #### Example 146 | ##### Checking if a player's name exists in a table called player's where the column name is "pname" and the rowidentifier is the player's name. 147 | ```pawn 148 | if(SQL::RowExistsEx("samp_users", "pname", ret_pName(playerid))) 149 | { 150 | //prompt the player to a login dialog 151 | } 152 | ``` 153 | More functions will be documented soon. 154 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /easy-mysql.inc: -------------------------------------------------------------------------------- 1 | /* 2 | _ ____ ___ 3 | | | |___ \ / _ \ 4 | ___ __ _ ___ _ _ ______ _ __ ___ _ _ ___ __ _ | | __ __ __) | | (_) | 5 | / _ \ / _` | / __| | | | | |______| | '_ ` _ \ | | | | / __| / _` | | | \ \ / / |__ < > _ < 6 | | __/ | (_| | \__ \ | |_| | | | | | | | | |_| | \__ \ | (_| | | | \ V / ___) | _ | (_) | 7 | \___| \__,_| |___/ \__, | |_| |_| |_| \__, | |___/ \__, | |_| \_/ |____/ (_) \___/ 8 | __/ | __/ | | | 9 | |___/ |___/ |_| 10 | 11 | Portions of this code are Copyright (C) 2015 ThreeKingz the Original Author 12 | Licensed under the Apache License, Version 2.0 (the "License"); 13 | you may not use this file except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | 24 | Credits: 25 | Original Author: (creator) 26 | * Freddy Borja - ThePhenix AKA ThreeKingz 27 | Author: (current developer) 28 | * eco1999 AKA Max_Andolini 29 | Version: 3.8 30 | 31 | Bugs solved. 32 | 33 | */ 34 | 35 | #if defined _tksql_included//Avoid including it again! 36 | #endinput 37 | #endif 38 | #define _tksql_included 39 | 40 | #if !defined _samp_included 41 | #tryinclude 42 | #if !defined _samp_included 43 | #error " was not found. Make sure the include is correctly placed on your includes folder." 44 | #endif 45 | #endif 46 | 47 | 48 | #if !defined mysql_included 49 | #tryinclude 50 | #if !defined mysql_included 51 | #error " was not found on your includes folder. Make sure you have the a_mysql include by BlueG on your includes folder." 52 | #endif 53 | #endif 54 | 55 | 56 | //By Y_Less 57 | //native strcpy(dest[], src[], len = sizeof(dest)); 58 | #if !defined strcpy 59 | #define strcpy(%0,%1) \ 60 | strcat((%0[0] = '\0', %0), %1) 61 | #endif 62 | #if !defined isnull 63 | #define isnull(%1) \ 64 | ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1])))) 65 | #endif 66 | #if !defined SQL_MAX_HANDLES 67 | #define SQL_MAX_HANDLES (3)//Maximun concurrent handles running. 68 | #endif 69 | 70 | #define SQL_MAX_TABLE_NAME (64) 71 | #define SQL_MAX_QUERY_LENGTH (8192) 72 | #define SQL_MAX_INDEXES (4) 73 | #define SQL_INVALID_HANDLE (-1) 74 | #define SQL_FORM_LENGTH (256) 75 | #define SQL:: SQL_T 76 | #define SQL_Warning(%0) (printf("[MYSQL] - WARNING: " %0)) 77 | #define SQL_Error(%0) (printf("[MYSQL] - ERROR: " %0)) 78 | #define SQL_Notice(%0) (printf("[MYSQL] - NOTICE: " %0)) 79 | 80 | 81 | /*============================================================================== 82 | Internal variables and functions 83 | ================================================================================*/ 84 | 85 | enum SQL::datatypes {SQL_TYPE_INT, SQL_TYPE_VCHAR, SQL_TYPE_FLOAT} 86 | enum SQL::qtypes {SQL::UPDATE, SQL::UPDATE2, SQL::TUPDATE, SQL::CREATE, SQL::INSERT, SQL_TYPE_DELETE, SQL::READ, SQL::READ2, SQL::TREAD, SQL::CALLBACK, SQL::MREAD, SQL::MREAD2, SQL::MTREAD} 87 | enum SQL::ftypes {SQL::CASCADE, SQL::SETNULL, SQL::NOACTION, SQL::RESTRICT} 88 | 89 | static stock 90 | bool:SQL::UsedHandle[SQL_MAX_HANDLES], 91 | MySQL:SQL::upd_connectionHandle[SQL_MAX_HANDLES], 92 | SQL::upd_table[SQL_MAX_HANDLES][SQL_MAX_TABLE_NAME], 93 | SQL::upd_rowidentifier[SQL_MAX_HANDLES][SQL_FORM_LENGTH], 94 | SQL::upd_query[SQL_MAX_HANDLES][SQL_MAX_QUERY_LENGTH], 95 | SQL::upd_query_2[SQL_MAX_HANDLES][SQL_MAX_QUERY_LENGTH], 96 | SQL::upd_increment_key[SQL_MAX_HANDLES][SQL_FORM_LENGTH], 97 | SQL::upd_form[SQL_FORM_LENGTH], 98 | SQL::upd_form2[SQL_FORM_LENGTH], 99 | SQL::upd_datacount[SQL_MAX_HANDLES], 100 | SQL::qtypes:SQL::upd_type[SQL_MAX_HANDLES], 101 | SQL::upd_pos[SQL_MAX_HANDLES], 102 | Cache:SQL::ReadCache[SQL_MAX_HANDLES], 103 | bool:SQL::upd_useautoincrement[SQL_MAX_HANDLES], 104 | SQL::primarykey[SQL_MAX_HANDLES][64], 105 | SQL::engine[SQL_MAX_HANDLES][64], 106 | SQL::charset[SQL_MAX_HANDLES][64], 107 | SQL::index_set[SQL_MAX_HANDLES][SQL_MAX_INDEXES], 108 | SQL::index[SQL_MAX_HANDLES][SQL_MAX_INDEXES][64], 109 | SQL::isset_primarykey[SQL_MAX_HANDLES] 110 | ; 111 | 112 | 113 | stock IsMultiReadHandleValid(handle) 114 | { 115 | if(!SQL::IsValidUpdatingSlot(handle)) return 0; 116 | if(SQL::upd_type[handle] != SQL::CALLBACK) return 0; 117 | return 1; 118 | } 119 | static stock SQL::GetFreeUpdatingSlot() 120 | { 121 | new i = 0; 122 | while (i < sizeof (SQL::UsedHandle) && SQL::UsedHandle[i] == true) 123 | { 124 | i++; 125 | } 126 | if(i == sizeof (SQL::UsedHandle)) return SQL_INVALID_HANDLE; 127 | return i; 128 | } 129 | 130 | static stock SQL::GetFreeIndexSlot(handle) 131 | { 132 | new i = 0; 133 | while (i < sizeof (SQL::index_set) && SQL::index_set[handle][i] == 1) 134 | { 135 | i++; 136 | } 137 | if(i == sizeof (SQL::index_set)) return SQL_INVALID_HANDLE; 138 | return i; 139 | } 140 | 141 | 142 | static stock SQL::RetFType(SQL::ftypes:type) 143 | { 144 | new SQL::fname[64]; 145 | switch(type) 146 | { 147 | case SQL::CASCADE: SQL::fname = "CASCADE"; 148 | case SQL::SETNULL: SQL::fname = "SET NULL"; 149 | case SQL::RESTRICT: SQL::fname = "RESTRICT"; 150 | case SQL::NOACTION: SQL::fname = "NO ACTION"; 151 | } 152 | return SQL::fname; 153 | } 154 | 155 | static stock SQL::IsValidUpdatingSlot(handle) 156 | { 157 | return SQL::UsedHandle[handle]; 158 | } 159 | 160 | static stock SQL::OpenTable_MultiRead(const table[], const column_where[] = "", row_identifier = -1, limit = -1, limit2 = -1, const desc[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 161 | { 162 | if(strlen(table) > SQL_MAX_TABLE_NAME) 163 | { 164 | SQL_Error("(SQL::OpenTable) Invalid table length."); 165 | return SQL_INVALID_HANDLE; 166 | } 167 | new 168 | i = SQL::GetFreeUpdatingSlot() 169 | ; 170 | if(i == SQL_INVALID_HANDLE) 171 | { 172 | return SQL_INVALID_HANDLE; 173 | } 174 | SQL::upd_type[i] = SQL::CALLBACK; 175 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s`", table); 176 | if(!isnull(column_where)) 177 | { 178 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " WHERE `%s`='%d'", column_where, row_identifier); 179 | strcat(SQL::upd_form, SQL::upd_form2); 180 | } 181 | if(!isnull(desc)) 182 | { 183 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " ORDER BY `%s` DESC", desc); 184 | strcat(SQL::upd_form, SQL::upd_form2); 185 | } 186 | if(limit != -1 && limit2 != -1) 187 | { 188 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d, %d", limit, limit2); 189 | strcat(SQL::upd_form, SQL::upd_form2); 190 | } 191 | if(limit != -1 && limit2 == -1) 192 | { 193 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d", limit); 194 | strcat(SQL::upd_form, SQL::upd_form2); 195 | } 196 | strcat(SQL::upd_form, " "); 197 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 198 | if(mysql_errno() != 0) 199 | { 200 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 201 | } 202 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 203 | SQL::upd_datacount[i] = 0; 204 | if(cache_is_valid(SQL::ReadCache[i])) 205 | { 206 | SQL::UsedHandle[i] = true; 207 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 208 | return i; 209 | } 210 | return SQL_INVALID_HANDLE; 211 | } 212 | 213 | static stock SQL::OpenTable_MultiRead2(const table[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", limit = -1, limit2 = -1, const desc[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 214 | { 215 | if(strlen(table) > SQL_MAX_TABLE_NAME) 216 | { 217 | SQL_Error("(SQL::OpenTable) Invalid table length."); 218 | return SQL_INVALID_HANDLE; 219 | } 220 | new 221 | i = SQL::GetFreeUpdatingSlot() 222 | ; 223 | if(i == SQL_INVALID_HANDLE) 224 | { 225 | return SQL_INVALID_HANDLE; 226 | } 227 | SQL::upd_type[i] = SQL::CALLBACK; 228 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s`", table); 229 | if(!isnull(column_where)) 230 | { 231 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " WHERE `%s`='%d'", column_where, row_identifier); 232 | strcat(SQL::upd_form, SQL::upd_form2); 233 | } 234 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 235 | { 236 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier2); 237 | strcat(SQL::upd_form, SQL::upd_form2); 238 | } 239 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 240 | { 241 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier3); 242 | strcat(SQL::upd_form, SQL::upd_form2); 243 | } 244 | if(!isnull(desc)) 245 | { 246 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " ORDER BY `%s` DESC", desc); 247 | strcat(SQL::upd_form, SQL::upd_form2); 248 | } 249 | if(limit != -1 && limit2 != -1) 250 | { 251 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d, %d", limit, limit2); 252 | strcat(SQL::upd_form, SQL::upd_form2); 253 | } 254 | if(limit != -1 && limit2 == -1) 255 | { 256 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d", limit); 257 | strcat(SQL::upd_form, SQL::upd_form2); 258 | } 259 | strcat(SQL::upd_form, " "); 260 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 261 | if(mysql_errno() != 0) 262 | { 263 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 264 | } 265 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 266 | SQL::upd_datacount[i] = 0; 267 | if(cache_is_valid(SQL::ReadCache[i])) 268 | { 269 | SQL::UsedHandle[i] = true; 270 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 271 | return i; 272 | } 273 | return SQL_INVALID_HANDLE; 274 | } 275 | 276 | static stock SQL::OpenTable_MultiReadEx(const table[], const column_where[] = "", const row_identifier[] = "", limit = -1, limit2 = -1, const desc[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 277 | { 278 | if(strlen(table) > SQL_MAX_TABLE_NAME) 279 | { 280 | SQL_Error("(SQL::OpenTable) Invalid table length."); 281 | return SQL_INVALID_HANDLE; 282 | } 283 | new 284 | i = SQL::GetFreeUpdatingSlot() 285 | ; 286 | if(i == SQL_INVALID_HANDLE) 287 | { 288 | return SQL_INVALID_HANDLE; 289 | } 290 | SQL::upd_type[i] = SQL::CALLBACK; 291 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s`", table); 292 | if(!isnull(column_where)) 293 | { 294 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " WHERE `%s`='%s'", column_where, row_identifier); 295 | strcat(SQL::upd_form, SQL::upd_form2); 296 | } 297 | if(!isnull(desc)) 298 | { 299 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " ORDER BY `%s` DESC", desc); 300 | strcat(SQL::upd_form, SQL::upd_form2); 301 | } 302 | if(limit != -1 && limit2 != -1) 303 | { 304 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d, %d", limit, limit2); 305 | strcat(SQL::upd_form, SQL::upd_form2); 306 | } 307 | if(limit != -1 && limit2 == -1) 308 | { 309 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d", limit); 310 | strcat(SQL::upd_form, SQL::upd_form2); 311 | } 312 | strcat(SQL::upd_form, " "); 313 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 314 | if(mysql_errno() != 0) 315 | { 316 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 317 | } 318 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 319 | SQL::upd_datacount[i] = 0; 320 | if(cache_is_valid(SQL::ReadCache[i])) 321 | { 322 | SQL::UsedHandle[i] = true; 323 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 324 | return i; 325 | } 326 | return SQL_INVALID_HANDLE; 327 | } 328 | 329 | static stock SQL::OpenTable_MultiReadEx2(const table[], const column_where[] = "", const row_identifier[] = "", const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, limit = -1, limit2 = -1, const desc[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 330 | { 331 | if(strlen(table) > SQL_MAX_TABLE_NAME) 332 | { 333 | SQL_Error("(SQL::OpenTable) Invalid table length."); 334 | return SQL_INVALID_HANDLE; 335 | } 336 | new 337 | i = SQL::GetFreeUpdatingSlot() 338 | ; 339 | if(i == SQL_INVALID_HANDLE) 340 | { 341 | return SQL_INVALID_HANDLE; 342 | } 343 | SQL::upd_type[i] = SQL::CALLBACK; 344 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s`", table); 345 | if(!isnull(column_where)) 346 | { 347 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " WHERE `%s`='%s'", column_where, row_identifier); 348 | strcat(SQL::upd_form, SQL::upd_form2); 349 | } 350 | if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1) 351 | { 352 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier2); 353 | strcat(SQL::upd_form, SQL::upd_form2); 354 | } 355 | if(!isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2)) 356 | { 357 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier3); 358 | strcat(SQL::upd_form, SQL::upd_form2); 359 | } 360 | if(!isnull(desc)) 361 | { 362 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " ORDER BY `%s` DESC", desc); 363 | strcat(SQL::upd_form, SQL::upd_form2); 364 | } 365 | if(limit != -1 && limit2 != -1) 366 | { 367 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d, %d", limit, limit2); 368 | strcat(SQL::upd_form, SQL::upd_form2); 369 | } 370 | if(limit != -1 && limit2 == -1) 371 | { 372 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d", limit); 373 | strcat(SQL::upd_form, SQL::upd_form2); 374 | } 375 | strcat(SQL::upd_form, " "); 376 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 377 | if(mysql_errno() != 0) 378 | { 379 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 380 | } 381 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 382 | SQL::upd_datacount[i] = 0; 383 | if(cache_is_valid(SQL::ReadCache[i])) 384 | { 385 | SQL::UsedHandle[i] = true; 386 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 387 | return i; 388 | } 389 | return SQL_INVALID_HANDLE; 390 | } 391 | 392 | static stock SQL::OpenTable_MultiTableRead(const table[], MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 393 | { 394 | if(strlen(table) > SQL_MAX_TABLE_NAME) 395 | { 396 | SQL_Error("(SQL::OpenTable) Invalid table length."); 397 | return SQL_INVALID_HANDLE; 398 | } 399 | new 400 | i = SQL::GetFreeUpdatingSlot() 401 | ; 402 | if(i == SQL_INVALID_HANDLE) 403 | { 404 | return SQL_INVALID_HANDLE; 405 | } 406 | SQL::upd_type[i] = SQL::CALLBACK; 407 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s` ", table); 408 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 409 | if(mysql_errno() != 0) 410 | { 411 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 412 | } 413 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 414 | SQL::upd_datacount[i] = 0; 415 | if(cache_is_valid(SQL::ReadCache[i])) 416 | { 417 | SQL::UsedHandle[i] = true; 418 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 419 | return i; 420 | } 421 | return SQL_INVALID_HANDLE; 422 | } 423 | 424 | static stock SQL::CreateTable(const tablename[], const engine[], const charset[] = "latin5", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 425 | { 426 | if(strlen(tablename) > SQL_MAX_TABLE_NAME) 427 | { 428 | SQL_Error("(SQL::CreateTable) Invalid table length."); 429 | return SQL_INVALID_HANDLE; 430 | } 431 | new 432 | i = SQL::GetFreeUpdatingSlot() 433 | ; 434 | if(i == SQL_INVALID_HANDLE) 435 | { 436 | return SQL_INVALID_HANDLE; 437 | } 438 | SQL::upd_type[i] = SQL::CREATE; 439 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 440 | strcpy(SQL::upd_table[i], tablename); 441 | strcpy(SQL::engine[i], engine); 442 | strcpy(SQL::charset[i], charset); 443 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "CREATE TABLE %s (", SQL::upd_table[i]); 444 | SQL::upd_datacount[i] = 0; 445 | SQL::isset_primarykey[i] = 0; 446 | SQL::UsedHandle[i] = true; 447 | return i; 448 | } 449 | 450 | static stock SQL::OpenTable_Read(const table[], const column_where[] = "", row_identifier = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 451 | { 452 | if(strlen(table) > SQL_MAX_TABLE_NAME) 453 | { 454 | SQL_Error("(SQL::OpenTable) Invalid table length."); 455 | return SQL_INVALID_HANDLE; 456 | } 457 | if(column_where[0] == '\0') 458 | { 459 | SQL_Error("(SQL::OpenTable) No format has been entered. Format example: (pID)"); 460 | return SQL_INVALID_HANDLE; 461 | } 462 | new 463 | i = SQL::GetFreeUpdatingSlot() 464 | ; 465 | if(i == SQL_INVALID_HANDLE) 466 | { 467 | return SQL_INVALID_HANDLE; 468 | } 469 | SQL::upd_type[i] = SQL::READ; 470 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s` WHERE `%s`='%d' ", table, column_where, row_identifier); 471 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 472 | if(mysql_errno() != 0) 473 | { 474 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 475 | } 476 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 477 | SQL::upd_datacount[i] = 0; 478 | if(cache_is_valid(SQL::ReadCache[i])) 479 | { 480 | SQL::UsedHandle[i] = true; 481 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 482 | return i; 483 | } 484 | return SQL_INVALID_HANDLE; 485 | } 486 | 487 | static stock SQL::OpenTable_Read2(const table[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 488 | { 489 | if(strlen(table) > SQL_MAX_TABLE_NAME) 490 | { 491 | SQL_Error("(SQL::OpenTable) Invalid table length."); 492 | return SQL_INVALID_HANDLE; 493 | } 494 | if(column_where[0] == '\0') 495 | { 496 | SQL_Error("(SQL::OpenTable) No format has been entered. Format example: (pID)"); 497 | return SQL_INVALID_HANDLE; 498 | } 499 | if(column_where2[0] == '\0') 500 | { 501 | SQL_Error("(SQL::OpenTable) No format has been entered. Format example: (pID)"); 502 | return SQL_INVALID_HANDLE; 503 | } 504 | new 505 | i = SQL::GetFreeUpdatingSlot() 506 | ; 507 | if(i == SQL_INVALID_HANDLE) 508 | { 509 | return SQL_INVALID_HANDLE; 510 | } 511 | SQL::upd_type[i] = SQL::READ; 512 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s` WHERE `%s`='%d'", table, column_where, row_identifier); 513 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 514 | { 515 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier2); 516 | strcat(SQL::upd_form, SQL::upd_form2); 517 | } 518 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 519 | { 520 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier3); 521 | strcat(SQL::upd_form, SQL::upd_form2); 522 | } 523 | strcat(SQL::upd_form, " "); 524 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 525 | if(mysql_errno() != 0) 526 | { 527 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 528 | } 529 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 530 | SQL::upd_datacount[i] = 0; 531 | if(cache_is_valid(SQL::ReadCache[i])) 532 | { 533 | SQL::UsedHandle[i] = true; 534 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 535 | return i; 536 | } 537 | return SQL_INVALID_HANDLE; 538 | } 539 | 540 | static stock SQL::OpenTable_ReadEx(const table[], const column_where[] = "", const row_identifier[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 541 | { 542 | if(strlen(table) > SQL_MAX_TABLE_NAME) 543 | { 544 | SQL_Error("(SQL::OpenTable_ReadEx) Invalid table length."); 545 | return SQL_INVALID_HANDLE; 546 | } 547 | if(column_where[0] == '\0') 548 | { 549 | SQL_Error("(SQL::OpenTable_ReadEx) No format has been entered. Format example: (pID)"); 550 | return SQL_INVALID_HANDLE; 551 | } 552 | new 553 | i = SQL::GetFreeUpdatingSlot() 554 | ; 555 | if(i == SQL_INVALID_HANDLE) 556 | { 557 | return SQL_INVALID_HANDLE; 558 | } 559 | SQL::upd_type[i] = SQL::READ; 560 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s` WHERE `%s`='%s' ", table, column_where, row_identifier); 561 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 562 | if(mysql_errno() != 0) 563 | { 564 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 565 | } 566 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 567 | SQL::upd_datacount[i] = 0; 568 | if(cache_is_valid(SQL::ReadCache[i])) 569 | { 570 | SQL::UsedHandle[i] = true; 571 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 572 | return i; 573 | } 574 | return SQL_INVALID_HANDLE; 575 | } 576 | 577 | static stock SQL::OpenTable_ReadEx2(const table[], const column_where[] = "", const row_identifier[] = "", const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 578 | { 579 | if(strlen(table) > SQL_MAX_TABLE_NAME) 580 | { 581 | SQL_Error("(SQL::OpenTable_ReadEx) Invalid table length."); 582 | return SQL_INVALID_HANDLE; 583 | } 584 | if(column_where[0] == '\0') 585 | { 586 | SQL_Error("(SQL::OpenTable_ReadEx) No format has been entered. Format example: (pID)"); 587 | return SQL_INVALID_HANDLE; 588 | } 589 | if(column_where2[0] == '\0') 590 | { 591 | SQL_Error("(SQL::OpenTable_ReadEx) No format has been entered. Format example: (pID)"); 592 | return SQL_INVALID_HANDLE; 593 | } 594 | new 595 | i = SQL::GetFreeUpdatingSlot() 596 | ; 597 | if(i == SQL_INVALID_HANDLE) 598 | { 599 | return SQL_INVALID_HANDLE; 600 | } 601 | SQL::upd_type[i] = SQL::READ; 602 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s` WHERE `%s`='%s'", table, column_where, row_identifier); 603 | if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1) 604 | { 605 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier2); 606 | strcat(SQL::upd_form, SQL::upd_form2); 607 | } 608 | if(!isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2)) 609 | { 610 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier3); 611 | strcat(SQL::upd_form, SQL::upd_form2); 612 | } 613 | strcat(SQL::upd_form, " "); 614 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 615 | if(mysql_errno() != 0) 616 | { 617 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 618 | } 619 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 620 | SQL::upd_datacount[i] = 0; 621 | if(cache_is_valid(SQL::ReadCache[i])) 622 | { 623 | SQL::UsedHandle[i] = true; 624 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 625 | return i; 626 | } 627 | return SQL_INVALID_HANDLE; 628 | } 629 | 630 | static stock SQL::OpenTable_TableRead(const table[], MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 631 | { 632 | if(strlen(table) > SQL_MAX_TABLE_NAME) 633 | { 634 | SQL_Error("(SQL::OpenTable) Invalid table length."); 635 | return SQL_INVALID_HANDLE; 636 | } 637 | new 638 | i = SQL::GetFreeUpdatingSlot() 639 | ; 640 | if(i == SQL_INVALID_HANDLE) 641 | { 642 | return SQL_INVALID_HANDLE; 643 | } 644 | SQL::upd_type[i] = SQL::READ; 645 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT * FROM `%s` ", table); 646 | SQL::ReadCache[i] = mysql_query(MySQL:connectionhandle, SQL::upd_form); 647 | if(mysql_errno() != 0) 648 | { 649 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 650 | } 651 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "%s", SQL::upd_form); 652 | SQL::upd_datacount[i] = 0; 653 | if(cache_is_valid(SQL::ReadCache[i])) 654 | { 655 | SQL::UsedHandle[i] = true; 656 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 657 | return i; 658 | } 659 | return SQL_INVALID_HANDLE; 660 | } 661 | 662 | static stock SQL::OpenTable_TableUpdate(const table[], MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 663 | { 664 | if(strlen(table) > SQL_MAX_TABLE_NAME) 665 | { 666 | SQL_Error("(SQL::OpenTable) Invalid table length."); 667 | return SQL_INVALID_HANDLE; 668 | } 669 | new 670 | i = SQL::GetFreeUpdatingSlot() 671 | ; 672 | if(i == SQL_INVALID_HANDLE) 673 | { 674 | return SQL_INVALID_HANDLE; 675 | } 676 | SQL::upd_type[i] = SQL::TUPDATE; 677 | strcpy(SQL::upd_table[i], table); 678 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "UPDATE `%s` SET ", SQL::upd_table[i]); 679 | SQL::upd_datacount[i] = 0; 680 | SQL::UsedHandle[i] = true; 681 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 682 | return i; 683 | } 684 | 685 | static stock SQL::OpenTable_Update(const table[], const column_where[] = "", row_identifier = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 686 | { 687 | if(strlen(table) > SQL_MAX_TABLE_NAME) 688 | { 689 | SQL_Error("(SQL::OpenTable) Invalid table length."); 690 | return SQL_INVALID_HANDLE; 691 | } 692 | if(column_where[0] == '\0') 693 | { 694 | SQL_Error("(SQL::OpenTable) No format has been entered. Format example: (pID)"); 695 | return SQL_INVALID_HANDLE; 696 | } 697 | new 698 | i = SQL::GetFreeUpdatingSlot() 699 | ; 700 | if(i == SQL_INVALID_HANDLE) 701 | { 702 | return SQL_INVALID_HANDLE; 703 | } 704 | SQL::upd_type[i] = SQL::UPDATE; 705 | strcpy(SQL::upd_table[i], table); 706 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "UPDATE `%s` SET ", SQL::upd_table[i]); 707 | mysql_format(MySQL:connectionhandle, SQL::upd_rowidentifier[i], SQL_FORM_LENGTH, " WHERE `%s`='%d' ", column_where, row_identifier); 708 | SQL::upd_datacount[i] = 0; 709 | SQL::UsedHandle[i] = true; 710 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 711 | return i; 712 | } 713 | 714 | static stock SQL::OpenTable_Update2(const table[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 715 | { 716 | if(strlen(table) > SQL_MAX_TABLE_NAME) 717 | { 718 | SQL_Error("(SQL::OpenTable) Invalid table length."); 719 | return SQL_INVALID_HANDLE; 720 | } 721 | if(column_where[0] == '\0') 722 | { 723 | SQL_Error("(SQL::OpenTable) No format has been entered. Format example: (pID)"); 724 | return SQL_INVALID_HANDLE; 725 | } 726 | if(column_where2[0] == '\0') 727 | { 728 | SQL_Error("(SQL::OpenTable) No format has been entered. Format example: (pID)"); 729 | return SQL_INVALID_HANDLE; 730 | } 731 | new 732 | i = SQL::GetFreeUpdatingSlot() 733 | ; 734 | if(i == SQL_INVALID_HANDLE) 735 | { 736 | return SQL_INVALID_HANDLE; 737 | } 738 | SQL::upd_type[i] = SQL::UPDATE; 739 | strcpy(SQL::upd_table[i], table); 740 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "UPDATE `%s` SET ", SQL::upd_table[i]); 741 | mysql_format(MySQL:connectionhandle, SQL::upd_rowidentifier[i], SQL_FORM_LENGTH, " WHERE `%s`='%d'", column_where, row_identifier); 742 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 743 | { 744 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier2); 745 | strcat(SQL::upd_rowidentifier[i], SQL::upd_form2); 746 | } 747 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 748 | { 749 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier3); 750 | strcat(SQL::upd_rowidentifier[i], SQL::upd_form2); 751 | } 752 | strcat(SQL::upd_rowidentifier[i], " "); 753 | SQL::upd_datacount[i] = 0; 754 | SQL::UsedHandle[i] = true; 755 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 756 | return i; 757 | } 758 | 759 | static stock SQL::OpenTable_UpdateEx(const table[], const column_where[] = "", const row_identifier[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 760 | { 761 | if(strlen(table) > SQL_MAX_TABLE_NAME) 762 | { 763 | SQL_Error("(SQL::OpenTable_UpdateEx) Invalid table length."); 764 | return SQL_INVALID_HANDLE; 765 | } 766 | if(column_where[0] == '\0') 767 | { 768 | SQL_Error("(SQL::OpenTable_UpdateEx) No format has been entered. Format example: (pID)"); 769 | return SQL_INVALID_HANDLE; 770 | } 771 | new 772 | i = SQL::GetFreeUpdatingSlot() 773 | ; 774 | if(i == SQL_INVALID_HANDLE) 775 | { 776 | return SQL_INVALID_HANDLE; 777 | } 778 | SQL::upd_type[i] = SQL::UPDATE; 779 | strcpy(SQL::upd_table[i], table); 780 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "UPDATE `%s` SET ", SQL::upd_table[i]); 781 | mysql_format(MySQL:connectionhandle, SQL::upd_rowidentifier[i], SQL_FORM_LENGTH, " WHERE `%s`='%s' ", column_where, row_identifier); 782 | SQL::upd_datacount[i] = 0; 783 | SQL::UsedHandle[i] = true; 784 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 785 | return i; 786 | } 787 | 788 | static stock SQL::OpenTable_UpdateEx2(const table[], const column_where[] = "", const row_identifier[] = "", const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 789 | { 790 | if(strlen(table) > SQL_MAX_TABLE_NAME) 791 | { 792 | SQL_Error("(SQL::OpenTable_UpdateEx) Invalid table length."); 793 | return SQL_INVALID_HANDLE; 794 | } 795 | if(column_where[0] == '\0') 796 | { 797 | SQL_Error("(SQL::OpenTable_UpdateEx) No format has been entered. Format example: (pID)"); 798 | return SQL_INVALID_HANDLE; 799 | } 800 | if(column_where2[0] == '\0') 801 | { 802 | SQL_Error("(SQL::OpenTable_UpdateEx) No format has been entered. Format example: (pID)"); 803 | return SQL_INVALID_HANDLE; 804 | } 805 | new 806 | i = SQL::GetFreeUpdatingSlot() 807 | ; 808 | if(i == SQL_INVALID_HANDLE) 809 | { 810 | return SQL_INVALID_HANDLE; 811 | } 812 | SQL::upd_type[i] = SQL::UPDATE; 813 | strcpy(SQL::upd_table[i], table); 814 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "UPDATE `%s` SET ", SQL::upd_table[i]); 815 | mysql_format(MySQL:connectionhandle, SQL::upd_rowidentifier[i], SQL_FORM_LENGTH, " WHERE `%s`='%s'", column_where, row_identifier); 816 | if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1) 817 | { 818 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier2); 819 | strcat(SQL::upd_rowidentifier[i], SQL::upd_form2); 820 | } 821 | if(!isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2)) 822 | { 823 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier3); 824 | strcat(SQL::upd_rowidentifier[i], SQL::upd_form2); 825 | } 826 | strcat(SQL::upd_rowidentifier[i], " "); 827 | SQL::upd_datacount[i] = 0; 828 | SQL::UsedHandle[i] = true; 829 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 830 | return i; 831 | } 832 | 833 | static stock SQL::UpdateFloatEntry(handle, const field[], Float:value) 834 | { 835 | if(!SQL::IsValidUpdatingSlot(handle)) 836 | { 837 | SQL_Error("(SQL::UpdateFloatEntry) Invalid handle. Make sure you used (SQL::OpenTable) first."); 838 | return 0; 839 | } 840 | new MySQL:connectionhandle = SQL::upd_connectionHandle[handle]; 841 | if(SQL::upd_type[handle] != SQL::UPDATE && SQL::upd_type[handle] != SQL::TUPDATE) return 0; 842 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "`%s`='%f',", field, value); 843 | strcat(SQL::upd_query[handle], SQL::upd_form); 844 | SQL::upd_datacount[handle]++; 845 | return 1; 846 | } 847 | 848 | static stock SQL::UpdateStringEntry(handle, const field[], const value[], bool:use_real_escape = true) 849 | { 850 | if(!SQL::IsValidUpdatingSlot(handle)) 851 | { 852 | SQL_Error("(SQL::UpdateStringEntry) Invalid handle. Make sure you used (SQL::OpenTable) first."); 853 | return 0; 854 | } 855 | new MySQL:connectionhandle = SQL::upd_connectionHandle[handle]; 856 | if(SQL::upd_type[handle] != SQL::UPDATE && SQL::upd_type[handle] != SQL::TUPDATE) return 0; 857 | if(use_real_escape == true) 858 | { 859 | new escape[SQL_FORM_LENGTH]; 860 | mysql_escape_string(value, escape); 861 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "`%s`='%s',", field, escape); 862 | } 863 | else 864 | { 865 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "`%s`='%s',", field, value); 866 | } 867 | strcat(SQL::upd_query[handle], SQL::upd_form); 868 | SQL::upd_datacount[handle]++; 869 | return 1; 870 | } 871 | static stock SQL::OpenTable_Insert(const table[], bool:use_autoincrement = false, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 872 | { 873 | if(strlen(table) > SQL_MAX_TABLE_NAME) 874 | { 875 | SQL_Error("(SQL::OpenTable_Insert) Invalid table length."); 876 | return SQL_INVALID_HANDLE; 877 | } 878 | new 879 | i = SQL::GetFreeUpdatingSlot() 880 | ; 881 | if(i == SQL_INVALID_HANDLE) 882 | { 883 | return SQL_INVALID_HANDLE; 884 | } 885 | SQL::upd_type[i] = SQL::INSERT; 886 | strcpy(SQL::upd_table[i], table); 887 | mysql_format(MySQL:connectionhandle, SQL::upd_query[i], SQL_MAX_QUERY_LENGTH, "INSERT INTO `%s` (", SQL::upd_table[i]); 888 | strcpy(SQL::upd_query_2[i], " VALUES ("); 889 | SQL::upd_datacount[i] = 0; 890 | if(use_autoincrement == true) 891 | { 892 | SQL::upd_useautoincrement[i] = true; 893 | } 894 | else 895 | { 896 | SQL::upd_useautoincrement[i] = false; 897 | } 898 | SQL::upd_connectionHandle[i] = MySQL:connectionhandle; 899 | SQL::UsedHandle[i] = true; 900 | return i; 901 | } 902 | 903 | static stock SQL::InsertIntEntry(handle, const field[], value) 904 | { 905 | if(!SQL::IsValidUpdatingSlot(handle)) 906 | { 907 | SQL_Error("(SQL::UpdateIntEntry) Invalid handle. Make sure you used (SQL::OpenTable) first."); 908 | return 0; 909 | } 910 | new MySQL:connectionhandle = SQL::upd_connectionHandle[handle]; 911 | if(SQL::upd_type[handle] != SQL::INSERT) return 0; 912 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "`%s`,", field); 913 | strcat(SQL::upd_query[handle], SQL::upd_form); 914 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "'%i',", value); 915 | strcat(SQL::upd_query_2[handle], SQL::upd_form); 916 | SQL::upd_datacount[handle]++; 917 | return 1; 918 | } 919 | 920 | static stock SQL::InsertFloatEntry(handle, const field[], Float:value) 921 | { 922 | if(!SQL::IsValidUpdatingSlot(handle)) 923 | { 924 | SQL_Error("(SQL::UpdateIntEntry) Invalid handle. Make sure you used (SQL::OpenTable) first."); 925 | return 0; 926 | } 927 | new MySQL:connectionhandle = SQL::upd_connectionHandle[handle]; 928 | if(SQL::upd_type[handle] != SQL::INSERT) return 0; 929 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "`%s`,", field); 930 | strcat(SQL::upd_query[handle], SQL::upd_form); 931 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "'%f',", value); 932 | strcat(SQL::upd_query_2[handle], SQL::upd_form); 933 | SQL::upd_datacount[handle]++; 934 | return 1; 935 | } 936 | 937 | static stock SQL::InsertStringEntry(handle, const field[], const value[], bool:use_real_escape = true) 938 | { 939 | if(!SQL::IsValidUpdatingSlot(handle)) 940 | { 941 | SQL_Error("(SQL::UpdateIntEntry) Invalid handle. Make sure you used (SQL::OpenTable) first."); 942 | return 0; 943 | } 944 | new MySQL:connectionhandle = SQL::upd_connectionHandle[handle]; 945 | if(SQL::upd_type[handle] != SQL::INSERT) return 0; 946 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "`%s`,", field); 947 | strcat(SQL::upd_query[handle], SQL::upd_form); 948 | if(use_real_escape == true) 949 | { 950 | new escape[SQL_FORM_LENGTH]; 951 | mysql_escape_string(value, escape); 952 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "'%s',", escape); 953 | } 954 | else 955 | { 956 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "'%s',", value); 957 | } 958 | strcat(SQL::upd_query_2[handle], SQL::upd_form); 959 | SQL::upd_datacount[handle]++; 960 | return 1; 961 | } 962 | 963 | /*============================================================================== 964 | Actual functions 965 | ================================================================================*/ 966 | 967 | #define SQL_TReadRetrievedRows(%0,%1) if(IsMultiReadHandleValid(%0)) if(cache_num_rows()) for(new %1 = 0; %1 < cache_num_rows(); %1++) 968 | 969 | stock SQL::cache_get_value_name_int(row_idx, const column_where[]) 970 | { 971 | new int = 0; 972 | cache_get_value_name_int(row_idx, column_where, int); 973 | return int; 974 | } 975 | stock Float:SQL::cache_get_value_name_float(row_idx, const column_where[]) 976 | { 977 | new Float:fval = 0; 978 | cache_get_value_name_float(row_idx, column_where, fval); 979 | return fval; 980 | } 981 | stock MySQL:SQL::Connect(const host[], const user[], const password[], const database[], const charset[] = "latin5", debugging = 0, port = 3306, bool:autoreconnect = true, pool_size = 2) 982 | { 983 | switch(debugging) 984 | { 985 | case 0: mysql_log(NONE); 986 | case 1: mysql_log(ALL); 987 | case 2: mysql_log(ERROR); 988 | case 3: mysql_log(WARNING); 989 | case 4: mysql_log(INFO); 990 | case 5: mysql_log(DEBUG); 991 | case 6: mysql_log(ERROR | WARNING); 992 | case 7: mysql_log(ERROR | DEBUG); 993 | case 8: mysql_log(ERROR | INFO); 994 | case 9: mysql_log(WARNING | DEBUG); 995 | case 10: mysql_log(WARNING | INFO); 996 | case 11: mysql_log(INFO | DEBUG); 997 | case 12: mysql_log(ERROR | WARNING | DEBUG); 998 | case 13: mysql_log(ERROR | WARNING | DEBUG | INFO); 999 | case 14: mysql_log(WARNING | DEBUG | INFO); 1000 | } 1001 | new MySQLOpt:options = mysql_init_options(); 1002 | mysql_set_option(options, SERVER_PORT, port); 1003 | mysql_set_option(options, AUTO_RECONNECT, autoreconnect); 1004 | mysql_set_option(options, POOL_SIZE, pool_size); 1005 | new MySQL:SQL::mc = mysql_connect(host, user, password, database, options); 1006 | mysql_set_charset(charset); 1007 | if(mysql_errno(SQL::mc) != 0) 1008 | { 1009 | SQL_Warning("Could not connect to database %s on host %s | user %s and password %s", database, host, user, password); 1010 | } 1011 | else 1012 | { 1013 | SQL_Notice("Successfully connected to database!"); 1014 | } 1015 | return SQL::mc; 1016 | } 1017 | 1018 | stock SQL::Disconnect(MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1019 | { 1020 | return mysql_close(connectionhandle); 1021 | } 1022 | 1023 | stock SQL::Begin(MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1024 | { 1025 | mysql_tquery(MySQL:connectionhandle, "BEGIN", "", ""); 1026 | return 1; 1027 | } 1028 | 1029 | stock SQL::Commit(MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1030 | { 1031 | mysql_tquery(MySQL:connectionhandle, "COMMIT", "", ""); 1032 | return 1; 1033 | } 1034 | 1035 | stock SQL::DeleteRow(const table[], const column_where[] = "", row_identifier = -1, limit = -1, limit2 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1036 | { 1037 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "DELETE FROM `%s` WHERE `%s`='%d'", table, column_where, row_identifier); 1038 | if(limit != -1 && limit2 != -1) 1039 | { 1040 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d, %d", limit, limit2); 1041 | strcat(SQL::upd_form, SQL::upd_form2); 1042 | } 1043 | if(limit != -1 && limit2 == -1) 1044 | { 1045 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d", limit); 1046 | strcat(SQL::upd_form, SQL::upd_form2); 1047 | } 1048 | strcat(SQL::upd_form, " "); 1049 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 1050 | return 1; 1051 | } 1052 | 1053 | stock SQL::DeleteRow2(const table[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", limit = -1, limit2 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1054 | { 1055 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "DELETE FROM `%s` WHERE `%s`='%d'", table, column_where, row_identifier); 1056 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 1057 | { 1058 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier2); 1059 | strcat(SQL::upd_form, SQL::upd_form2); 1060 | } 1061 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 1062 | { 1063 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier3); 1064 | strcat(SQL::upd_form, SQL::upd_form2); 1065 | } 1066 | if(limit != -1 && limit2 != -1) 1067 | { 1068 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d, %d", limit, limit2); 1069 | strcat(SQL::upd_form, SQL::upd_form2); 1070 | } 1071 | if(limit != -1 && limit2 == -1) 1072 | { 1073 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d", limit); 1074 | strcat(SQL::upd_form, SQL::upd_form2); 1075 | } 1076 | strcat(SQL::upd_form, " "); 1077 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 1078 | return 1; 1079 | } 1080 | 1081 | stock SQL::DeleteRow3(const table[], MySQL:connectionhandle, const column_where[] = "", type = 'i', {Float,_}:...) 1082 | { 1083 | switch (type) 1084 | { 1085 | case 'd', 'i': mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "DELETE FROM `%s` WHERE `%s`='%d' ", table, column_where, getarg(4)); 1086 | case 's': 1087 | { 1088 | new i_ArgLoop = -1; 1089 | new i_Extract[128]; 1090 | while (++i_ArgLoop != 0x100) 1091 | { 1092 | if(i_ArgLoop < 128) 1093 | { 1094 | i_Extract[i_ArgLoop] = getarg(4, i_ArgLoop); 1095 | } 1096 | } 1097 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "DELETE FROM `%s` WHERE `%s`='%e' ", table, column_where, i_Extract); 1098 | } 1099 | case 'f': mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "DELETE FROM `%s` WHERE `%s`='%f' ", table, column_where, getarg(4)); 1100 | } 1101 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 1102 | return 1; 1103 | } 1104 | 1105 | stock SQL::Open(SQL::qtypes:type, const table[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", limit = -1, limit2 = -1, const desc[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1106 | { 1107 | new handle; 1108 | switch(type) 1109 | { 1110 | case SQL::CREATE: 1111 | { 1112 | handle = SQL::CreateTable(table, (isnull(column_where)) ? ("InnoDB") : (column_where), (isnull(column_where2)) ? ("latin5") : (column_where2), MySQL:connectionhandle); 1113 | } 1114 | case SQL::READ: 1115 | { 1116 | handle = SQL::OpenTable_Read(table, column_where, row_identifier, MySQL:connectionhandle); 1117 | } 1118 | case SQL::READ2: 1119 | { 1120 | handle = SQL::OpenTable_Read2(table, column_where, row_identifier, column_where2, row_identifier2, row_identifier3, MySQL:connectionhandle); 1121 | } 1122 | case SQL::TREAD: 1123 | { 1124 | handle = SQL::OpenTable_TableRead(table, MySQL:connectionhandle); 1125 | } 1126 | case SQL::INSERT: 1127 | { 1128 | handle = SQL::OpenTable_Insert(table, false, MySQL:connectionhandle); 1129 | } 1130 | case SQL::UPDATE: 1131 | { 1132 | handle = SQL::OpenTable_Update(table, column_where, row_identifier, MySQL:connectionhandle); 1133 | } 1134 | case SQL::UPDATE2: 1135 | { 1136 | handle = SQL::OpenTable_Update2(table, column_where, row_identifier, column_where2, row_identifier2, row_identifier3, MySQL:connectionhandle); 1137 | } 1138 | case SQL::TUPDATE: 1139 | { 1140 | handle = SQL::OpenTable_TableUpdate(table, MySQL:connectionhandle); 1141 | } 1142 | case SQL::MREAD: 1143 | { 1144 | handle = SQL::OpenTable_MultiRead(table, column_where, row_identifier, limit, limit2, desc, MySQL:connectionhandle); 1145 | } 1146 | case SQL::MREAD2: 1147 | { 1148 | handle = SQL::OpenTable_MultiRead2(table, column_where, row_identifier, column_where2, row_identifier2, row_identifier3, limit, limit2, desc, MySQL:connectionhandle); 1149 | } 1150 | case SQL::MTREAD: 1151 | { 1152 | handle = SQL::OpenTable_MultiTableRead(table, MySQL:connectionhandle); 1153 | } 1154 | } 1155 | return handle; 1156 | } 1157 | 1158 | stock SQL::OpenEx(SQL::qtypes:type, const table[], const column_where[] = "", const row_identifier[] = "", const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, limit = -1, limit2 = -1, const desc[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1159 | { 1160 | new handle; 1161 | switch(type) 1162 | { 1163 | case SQL::CREATE: 1164 | { 1165 | handle = SQL::CreateTable(table, (isnull(column_where)) ? ("InnoDB") : (column_where), (isnull(column_where2)) ? ("latin5") : (column_where2), MySQL:connectionhandle); 1166 | } 1167 | case SQL::READ: 1168 | { 1169 | handle = SQL::OpenTable_ReadEx(table, column_where, row_identifier, MySQL:connectionhandle); 1170 | } 1171 | case SQL::READ2: 1172 | { 1173 | handle = SQL::OpenTable_ReadEx2(table, column_where, row_identifier, column_where2, row_identifier2, row_identifier3, MySQL:connectionhandle); 1174 | } 1175 | case SQL::TREAD: 1176 | { 1177 | handle = SQL::OpenTable_TableRead(table, MySQL:connectionhandle); 1178 | } 1179 | case SQL::INSERT: 1180 | { 1181 | handle = SQL::OpenTable_Insert(table, false, MySQL:connectionhandle); 1182 | } 1183 | case SQL::UPDATE: 1184 | { 1185 | handle = SQL::OpenTable_UpdateEx(table, column_where, row_identifier, MySQL:connectionhandle); 1186 | } 1187 | case SQL::UPDATE2: 1188 | { 1189 | handle = SQL::OpenTable_UpdateEx2(table, column_where, row_identifier, column_where2, row_identifier2, row_identifier3, MySQL:connectionhandle); 1190 | } 1191 | case SQL::TUPDATE: 1192 | { 1193 | handle = SQL::OpenTable_TableUpdate(table, MySQL:connectionhandle); 1194 | } 1195 | case SQL::MREAD: 1196 | { 1197 | handle = SQL::OpenTable_MultiReadEx(table, column_where, row_identifier, limit, limit2, desc, MySQL:connectionhandle); 1198 | } 1199 | case SQL::MREAD2: 1200 | { 1201 | handle = SQL::OpenTable_MultiReadEx2(table, column_where, row_identifier, column_where2, row_identifier2, row_identifier3, limit, limit2, desc, MySQL:connectionhandle); 1202 | } 1203 | case SQL::MTREAD: 1204 | { 1205 | handle = SQL::OpenTable_MultiTableRead(table, MySQL:connectionhandle); 1206 | } 1207 | } 1208 | return handle; 1209 | } 1210 | 1211 | stock SQL::ToggleAutoIncrement(handle, bool:toggle) 1212 | { 1213 | if(!SQL::IsValidUpdatingSlot(handle)) return 0; 1214 | if(SQL::upd_type[handle] != SQL::INSERT) return 0; 1215 | SQL::upd_useautoincrement[handle] = toggle; 1216 | return 1; 1217 | } 1218 | 1219 | stock SQL::DeleteRowEx(const table[], const column_where[] = "", const row_identifier[] = "", limit = -1, limit2 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1220 | { 1221 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "DELETE FROM `%s` WHERE `%s`='%e'", table, column_where, row_identifier); 1222 | if(limit != -1 && limit2 != -1) 1223 | { 1224 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d, %d", limit, limit2); 1225 | strcat(SQL::upd_form, SQL::upd_form2); 1226 | } 1227 | if(limit != -1 && limit2 == -1) 1228 | { 1229 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d", limit); 1230 | strcat(SQL::upd_form, SQL::upd_form2); 1231 | } 1232 | strcat(SQL::upd_form, " "); 1233 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 1234 | return 1; 1235 | } 1236 | 1237 | stock SQL::DeleteRowEx2(const table[], const column_where[] = "", const row_identifier[] = "", const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, limit = -1, limit2 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1238 | { 1239 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "DELETE FROM `%s` WHERE `%s`='%e'", table, column_where, row_identifier); 1240 | if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1) 1241 | { 1242 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%e'", column_where2, row_identifier2); 1243 | strcat(SQL::upd_form, SQL::upd_form2); 1244 | } 1245 | if(!isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2)) 1246 | { 1247 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier3); 1248 | strcat(SQL::upd_form, SQL::upd_form2); 1249 | } 1250 | if(limit != -1 && limit2 != -1) 1251 | { 1252 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d, %d", limit, limit2); 1253 | strcat(SQL::upd_form, SQL::upd_form2); 1254 | } 1255 | if(limit != -1 && limit2 == -1) 1256 | { 1257 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " LIMIT %d", limit); 1258 | strcat(SQL::upd_form, SQL::upd_form2); 1259 | } 1260 | strcat(SQL::upd_form, " "); 1261 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 1262 | return 1; 1263 | } 1264 | 1265 | stock SQL::GetIntEntry(const table[], const field[], const column_where[] = "", row_identifier = -1, const column_whereo[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1266 | { 1267 | new Cache:result, int = 0, count; 1268 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%d' ", field, table, column_where, column_whereo, row_identifier); 1269 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1270 | if(mysql_errno() != 0) 1271 | { 1272 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1273 | } 1274 | if(result) 1275 | { 1276 | cache_get_row_count(count); 1277 | if(count) cache_get_value_name_int(0, field, int); 1278 | cache_delete(result); 1279 | } 1280 | return int; 1281 | } 1282 | 1283 | stock SQL::GetIntEntry2(const table[], const field[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", const column_whereo[] = "=", const column_whereo2[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1284 | { 1285 | new Cache:result, int = 0, count; 1286 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%d'", field, table, column_where, column_whereo, row_identifier); 1287 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 1288 | { 1289 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%d'", column_where2, column_whereo2, row_identifier2); 1290 | strcat(SQL::upd_form, SQL::upd_form2); 1291 | } 1292 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 1293 | { 1294 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%s'", column_where2, column_whereo2, row_identifier3); 1295 | strcat(SQL::upd_form, SQL::upd_form2); 1296 | } 1297 | strcat(SQL::upd_form, " "); 1298 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1299 | if(mysql_errno() != 0) 1300 | { 1301 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1302 | } 1303 | if(result) 1304 | { 1305 | cache_get_row_count(count); 1306 | if(count) cache_get_value_name_int(0, field, int); 1307 | cache_delete(result); 1308 | } 1309 | return int; 1310 | } 1311 | 1312 | stock Float:SQL::GetFloatEntry(const table[], const field[], const column_where[] = "", row_identifier = -1, const column_whereo[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1313 | { 1314 | new 1315 | Cache:result, 1316 | Float:int, 1317 | count 1318 | ; 1319 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%d' ", field, table, column_where, column_whereo, row_identifier); 1320 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1321 | if(mysql_errno() != 0) 1322 | { 1323 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1324 | } 1325 | if(result) 1326 | { 1327 | cache_get_row_count(count); 1328 | if(count) 1329 | { 1330 | cache_get_value_name_float(0, field, int); 1331 | } 1332 | else 1333 | { 1334 | int = 0.0; 1335 | } 1336 | cache_delete(result); 1337 | } 1338 | return int; 1339 | } 1340 | 1341 | stock Float:SQL::GetFloatEntry2(const table[], const field[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", const column_whereo[] = "=", const column_whereo2[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1342 | { 1343 | new 1344 | Cache:result, 1345 | Float:int, 1346 | count 1347 | ; 1348 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%d'", field, table, column_where, column_whereo, row_identifier); 1349 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 1350 | { 1351 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%d'", column_where2, column_whereo2, row_identifier2); 1352 | strcat(SQL::upd_form, SQL::upd_form2); 1353 | } 1354 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 1355 | { 1356 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%s'", column_where2, column_whereo2, row_identifier3); 1357 | strcat(SQL::upd_form, SQL::upd_form2); 1358 | } 1359 | strcat(SQL::upd_form, " "); 1360 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1361 | if(mysql_errno() != 0) 1362 | { 1363 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1364 | } 1365 | if(result) 1366 | { 1367 | cache_get_row_count(count); 1368 | if(count) 1369 | { 1370 | cache_get_value_name_float(0, field, int); 1371 | } 1372 | else 1373 | { 1374 | int = 0.0; 1375 | } 1376 | cache_delete(result); 1377 | } 1378 | return int; 1379 | } 1380 | 1381 | stock SQL::t_GetStringEntry(const table[], const field[], const column_where[] = "", row_identifier = -1, const column_whereo[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1382 | { 1383 | new Cache:result, count; 1384 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%d' ", field, table, column_where, column_whereo, row_identifier); 1385 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1386 | if(mysql_errno() != 0) 1387 | { 1388 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1389 | } 1390 | SQL::upd_form[0] = EOS; 1391 | if(result) 1392 | { 1393 | cache_get_row_count(count); 1394 | if(count == 1) 1395 | { 1396 | cache_get_value_name(0, field, SQL::upd_form, sizeof(SQL::upd_form)); 1397 | cache_delete(result); 1398 | } 1399 | else 1400 | { 1401 | cache_delete(result); 1402 | return SQL::upd_form; 1403 | } 1404 | } 1405 | return SQL::upd_form; 1406 | } 1407 | 1408 | stock SQL::t_GetStringEntry2(const table[], const field[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", const column_whereo[] = "=", const column_whereo2[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1409 | { 1410 | new Cache:result, count; 1411 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%d' ", field, table, column_where, column_whereo, row_identifier); 1412 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1413 | if(mysql_errno() != 0) 1414 | { 1415 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1416 | } 1417 | SQL::upd_form[0] = EOS; 1418 | if(result) 1419 | { 1420 | cache_get_row_count(count); 1421 | if(count == 1) 1422 | { 1423 | cache_get_value_name(0, field, SQL::upd_form, sizeof(SQL::upd_form)); 1424 | cache_delete(result); 1425 | } 1426 | else 1427 | { 1428 | cache_delete(result); 1429 | return SQL::upd_form; 1430 | } 1431 | } 1432 | return SQL::upd_form; 1433 | } 1434 | 1435 | stock SQL::GetStringEntry(const table[], const field[], const column_where[] = "", row_identifier = -1, dest[], len = sizeof(dest), const column_whereo[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1436 | { 1437 | new Cache:result, count; 1438 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%d' ", field, table, column_where, column_whereo, row_identifier); 1439 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1440 | if(mysql_errno() != 0) 1441 | { 1442 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1443 | } 1444 | if(result) 1445 | { 1446 | cache_get_row_count(count); 1447 | if(count == 1) 1448 | { 1449 | cache_get_value_name(0, field, SQL::upd_form, sizeof(SQL::upd_form)); 1450 | strcpy(dest, SQL::upd_form, len); 1451 | cache_delete(result); 1452 | } 1453 | else 1454 | { 1455 | cache_delete(result); 1456 | return 0; 1457 | } 1458 | } 1459 | return 1; 1460 | } 1461 | 1462 | stock SQL::GetStringEntry2(const table[], const field[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", dest[], len = sizeof(dest), const column_whereo[] = "=", const column_whereo2[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1463 | { 1464 | new Cache:result, count; 1465 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%d'", field, table, column_where, column_whereo, row_identifier); 1466 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 1467 | { 1468 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%d'", column_where2, column_whereo2, row_identifier2); 1469 | strcat(SQL::upd_form, SQL::upd_form2); 1470 | } 1471 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 1472 | { 1473 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%s'", column_where2, column_whereo2, row_identifier3); 1474 | strcat(SQL::upd_form, SQL::upd_form2); 1475 | } 1476 | strcat(SQL::upd_form, " "); 1477 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1478 | if(mysql_errno() != 0) 1479 | { 1480 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1481 | } 1482 | if(result) 1483 | { 1484 | cache_get_row_count(count); 1485 | if(count == 1) 1486 | { 1487 | cache_get_value_name(0, field, SQL::upd_form, sizeof(SQL::upd_form)); 1488 | strcpy(dest, SQL::upd_form, len); 1489 | cache_delete(result); 1490 | } 1491 | else 1492 | { 1493 | cache_delete(result); 1494 | return 0; 1495 | } 1496 | } 1497 | return 1; 1498 | } 1499 | 1500 | stock SQL::GetStringEntryEx(const table[], const field[], const column_where[] = "", const scolumn_where[] = "", dest[], len = sizeof(dest), const column_whereo[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1501 | { 1502 | new Cache:result, count; 1503 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%e' ", field, table, column_where, column_whereo, scolumn_where); 1504 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1505 | if(mysql_errno() != 0) 1506 | { 1507 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1508 | } 1509 | if(result) 1510 | { 1511 | cache_get_row_count(count); 1512 | if(count == 1) 1513 | { 1514 | cache_get_value_name(0, field, SQL::upd_form, sizeof(SQL::upd_form)); 1515 | strcpy(dest, SQL::upd_form, len); 1516 | cache_delete(result); 1517 | } 1518 | else 1519 | { 1520 | cache_delete(result); 1521 | return 0; 1522 | } 1523 | } 1524 | return 1; 1525 | } 1526 | 1527 | stock SQL::GetStringEntryEx2(const table[], const field[], const column_where[] = "", const scolumn_where[] = "", const column_where2[] = "", const scolumn_where2[] = "", scolumn_where3 = -1, dest[], len = sizeof(dest), const column_whereo[] = "=", const column_whereo2[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1528 | { 1529 | new Cache:result, count; 1530 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%e'", field, table, column_where, column_whereo, scolumn_where); 1531 | if(!isnull(column_where2) && !isnull(scolumn_where2) && scolumn_where3 == -1) 1532 | { 1533 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%e'", column_where2, column_whereo2, scolumn_where2); 1534 | strcat(SQL::upd_form, SQL::upd_form2); 1535 | } 1536 | if(!isnull(column_where2) && scolumn_where3 != -1 && isnull(scolumn_where2)) 1537 | { 1538 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%d'", column_where2, column_whereo2, scolumn_where3); 1539 | strcat(SQL::upd_form, SQL::upd_form2); 1540 | } 1541 | strcat(SQL::upd_form, " "); 1542 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1543 | if(mysql_errno() != 0) 1544 | { 1545 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1546 | } 1547 | if(result) 1548 | { 1549 | cache_get_row_count(count); 1550 | if(count == 1) 1551 | { 1552 | cache_get_value_name(0, field, SQL::upd_form, sizeof(SQL::upd_form)); 1553 | strcpy(dest, SQL::upd_form, len); 1554 | cache_delete(result); 1555 | } 1556 | else 1557 | { 1558 | cache_delete(result); 1559 | return 0; 1560 | } 1561 | } 1562 | return 1; 1563 | } 1564 | 1565 | stock SQL::t_GetStringEntryEx(const table[], const field[], const column_where[] = "", const scolumn_where[] = "", const column_whereo[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1566 | { 1567 | new Cache:result, count; 1568 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%e' ", field, table, column_where, column_whereo, scolumn_where); 1569 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1570 | if(mysql_errno() != 0) 1571 | { 1572 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1573 | } 1574 | SQL::upd_form[0] = EOS; 1575 | if(result) 1576 | { 1577 | cache_get_row_count(count); 1578 | if(count == 1) 1579 | { 1580 | cache_get_value_name(0, field, SQL::upd_form, sizeof(SQL::upd_form)); 1581 | cache_delete(result); 1582 | } 1583 | else 1584 | { 1585 | cache_delete(result); 1586 | return SQL::upd_form,; 1587 | } 1588 | } 1589 | return SQL::upd_form,; 1590 | } 1591 | 1592 | stock SQL::t_GetStringEntryEx2(const table[], const field[], const column_where[] = "", const scolumn_where[] = "", const column_where2[] = "", const scolumn_where2[] = "", scolumn_where3 = -1, const column_whereo[] = "=", const column_whereo2[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1593 | { 1594 | new Cache:result, count; 1595 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%e'", field, table, column_where, column_whereo, scolumn_where); 1596 | if(!isnull(column_where2) && !isnull(scolumn_where2) && scolumn_where3 == -1) 1597 | { 1598 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%e'", column_where2, column_whereo2, scolumn_where2); 1599 | strcat(SQL::upd_form, SQL::upd_form2); 1600 | } 1601 | if(!isnull(column_where2) && scolumn_where3 != -1 && isnull(scolumn_where2)) 1602 | { 1603 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%d'", column_where2, column_whereo2, scolumn_where3); 1604 | strcat(SQL::upd_form, SQL::upd_form2); 1605 | } 1606 | strcat(SQL::upd_form, " "); 1607 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1608 | if(mysql_errno() != 0) 1609 | { 1610 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1611 | } 1612 | SQL::upd_form[0] = EOS; 1613 | if(result) 1614 | { 1615 | cache_get_row_count(count); 1616 | if(count == 1) 1617 | { 1618 | cache_get_value_name(0, field, SQL::upd_form, sizeof(SQL::upd_form)); 1619 | cache_delete(result); 1620 | } 1621 | else 1622 | { 1623 | cache_delete(result); 1624 | return SQL::upd_form,; 1625 | } 1626 | } 1627 | return SQL::upd_form,; 1628 | } 1629 | 1630 | stock SQL::GetIntEntryEx(const table[], const field[], const column_where[] = "", scolumn_where[] = "", const column_whereo[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1631 | { 1632 | new Cache:result, int, count; 1633 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%e' ", field, table, column_where, column_whereo, scolumn_where); 1634 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1635 | if(mysql_errno() != 0) 1636 | { 1637 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1638 | } 1639 | if(result) 1640 | { 1641 | cache_get_row_count(count); 1642 | if(count == 1) 1643 | { 1644 | cache_get_value_name_int(0, field, int); 1645 | } 1646 | else 1647 | { 1648 | int = -1; 1649 | } 1650 | cache_delete(result); 1651 | } 1652 | return int; 1653 | } 1654 | 1655 | stock SQL::GetIntEntryEx2(const table[], const field[], const column_where[] = "", scolumn_where[] = "", const column_where2[] = "", scolumn_where2[] = "", scolumn_where3 = -1, const column_whereo[] = "=", const column_whereo2[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1656 | { 1657 | new Cache:result, int, count; 1658 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%e'", field, table, column_where, column_whereo, scolumn_where); 1659 | if(!isnull(column_where2) && !isnull(scolumn_where2) && scolumn_where3 == -1) 1660 | { 1661 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%e'", column_where2, column_whereo2, scolumn_where2); 1662 | strcat(SQL::upd_form, SQL::upd_form2); 1663 | } 1664 | if(!isnull(column_where2) && scolumn_where3 != -1 && isnull(scolumn_where2)) 1665 | { 1666 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%d'", column_where2, column_whereo2, scolumn_where3); 1667 | strcat(SQL::upd_form, SQL::upd_form2); 1668 | } 1669 | strcat(SQL::upd_form, " "); 1670 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1671 | if(mysql_errno() != 0) 1672 | { 1673 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1674 | } 1675 | if(result) 1676 | { 1677 | cache_get_row_count(count); 1678 | if(count == 1) 1679 | { 1680 | cache_get_value_name_int(0, field, int); 1681 | } 1682 | else 1683 | { 1684 | int = -1; 1685 | } 1686 | cache_delete(result); 1687 | } 1688 | return int; 1689 | } 1690 | 1691 | stock Float:SQL::GetFloatEntryEx(const table[], const field[], const column_where[] = "", scolumn_where[] = "", const column_whereo[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1692 | { 1693 | new Cache:result, Float:int, count; 1694 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%e' ", field, table, column_where, column_whereo, scolumn_where); 1695 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1696 | if(mysql_errno() != 0) 1697 | { 1698 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1699 | } 1700 | if(result) 1701 | { 1702 | cache_get_row_count(count); 1703 | if(count == 1) 1704 | { 1705 | cache_get_value_name_float(0, field, int); 1706 | } 1707 | else 1708 | { 1709 | int = -1.0; 1710 | } 1711 | cache_delete(result); 1712 | } 1713 | return int; 1714 | } 1715 | 1716 | stock Float:SQL::GetFloatEntryEx2(const table[], const field[], const column_where[] = "", scolumn_where[] = "", const column_where2[] = "", scolumn_where2[] = "", scolumn_where3 = -1, const column_whereo[] = "=", const column_whereo2[] = "=", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 1717 | { 1718 | new Cache:result, Float:int, count; 1719 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "SELECT `%s` FROM `%s` WHERE `%s`%s'%e'", field, table, column_where, column_whereo, scolumn_where); 1720 | if(!isnull(column_where2) && !isnull(scolumn_where2) && scolumn_where3 == -1) 1721 | { 1722 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%e'", column_where2, column_whereo2, scolumn_where2); 1723 | strcat(SQL::upd_form, SQL::upd_form2); 1724 | } 1725 | if(!isnull(column_where2) && scolumn_where3 != -1 && isnull(scolumn_where2)) 1726 | { 1727 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`%s'%d'", column_where2, column_whereo2, scolumn_where3); 1728 | strcat(SQL::upd_form, SQL::upd_form2); 1729 | } 1730 | strcat(SQL::upd_form, " "); 1731 | result = mysql_query(MySQL:connectionhandle, SQL::upd_form); 1732 | if(mysql_errno() != 0) 1733 | { 1734 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_form); 1735 | } 1736 | if(result) 1737 | { 1738 | cache_get_row_count(count); 1739 | if(count == 1) 1740 | { 1741 | cache_get_value_name_int(0, field, int); 1742 | } 1743 | else 1744 | { 1745 | int = -1.0; 1746 | } 1747 | cache_delete(result); 1748 | } 1749 | return int; 1750 | } 1751 | 1752 | stock SQL::AddTableColumn(handle, const field_name[], SQL::datatypes: type = SQL_TYPE_INT, maxlength = 11, bool:null = false, bool:auto_increment = false, bool:setprimary = false, bool:setindex = false) 1753 | { 1754 | if(!SQL::IsValidUpdatingSlot(handle)) 1755 | { 1756 | SQL_Error("(SQL::AddTableColumn) Invalid handle. Make sure you used (SQL::Open) first."); 1757 | return 0; 1758 | } 1759 | new MySQL:connectionhandle = SQL::upd_connectionHandle[handle]; 1760 | if(SQL::upd_type[handle] != SQL::CREATE) return 0; 1761 | if(SQL::isset_primarykey[handle] && setprimary == true) 1762 | { 1763 | SQL_Error("(SQL::AddTableColumn) A primary column_where was created already. There can only be one primary column_where! [Key %s]", field_name); 1764 | return 0; 1765 | } 1766 | if(auto_increment == true && type == SQL_TYPE_VCHAR) 1767 | { 1768 | SQL_Error("(SQL::AddTableColumn) You can't set auto increment if the type is varchar! [Key %s]", field_name); 1769 | return 0; 1770 | } 1771 | switch(type) 1772 | { 1773 | case SQL_TYPE_INT: 1774 | { 1775 | if(auto_increment == true && setprimary == false) 1776 | { 1777 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "%s int %s AUTO_INCREMENT,", field_name, (null == false) ? ("NOT NULL") : ("NULL")); 1778 | strcat(SQL::upd_query[handle], SQL::upd_form); 1779 | SQL::upd_datacount[handle]++; 1780 | SQL::isset_primarykey[handle] = 1; 1781 | strcpy(SQL::primarykey[handle], field_name); 1782 | } 1783 | else if(auto_increment == true && setprimary == true) 1784 | { 1785 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "%s int %s PRIMARY KEY AUTO_INCREMENT,", field_name, (null == false) ? ("NOT NULL") : ("NULL")); 1786 | strcat(SQL::upd_query[handle], SQL::upd_form); 1787 | SQL::upd_datacount[handle]++; 1788 | SQL::isset_primarykey[handle] = 1; 1789 | strcpy(SQL::primarykey[handle], field_name); 1790 | } 1791 | else if(setprimary == true) 1792 | { 1793 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "%s int %s PRIMARY KEY,", field_name, (null == false) ? ("NOT NULL") : ("NULL")); 1794 | strcat(SQL::upd_query[handle], SQL::upd_form); 1795 | SQL::upd_datacount[handle]++; 1796 | SQL::isset_primarykey[handle] = 2; 1797 | strcpy(SQL::primarykey[handle], field_name); 1798 | } 1799 | else 1800 | { 1801 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "%s int(%d) %s,", field_name, maxlength, (null == false) ? ("NOT NULL") : ("NULL")); 1802 | strcat(SQL::upd_query[handle], SQL::upd_form); 1803 | SQL::upd_datacount[handle]++; 1804 | } 1805 | } 1806 | case SQL_TYPE_VCHAR: 1807 | { 1808 | if(auto_increment == true) return 0; 1809 | if(setprimary == true) 1810 | { 1811 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "%s varchar(%d) %s PRIMARY KEY,", field_name, maxlength, (null == false) ? ("NOT NULL") : ("NULL")); 1812 | strcat(SQL::upd_query[handle], SQL::upd_form); 1813 | SQL::upd_datacount[handle]++; 1814 | SQL::isset_primarykey[handle] = 2; 1815 | strcpy(SQL::primarykey[handle], field_name); 1816 | } 1817 | else 1818 | { 1819 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "%s varchar(%d) %s,", field_name, maxlength, (null == false) ? ("NOT NULL") : ("NULL")); 1820 | strcat(SQL::upd_query[handle], SQL::upd_form); 1821 | SQL::upd_datacount[handle]++; 1822 | 1823 | } 1824 | } 1825 | case SQL_TYPE_FLOAT: 1826 | { 1827 | if(auto_increment == true) return 0; 1828 | if(setprimary == true) 1829 | { 1830 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "%s float(%d) %s PRIMARY KEY,", field_name, maxlength, (null == false) ? ("NOT NULL") : ("NULL")); 1831 | strcat(SQL::upd_query[handle], SQL::upd_form); 1832 | SQL::upd_datacount[handle]++; 1833 | SQL::isset_primarykey[handle] = 2; 1834 | strcpy(SQL::primarykey[handle], field_name); 1835 | } 1836 | else 1837 | { 1838 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "%s float(%d) %s,", field_name, maxlength, (null == false) ? ("NOT NULL") : ("NULL")); 1839 | strcat(SQL::upd_query[handle], SQL::upd_form); 1840 | SQL::upd_datacount[handle]++; 1841 | } 1842 | } 1843 | } 1844 | if(setindex == true) 1845 | { 1846 | new indexslot = SQL::GetFreeIndexSlot(handle); 1847 | if(indexslot == SQL_INVALID_HANDLE) return SQL_Error("(SQL::AddTableColumn) Indexes limit reached. Increase the limit in MAX_INDEXES"); 1848 | SQL::index_set[handle][indexslot] = 1; 1849 | strcpy(SQL::index[handle][indexslot], field_name); 1850 | } 1851 | return 1; 1852 | } 1853 | 1854 | stock SQL::ReadInt(handle, const field[], &dest, row = 0) 1855 | { 1856 | if(!SQL::IsValidUpdatingSlot(handle)) 1857 | { 1858 | SQL_Error("(SQL::ReadInt) Invalid handle. Make sure you opened the table first."); 1859 | return 0; 1860 | } 1861 | if(SQL::upd_type[handle] == SQL::READ) 1862 | { 1863 | cache_get_value_name_int(0, field, dest); 1864 | SQL::upd_datacount[handle]++; 1865 | } 1866 | else if(SQL::upd_type[handle] == SQL::CALLBACK) 1867 | { 1868 | cache_get_value_name_int(row, field, dest); 1869 | SQL::upd_datacount[handle]++; 1870 | } 1871 | else return 0; 1872 | return 1; 1873 | } 1874 | 1875 | stock SQL::ReadFloat(handle, const field[], &Float:dest, row = 0) 1876 | { 1877 | if(!SQL::IsValidUpdatingSlot(handle)) 1878 | { 1879 | SQL_Error("(SQL::ReadInt) Invalid handle. Make sure you opened the table first."); 1880 | return 0; 1881 | } 1882 | if(SQL::upd_type[handle] == SQL::READ) 1883 | { 1884 | cache_get_value_name_float(0, field, dest); 1885 | SQL::upd_datacount[handle]++; 1886 | } 1887 | else if(SQL::upd_type[handle] == SQL::CALLBACK) 1888 | { 1889 | cache_get_value_name_float(row, field, dest); 1890 | SQL::upd_datacount[handle]++; 1891 | } 1892 | else return 0; 1893 | return 1; 1894 | } 1895 | 1896 | stock SQL::ReadString(handle, const field[], dest[], len = sizeof(dest), row = 0) 1897 | { 1898 | if(!SQL::IsValidUpdatingSlot(handle)) 1899 | { 1900 | SQL_Error("(SQL::ReadInt) Invalid handle. Make sure you opened the table first."); 1901 | return 0; 1902 | } 1903 | if(SQL::upd_type[handle] == SQL::READ) 1904 | { 1905 | cache_get_value_name(0, field, dest, len+1); 1906 | SQL::upd_datacount[handle]++; 1907 | } 1908 | else if(SQL::upd_type[handle] == SQL::CALLBACK) 1909 | { 1910 | cache_get_value_name(row, field, dest, len+1); 1911 | SQL::upd_datacount[handle]++; 1912 | } 1913 | else return 0; 1914 | return 1; 1915 | } 1916 | 1917 | 1918 | stock SQL::UpdateIntEntry(handle, const field[], value) 1919 | { 1920 | if(!SQL::IsValidUpdatingSlot(handle)) 1921 | { 1922 | SQL_Error("(SQL::UpdateIntEntry) Invalid handle. Make sure you used (SQL::OpenTable) first."); 1923 | return 0; 1924 | } 1925 | new MySQL:connectionhandle = SQL::upd_connectionHandle[handle]; 1926 | if(SQL::upd_type[handle] != SQL::UPDATE && SQL::upd_type[handle] != SQL::TUPDATE) return 0; 1927 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "`%s`='%i',", field, value); 1928 | strcat(SQL::upd_query[handle], SQL::upd_form); 1929 | SQL::upd_datacount[handle]++; 1930 | return 1; 1931 | } 1932 | 1933 | stock SQL::WriteInt(handle, const field[], value) 1934 | { 1935 | if(!SQL::IsValidUpdatingSlot(handle)) 1936 | { 1937 | SQL_Error("(SQL::WriteInt) Invalid handle. Make sure you used (SQL::Open) first."); 1938 | return 0; 1939 | } 1940 | switch(SQL::upd_type[handle]) 1941 | { 1942 | case SQL::UPDATE: 1943 | { 1944 | return SQL::UpdateIntEntry(handle, field, value); 1945 | } 1946 | case SQL::TUPDATE: 1947 | { 1948 | return SQL::UpdateIntEntry(handle, field, value); 1949 | } 1950 | case SQL::INSERT: 1951 | { 1952 | return SQL::InsertIntEntry(handle, field, value); 1953 | } 1954 | } 1955 | return 0; 1956 | } 1957 | 1958 | stock SQL::WriteFloat(handle, const field[], Float:value) 1959 | { 1960 | if(!SQL::IsValidUpdatingSlot(handle)) 1961 | { 1962 | SQL_Error("(SQL::WriteFloat) Invalid handle. Make sure you used (SQL::Open) first."); 1963 | return 0; 1964 | } 1965 | switch(SQL::upd_type[handle]) 1966 | { 1967 | case SQL::UPDATE: 1968 | { 1969 | return SQL::UpdateFloatEntry(handle, field, value); 1970 | } 1971 | case SQL::TUPDATE: 1972 | { 1973 | return SQL::UpdateFloatEntry(handle, field, value); 1974 | } 1975 | case SQL::INSERT: 1976 | { 1977 | return SQL::InsertFloatEntry(handle, field, value); 1978 | } 1979 | } 1980 | return 0; 1981 | } 1982 | 1983 | stock SQL::WriteString(handle, const field[], const value[], bool: use_real_escape = true) 1984 | { 1985 | if(!SQL::IsValidUpdatingSlot(handle)) 1986 | { 1987 | SQL_Error("(SQL::WriteFloat) Invalid handle. Make sure you used (SQL::Open) first."); 1988 | return 0; 1989 | } 1990 | switch(SQL::upd_type[handle]) 1991 | { 1992 | case SQL::UPDATE: 1993 | { 1994 | return SQL::UpdateStringEntry(handle, field, value, use_real_escape); 1995 | } 1996 | case SQL::TUPDATE: 1997 | { 1998 | return SQL::UpdateStringEntry(handle, field, value, use_real_escape); 1999 | } 2000 | case SQL::INSERT: 2001 | { 2002 | return SQL::InsertStringEntry(handle, field, value, use_real_escape); 2003 | } 2004 | } 2005 | return 0; 2006 | } 2007 | 2008 | 2009 | stock SQL::Close(handle) 2010 | { 2011 | if(!SQL::IsValidUpdatingSlot(handle)) 2012 | { 2013 | SQL_Error("(SQL::Close) Invalid handle. Make sure you opened a handle first."); 2014 | return 0; 2015 | } 2016 | new MySQL:connectionhandle = SQL::upd_connectionHandle[handle]; 2017 | if(SQL::upd_type[handle] == SQL::UPDATE) 2018 | { 2019 | if(!SQL::upd_datacount[handle]) 2020 | { 2021 | SQL_Error("%s", SQL::upd_query[handle]); 2022 | SQL_Error("(SQL::Close) No data has been updated."); 2023 | SQL::UsedHandle[handle] = false; 2024 | return 0; 2025 | } 2026 | //Remove last comma 2027 | new pos = strlen(SQL::upd_query[handle])-1; 2028 | SQL::upd_query[handle][pos] = ' '; 2029 | strcat(SQL::upd_query[handle], SQL::upd_rowidentifier[handle]); 2030 | 2031 | mysql_tquery(MySQL:connectionhandle, SQL::upd_query[handle], "", ""); 2032 | SQL::upd_table[handle][0] = '\0'; 2033 | SQL::upd_query[handle][0] = '\0'; 2034 | SQL::upd_rowidentifier[handle][0] = '\0'; 2035 | SQL::upd_datacount[handle] = 0; 2036 | SQL::UsedHandle[handle] = false; 2037 | } 2038 | else if(SQL::upd_type[handle] == SQL::TUPDATE) 2039 | { 2040 | //Remove last comma 2041 | new pos = strlen(SQL::upd_query[handle])-1; 2042 | SQL::upd_query[handle][pos] = ' '; 2043 | 2044 | mysql_tquery(MySQL:connectionhandle, SQL::upd_query[handle], "", ""); 2045 | SQL::upd_table[handle][0] = '\0'; 2046 | SQL::upd_query[handle][0] = '\0'; 2047 | SQL::upd_datacount[handle] = 0; 2048 | SQL::UsedHandle[handle] = false; 2049 | } 2050 | else if(SQL::upd_type[handle] == SQL::CREATE) 2051 | { 2052 | if(!SQL::upd_datacount[handle]) 2053 | { 2054 | SQL_Error("%s", SQL::upd_query[handle]); 2055 | SQL_Error("(SQL::Close) No data has been added.."); 2056 | SQL::UsedHandle[handle] = false; 2057 | return 0; 2058 | } 2059 | new pos = strlen(SQL::upd_query[handle])-1; 2060 | SQL::upd_query[handle][pos] = ' '; 2061 | for(new i = 0; i != SQL_MAX_INDEXES; i++) 2062 | { 2063 | if(SQL::index_set[handle][i]) 2064 | { 2065 | mysql_format(MySQL:connectionhandle, SQL::upd_form, 128, ",INDEX (`%s`)", SQL::index[handle][i]); 2066 | strcat(SQL::upd_query[handle], SQL::upd_form); 2067 | SQL::index_set[handle][i] = 0; 2068 | SQL::index[handle][i][0] = EOS; 2069 | } 2070 | } 2071 | if(SQL::isset_primarykey[handle] == 1) 2072 | { 2073 | mysql_format(MySQL:connectionhandle, SQL::upd_form, 128, ",primary key (%s)", SQL::primarykey[handle]); 2074 | strcat(SQL::upd_query[handle], SQL::upd_form); 2075 | } 2076 | mysql_format(MySQL:connectionhandle, SQL::upd_form, 128, ") ENGINE=%s DEFAULT CHARSET=%s;", SQL::engine[handle], SQL::charset[handle]); 2077 | strcat(SQL::upd_query[handle], SQL::upd_form); 2078 | mysql_tquery(MySQL:connectionhandle, SQL::upd_query[handle], "", ""); 2079 | SQL::upd_table[handle][0] = '\0'; 2080 | //SQL::upd_connectionHandle[handle] = MYSQL_INVALID_HANDLE; 2081 | SQL::primarykey[handle][0] = '\0'; 2082 | SQL::engine[handle][0] = '\0'; 2083 | SQL::charset[handle][0] = '\0'; 2084 | SQL::isset_primarykey[handle] = false; 2085 | SQL::upd_query[handle][0] = '\0'; 2086 | SQL::upd_rowidentifier[handle][0] = '\0'; 2087 | SQL::upd_datacount[handle] = 0; 2088 | SQL::UsedHandle[handle] = false; 2089 | 2090 | 2091 | } 2092 | else if(SQL::upd_type[handle] == SQL::INSERT) 2093 | { 2094 | if(!SQL::upd_datacount[handle]) 2095 | { 2096 | SQL_Error("%s", SQL::upd_query[handle]); 2097 | SQL_Error("(SQL::Close) No data has been inserted.."); 2098 | SQL::UsedHandle[handle] = false; 2099 | return 0; 2100 | } 2101 | new pos = strlen(SQL::upd_query[handle])-1; 2102 | SQL::upd_query[handle][pos] = ')'; 2103 | pos = strlen(SQL::upd_query_2[handle])-1; 2104 | SQL::upd_query_2[handle][pos] = ' '; 2105 | strcat(SQL::upd_query_2[handle], ");"); 2106 | strcat(SQL::upd_query[handle], SQL::upd_query_2[handle]); 2107 | SQL::upd_table[handle][0] = '\0'; 2108 | SQL::upd_query_2[handle][0] = '\0'; 2109 | SQL::upd_rowidentifier[handle][0] = '\0'; 2110 | SQL::upd_datacount[handle] = 0; 2111 | if(SQL::upd_useautoincrement[handle] == true) 2112 | { 2113 | new Cache:result; 2114 | result = mysql_query(MySQL:connectionhandle, SQL::upd_query[handle]); 2115 | if(mysql_errno() != 0) 2116 | { 2117 | return SQL_Warning("Query could not be completed due to error: %s", SQL::upd_query[handle]); 2118 | } 2119 | if(result) 2120 | { 2121 | new id = cache_insert_id(); 2122 | cache_delete(result); 2123 | SQL::upd_query[handle][0] = '\0'; 2124 | SQL::UsedHandle[handle] = false; 2125 | return id; 2126 | } 2127 | } 2128 | else 2129 | { 2130 | mysql_tquery(MySQL:connectionhandle, SQL::upd_query[handle], "", ""); 2131 | SQL::UsedHandle[handle] = false; 2132 | } 2133 | } 2134 | else if(SQL::upd_type[handle] == SQL::READ) 2135 | { 2136 | if(!SQL::upd_datacount[handle]) 2137 | { 2138 | SQL_Error("%s", SQL::upd_query[handle]); 2139 | SQL_Error("(SQL::Close) No data has been read.."); 2140 | SQL::UsedHandle[handle] = false; 2141 | return 0; 2142 | } 2143 | if(cache_is_valid(SQL::ReadCache[handle])) 2144 | { 2145 | cache_delete(SQL::ReadCache[handle]); 2146 | } 2147 | SQL::UsedHandle[handle] = false; 2148 | } 2149 | else if(SQL::upd_type[handle] == SQL::CALLBACK) 2150 | { 2151 | new count; 2152 | cache_get_row_count(count); 2153 | if(cache_is_valid(SQL::ReadCache[handle])) 2154 | { 2155 | cache_delete(SQL::ReadCache[handle]); 2156 | } 2157 | SQL::UsedHandle[handle] = false; 2158 | return count; 2159 | } 2160 | return -1; 2161 | } 2162 | 2163 | stock SQL::SetIntEntry(const table[], const field[], value, const column_where[] = "", row_identifier = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2164 | { 2165 | if(!table[0]) return 0; 2166 | if(!field[0]) return 0; 2167 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%d' WHERE `%s`='%d' ", table, field, value, column_where, row_identifier); 2168 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2169 | return 1; 2170 | } 2171 | 2172 | stock SQL::SetIntEntry2(const table[], const field[], value, const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2173 | { 2174 | if(!table[0]) return 0; 2175 | if(!field[0]) return 0; 2176 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%d' WHERE `%s`='%d'", table, field, value, column_where, row_identifier); 2177 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 2178 | { 2179 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier2); 2180 | strcat(SQL::upd_form, SQL::upd_form2); 2181 | } 2182 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 2183 | { 2184 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier3); 2185 | strcat(SQL::upd_form, SQL::upd_form2); 2186 | } 2187 | strcat(SQL::upd_form, " "); 2188 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2189 | return 1; 2190 | } 2191 | 2192 | stock SQL::SetIntEntryEx(const table[], const field[], value, const column_where[] = "", const row_identifier[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2193 | { 2194 | if(!table[0]) return 0; 2195 | if(!field[0]) return 0; 2196 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%d' WHERE `%s`='%e' ", table, field, value, column_where, row_identifier); 2197 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2198 | return 1; 2199 | } 2200 | 2201 | stock SQL::SetIntEntryEx2(const table[], const field[], value, const column_where[] = "", const row_identifier[] = "", const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2202 | { 2203 | if(!table[0]) return 0; 2204 | if(!field[0]) return 0; 2205 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%d' WHERE `%s`='%e'", table, field, value, column_where, row_identifier); 2206 | if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1) 2207 | { 2208 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%e'", column_where2, row_identifier2); 2209 | strcat(SQL::upd_form, SQL::upd_form2); 2210 | } 2211 | if(!isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2)) 2212 | { 2213 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier3); 2214 | strcat(SQL::upd_form, SQL::upd_form2); 2215 | } 2216 | strcat(SQL::upd_form, " "); 2217 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2218 | return 1; 2219 | } 2220 | 2221 | stock SQL::SetStringEntry(const table[], const field[], const value[], const column_where[] = "", row_identifier = -1, bool:use_real_escape = true, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2222 | { 2223 | if(!table[0]) return 0; 2224 | if(!field[0]) return 0; 2225 | if(use_real_escape == true) 2226 | { 2227 | //Not using mysql_escape_string as the %e specifier is faster. 2228 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%e' WHERE `%s`='%d' ", table, field, value, column_where, row_identifier); 2229 | } 2230 | else 2231 | { 2232 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%s' WHERE `%s`='%d' ", table, field, value, column_where, row_identifier); 2233 | } 2234 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2235 | return 1; 2236 | } 2237 | 2238 | stock SQL::SetStringEntry2(const table[], const field[], const value[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", bool:use_real_escape = true, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2239 | { 2240 | if(!table[0]) return 0; 2241 | if(!field[0]) return 0; 2242 | if(use_real_escape == true) 2243 | { 2244 | //Not using mysql_escape_string as the %e specifier is faster. 2245 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%e' WHERE `%s`='%d'", table, field, value, column_where, row_identifier); 2246 | } 2247 | else 2248 | { 2249 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%e' WHERE `%s`='%d'", table, field, value, column_where, row_identifier); 2250 | } 2251 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 2252 | { 2253 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier2); 2254 | strcat(SQL::upd_form, SQL::upd_form2); 2255 | } 2256 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 2257 | { 2258 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier3); 2259 | strcat(SQL::upd_form, SQL::upd_form2); 2260 | } 2261 | strcat(SQL::upd_form, " "); 2262 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2263 | return 1; 2264 | } 2265 | 2266 | stock SQL::SetStringEntryEx(const table[], const field[], const value[], const column_where[] = "", const row_identifier[] = "", bool:use_real_escape = true, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2267 | { 2268 | if(!table[0]) return 0; 2269 | if(!field[0]) return 0; 2270 | if(use_real_escape == true) 2271 | { 2272 | //Not using mysql_escape_string as the %e specifier is faster. 2273 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%e' WHERE `%s`='%e' ", table, field, value, column_where, row_identifier); 2274 | } 2275 | else 2276 | { 2277 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%s' WHERE `%s`='%e' ", table, field, value, column_where, row_identifier); 2278 | } 2279 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2280 | return 1; 2281 | } 2282 | 2283 | stock SQL::SetStringEntryEx2(const table[], const field[], const value[], const column_where[] = "", const row_identifier[] = "", const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, bool:use_real_escape = true, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2284 | { 2285 | if(!table[0]) return 0; 2286 | if(!field[0]) return 0; 2287 | if(use_real_escape == true) 2288 | { 2289 | //Not using mysql_escape_string as the %e specifier is faster. 2290 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%e' WHERE `%s`='%e'", table, field, value, column_where, row_identifier); 2291 | } 2292 | else 2293 | { 2294 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%s' WHERE `%s`='%e'", table, field, value, column_where, row_identifier); 2295 | } 2296 | if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1) 2297 | { 2298 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%e'", column_where2, row_identifier2); 2299 | strcat(SQL::upd_form, SQL::upd_form2); 2300 | } 2301 | if(!isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2)) 2302 | { 2303 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier3); 2304 | strcat(SQL::upd_form, SQL::upd_form2); 2305 | } 2306 | strcat(SQL::upd_form, " "); 2307 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2308 | return 1; 2309 | } 2310 | 2311 | stock SQL::SetFloatEntry(const table[], const field[], Float:value, const column_where[] = "", row_identifier = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2312 | { 2313 | if(!table[0]) return 0; 2314 | if(!field[0]) return 0; 2315 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%f' WHERE `%s`='%d' ", table, field, value, column_where, row_identifier); 2316 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2317 | return 1; 2318 | } 2319 | 2320 | stock SQL::SetFloatEntry2(const table[], const field[], Float:value, const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2321 | { 2322 | if(!table[0]) return 0; 2323 | if(!field[0]) return 0; 2324 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%f' WHERE `%s`='%d'", table, field, value, column_where, row_identifier); 2325 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 2326 | { 2327 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier2); 2328 | strcat(SQL::upd_form, SQL::upd_form2); 2329 | } 2330 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 2331 | { 2332 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%s'", column_where2, row_identifier3); 2333 | strcat(SQL::upd_form, SQL::upd_form2); 2334 | } 2335 | strcat(SQL::upd_form, " "); 2336 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2337 | return 1; 2338 | } 2339 | 2340 | stock SQL::SetFloatEntryEx(const table[], const field[], Float:value, const column_where[] = "", const row_identifier[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2341 | { 2342 | if(!table[0]) return 0; 2343 | if(!field[0]) return 0; 2344 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%f' WHERE `%s`='%e' ", table, field, value, column_where, row_identifier); 2345 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2346 | return 1; 2347 | } 2348 | 2349 | stock SQL::SetFloatEntryEx2(const table[], const field[], Float:value, const column_where[] = "", const row_identifier[] = "", const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2350 | { 2351 | if(!table[0]) return 0; 2352 | if(!field[0]) return 0; 2353 | mysql_format(MySQL:connectionhandle, SQL::upd_form, sizeof(SQL::upd_form), "UPDATE `%s` SET `%s`='%f' WHERE `%s`='%e'", table, field, value, column_where, row_identifier); 2354 | if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1) 2355 | { 2356 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%e'", column_where2, row_identifier2); 2357 | strcat(SQL::upd_form, SQL::upd_form2); 2358 | } 2359 | if(!isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2)) 2360 | { 2361 | mysql_format(MySQL:connectionhandle, SQL::upd_form2, sizeof(SQL::upd_form2), " AND `%s`='%d'", column_where2, row_identifier3); 2362 | strcat(SQL::upd_form, SQL::upd_form2); 2363 | } 2364 | strcat(SQL::upd_form, " "); 2365 | mysql_tquery(MySQL:connectionhandle, SQL::upd_form, "", ""); 2366 | return 1; 2367 | } 2368 | 2369 | 2370 | stock SQL::TableExists(const tablename[], MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2371 | { 2372 | new query[SQL_FORM_LENGTH], Cache:result, rows; 2373 | mysql_format(MySQL:connectionhandle, query, sizeof(query),"SELECT * FROM `%s` ", tablename); 2374 | result = mysql_query(MySQL:connectionhandle, query); 2375 | if(mysql_errno() != 0) 2376 | { 2377 | return SQL_Warning("Query could not be completed due to error: %s", query); 2378 | } 2379 | cache_get_row_count(rows); 2380 | cache_delete(result); 2381 | if(rows > 0) 2382 | { 2383 | return 1; 2384 | } 2385 | return 0; 2386 | } 2387 | 2388 | stock SQL::ExistsTable(const tablename[], MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2389 | { 2390 | new query[85], Cache:result, rows; 2391 | mysql_format(MySQL:connectionhandle, query, sizeof(query), "SHOW TABLES LIKE '%s' ", tablename); 2392 | result = mysql_query(MySQL:connectionhandle, query); 2393 | if(mysql_errno() != 0) 2394 | { 2395 | return SQL_Warning("Query could not be completed due to error: %s", query); 2396 | } 2397 | cache_get_row_count(rows); 2398 | cache_delete(result); 2399 | if(rows > 0) 2400 | { 2401 | return 1; 2402 | } 2403 | return 0; 2404 | } 2405 | 2406 | stock SQL::CountRows(const tablename[], MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2407 | { 2408 | new query[SQL_FORM_LENGTH], Cache:result, rows; 2409 | mysql_format(MySQL:connectionhandle, query, sizeof(query), "SELECT * FROM `%s` ", tablename); 2410 | result = mysql_query(MySQL:connectionhandle, query); 2411 | if(mysql_errno() != 0) 2412 | { 2413 | return SQL_Warning("Query could not be completed due to error: %s", query); 2414 | } 2415 | cache_get_row_count(rows); 2416 | cache_delete(result); 2417 | return rows; 2418 | } 2419 | 2420 | stock SQL::RowExistsEx(const table[], const column_where[] = "", const row_identifier[], MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2421 | { 2422 | new query[SQL_FORM_LENGTH], Cache:result, rows; 2423 | mysql_format(MySQL:connectionhandle, query, sizeof(query),"SELECT * FROM `%s` WHERE `%s`='%e' ", table, column_where, row_identifier); 2424 | result = mysql_query(MySQL:connectionhandle, query); 2425 | if(mysql_errno() != 0) 2426 | { 2427 | return SQL_Warning("Query could not be completed due to error: %s", query); 2428 | } 2429 | cache_get_row_count(rows); 2430 | cache_delete(result); 2431 | if(rows > 0) 2432 | { 2433 | return rows; 2434 | } 2435 | return 0; 2436 | } 2437 | 2438 | stock SQL::RowExistsEx2(const table[], const column_where[] = "", const row_identifier[], const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2439 | { 2440 | new query[SQL_FORM_LENGTH], query2[SQL_FORM_LENGTH], Cache:result, rows; 2441 | mysql_format(MySQL:connectionhandle, query, sizeof(query), "SELECT * FROM `%s` WHERE `%s`='%e'", table, column_where, row_identifier); 2442 | if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1) 2443 | { 2444 | mysql_format(MySQL:connectionhandle, query2, sizeof(query2), " AND `%s`='%e'", column_where2, row_identifier2); 2445 | strcat(query, query2); 2446 | } 2447 | if(!isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2)) 2448 | { 2449 | mysql_format(MySQL:connectionhandle, query2, sizeof(query2), " AND `%s`='%d'", column_where2, row_identifier3); 2450 | strcat(query, query2); 2451 | } 2452 | strcat(query, " "); 2453 | result = mysql_query(MySQL:connectionhandle, query); 2454 | if(mysql_errno() != 0) 2455 | { 2456 | return SQL_Warning("Query could not be completed due to error: %s", query); 2457 | } 2458 | cache_get_row_count(rows); 2459 | cache_delete(result); 2460 | if(rows > 0) 2461 | { 2462 | return rows; 2463 | } 2464 | return 0; 2465 | } 2466 | 2467 | stock SQL::DropTable(const table[], MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2468 | { 2469 | new query[SQL_FORM_LENGTH]; 2470 | mysql_format(MySQL:connectionhandle, query, sizeof(query), "DROP TABLE %s;", table); 2471 | mysql_tquery(MySQL:connectionhandle, query, "", ""); 2472 | return 0; 2473 | } 2474 | 2475 | stock SQL::RowExists(const table[], const column_where[] = "", row_identifier = -1, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2476 | { 2477 | new query[SQL_FORM_LENGTH], Cache:result, rows; 2478 | mysql_format(MySQL:connectionhandle, query, sizeof(query),"SELECT * FROM `%s` WHERE `%s`='%d' ", table, column_where, row_identifier); 2479 | result = mysql_query(MySQL:connectionhandle, query); 2480 | if(mysql_errno() != 0) 2481 | { 2482 | return SQL_Warning("Query could not be completed due to error: %s", query); 2483 | } 2484 | cache_get_row_count(rows); 2485 | cache_delete(result); 2486 | if(rows > 0) 2487 | { 2488 | return rows; 2489 | } 2490 | return 0; 2491 | } 2492 | 2493 | stock SQL::RowExists2(const table[], const column_where[] = "", row_identifier = -1, const column_where2[] = "", row_identifier2 = -1, const row_identifier3[] = "", MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2494 | { 2495 | new query[SQL_FORM_LENGTH], query2[SQL_FORM_LENGTH], Cache:result, rows; 2496 | mysql_format(MySQL:connectionhandle, query, sizeof(query), "SELECT * FROM `%s` WHERE `%s`='%d'", table, column_where, row_identifier); 2497 | if(!isnull(column_where2) && row_identifier2 != -1 && isnull(row_identifier3)) 2498 | { 2499 | mysql_format(MySQL:connectionhandle, query2, sizeof(query2), " AND `%s`='%d'", column_where2, row_identifier2); 2500 | strcat(query, query2); 2501 | } 2502 | if(!isnull(column_where2) && !isnull(row_identifier3) && row_identifier2 == -1) 2503 | { 2504 | mysql_format(MySQL:connectionhandle, query2, sizeof(query2), " AND `%s`='%s'", column_where2, row_identifier3); 2505 | strcat(query, query2); 2506 | } 2507 | strcat(query, " "); 2508 | result = mysql_query(MySQL:connectionhandle, query); 2509 | if(mysql_errno() != 0) 2510 | { 2511 | return SQL_Warning("Query could not be completed due to error: %s", query); 2512 | } 2513 | cache_get_row_count(rows); 2514 | cache_delete(result); 2515 | if(rows > 0) 2516 | { 2517 | return rows; 2518 | } 2519 | return 0; 2520 | } 2521 | 2522 | stock SQL::CountTables(MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2523 | { 2524 | new Cache:result, rows; 2525 | result = mysql_query(MySQL:connectionhandle, "SHOW TABLES"); 2526 | if(mysql_errno() != 0) 2527 | { 2528 | return SQL_Warning("Query could not be completed due to error: %s", "SHOW TABLES"); 2529 | } 2530 | cache_get_row_count(rows); 2531 | cache_delete(result); 2532 | return rows; 2533 | } 2534 | 2535 | stock SQL::AddForeignKey(const o_table[], const f_table[], const o_key[], const f_key[], const db[], SQL::ftypes:on_delete, SQL::ftypes:on_update, MySQL:connectionhandle = MYSQL_DEFAULT_HANDLE) 2536 | { 2537 | new query[256]; 2538 | mysql_format(MySQL:connectionhandle, query, sizeof(query), "ALTER TABLE `%s` ADD FOREIGN KEY (`%s`) REFERENCES `%s`.`%s`(`%s`) ON DELETE %s ON UPDATE %s;", 2539 | o_table, o_key, db, f_table, f_key, SQL::RetFType(on_delete), SQL::RetFType(on_update)); 2540 | mysql_tquery(MySQL:connectionhandle, query, "", ""); 2541 | return 0; 2542 | } 2543 | 2544 | #undef SQL_INVALID_HANDLE 2545 | #undef SQL_MAX_TABLE_NAME 2546 | #undef SQL_MAX_HANDLES 2547 | #undef SQL_Warning 2548 | #undef SQL_Error 2549 | -------------------------------------------------------------------------------- /login-register.pwn: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * Simple register/login system using easy_mysql.inc! 6 | */ 7 | 8 | #define mysql_host "localhost" 9 | #define mysql_user "root" 10 | #define mysql_db "server" 11 | #define mysql_pass "" 12 | #define mysql_debugging_enabled (true) 13 | #define SQL_PLAYERS_TABLE "players" 14 | #define DIALOG_LOGIN 0 15 | #define DIALOG_REGISTER 1 16 | 17 | enum p_info 18 | { 19 | p_id, 20 | p_name[24], 21 | p_password[64], 22 | p_score, 23 | Float:p_posx, 24 | Float:p_posy, 25 | Float:p_posz, 26 | p_loggedin 27 | }; 28 | new UserInfo[MAX_PLAYERS][p_info]; 29 | 30 | stock ret_pName(playerid) 31 | { 32 | new name[24]; 33 | GetPlayerName(playerid, name, sizeof(name)); 34 | return name; 35 | } 36 | 37 | main() 38 | { 39 | 40 | } 41 | public OnGameModeInit() 42 | { 43 | //Connecting to the MySQL database, default connection handle. 44 | SQL::Connect(mysql_host, mysql_user, mysql_pass, mysql_db); 45 | //Checking if the table 'players' exists 46 | 47 | //Checking if the table 'players' exists 48 | if(!SQL::ExistsTable(SQL_PLAYERS_TABLE)) 49 | { 50 | //If not, then create a table called 'players'. 51 | new handle = SQL::Open(SQL::CREATE, SQL_PLAYERS_TABLE); //Opening a valid handle to create a table called 'players' 52 | SQL::AddTableColumn(handle, "p_id", SQL_TYPE_INT, 11, true); //Setting auto-increment for this field. 53 | SQL::AddTableColumn(handle, "p_name", SQL_TYPE_VCHAR, 24); 54 | SQL::AddTableColumn(handle, "p_password", SQL_TYPE_VCHAR, 64); 55 | SQL::AddTableColumn(handle, "p_score", SQL_TYPE_INT); 56 | SQL::AddTableColumn(handle, "p_posx", SQL_TYPE_FLOAT); 57 | SQL::AddTableColumn(handle, "p_posy", SQL_TYPE_FLOAT); 58 | SQL::AddTableColumn(handle, "p_posz", SQL_TYPE_FLOAT); 59 | SQL::Close(handle);//Closing the previous opened handle. 60 | } 61 | return 1; 62 | } 63 | 64 | public OnPlayerConnect(playerid) 65 | { 66 | UserInfo[playerid][p_loggedin] = 0; UserInfo[playerid][p_score] = 0; UserInfo[playerid][p_posx] = 1958.3783; 67 | UserInfo[playerid][p_posy] = 1343.1572; UserInfo[playerid][p_posz] = 15.3746; 68 | 69 | if(SQL::RowExistsEx(SQL_PLAYERS_TABLE, "p_name", ret_pName(playerid))) //Check if the name is registered in the database 70 | { 71 | //Get the player password and unique ID. 72 | new handle = SQL::OpenEx(SQL::READ, "players", "p_name", ret_pName(playerid)); 73 | SQL::ReadString(handle, "p_password", UserInfo[playerid][p_password], 64); 74 | SQL::ReadInt(handle, "p_id", UserInfo[playerid][p_id]); 75 | SQL::Close(handle); 76 | //Show the login dialog 77 | ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{0080FF}Login", "Please input your password below to log in.", "Login", "Exit"); 78 | } 79 | else 80 | { 81 | //If not registered, then show the register DIALOG. 82 | ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{0080FF}Register", "Please input a password below to register in.", "Login", "Exit"); 83 | } 84 | return 1; 85 | } 86 | 87 | public OnPlayerSpawn(playerid) 88 | { 89 | SetPlayerPos(playerid, UserInfo[playerid][p_posx], UserInfo[playerid][p_posy], UserInfo[playerid][p_posz]); 90 | return 1; 91 | } 92 | 93 | public OnPlayerDisconnect(playerid, reason) 94 | { 95 | if(UserInfo[playerid][p_loggedin] == 1) 96 | { 97 | //Save the player data. 98 | GetPlayerPos(playerid, UserInfo[playerid][p_posx], UserInfo[playerid][p_posy], UserInfo[playerid][p_posz]); 99 | new handle = SQL::Open(SQL::UPDATE, SQL_PLAYERS_TABLE, "p_id", UserInfo[playerid][p_id]); //update WHERE p_id = UserInfo[playerid][p_id] 100 | SQL::WriteInt(handle, "p_score", GetPlayerScore(playerid)); 101 | SQL::WriteFloat(handle, "p_posx", UserInfo[playerid][p_posx]); 102 | SQL::WriteFloat(handle, "p_posy", UserInfo[playerid][p_posy]); 103 | SQL::WriteFloat(handle, "p_posz", UserInfo[playerid][p_posz]); 104 | SQL::Close(handle); 105 | } 106 | return 1; 107 | } 108 | 109 | public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 110 | { 111 | switch(dialogid) 112 | { 113 | case DIALOG_REGISTER: 114 | { 115 | if(!response) return Kick(playerid); 116 | if(strlen(inputtext) < 5) 117 | { 118 | ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{0080FF}Register", "Please input a password below to register in.", "Login", "Exit"); 119 | return 1; 120 | } 121 | SHA256_PassHash(inputtext, "", UserInfo[playerid][p_password], 64); 122 | new handle = SQL::Open(SQL::INSERT, SQL_PLAYERS_TABLE); 123 | SQL::ToggleAutoIncrement(handle, true);//Toggles auto increment, SQL::Close will return cache_insert_id(); 124 | SQL::WriteString(handle, "p_name", ret_pName(playerid)); 125 | SQL::WriteString(handle, "p_password", UserInfo[playerid][p_password]); 126 | SQL::WriteInt(handle, "p_score", 0); 127 | SQL::WriteFloat(handle, "p_posx", 0.0); 128 | SQL::WriteFloat(handle, "p_posy", 0.0); 129 | SQL::WriteFloat(handle, "p_posz", 0.0); 130 | UserInfo[playerid][p_id] = SQL::Close(handle); 131 | SendClientMessage(playerid, -1, "Successfully registered in!"); 132 | UserInfo[playerid][p_loggedin] = 1; 133 | } 134 | case DIALOG_LOGIN: 135 | { 136 | if(!response) Kick(playerid); 137 | new hash[64]; 138 | SHA256_PassHash(inputtext, "", hash, 64); 139 | if(!strcmp(hash, UserInfo[playerid][p_password])) 140 | { 141 | //Load player data 142 | new handle = SQL::Open(SQL::READ, SQL_PLAYERS_TABLE, "p_id", UserInfo[playerid][p_id]); 143 | SQL::ReadInt(handle, "p_score", UserInfo[playerid][p_score]); 144 | SQL::ReadFloat(handle, "p_posx", UserInfo[playerid][p_posx]); 145 | SQL::ReadFloat(handle, "p_posy", UserInfo[playerid][p_posy]); 146 | SQL::ReadFloat(handle, "p_posz", UserInfo[playerid][p_posz]); 147 | SQL::Close(handle);//You must close the handle. 148 | SetPlayerScore(playerid, UserInfo[playerid][p_score]); 149 | UserInfo[playerid][p_loggedin] = 1; 150 | SendClientMessage(playerid, -1, "Successfully logged in!"); 151 | 152 | } 153 | else 154 | { 155 | ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{0080FF}Login", "Please input your password below to log in.", "Login", "Exit"); 156 | } 157 | } 158 | } 159 | return 1; 160 | } 161 | --------------------------------------------------------------------------------