├── LICENSE ├── README.md ├── package.json └── pysql.py /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 [yyyy] [name of copyright owner] 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [](https://luciopaiva.com/markdown-toc/) 2 | ![PySQL Framework](https://i.ibb.co/3FmsWch/mWQTLXjU.gif) 3 | 4 | PySQL is database framework for Python (v3.x) Language, Which is based on Python module mysql.connector, this module can help you to make your code more short and more easier. Before using this framework you must have knowledge about list, tuple, set, dictionary because all codes are designed using it. It's totally free and open source. 5 | ## Tutorial Video in English ([Watch Now](https://www.youtube.com/watch?v=8SQcq0a_UEg)) 6 | [![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/8SQcq0a_UEg/mqdefault.jpg)](https://www.youtube.com/watch?v=8SQcq0a_UEg) 7 | ## Installation 8 | Before we said that this framework is based on mysql.connector so you have to install mysql.connector first on your system. Then you can import pysql and enjoy coding! 9 | > python -m pip install mysql-connector-python 10 | 11 | 12 | After Install mysql.connector successfully create Python file download/install pysql on the same dir where you want to create program. You can clone is using git or npm command, and you can also downlaod manually from repository site. 13 | 14 | #### PyPi Command 15 | Go to [https://pypi.org/project/pysql-framework/](https://pypi.org/project/pysql-framework/) or use command 16 | ```sh 17 | pip install pysql-framework 18 | ``` 19 | 20 | #### Git Command 21 | ```sh 22 | git clone https://github.com/rohit-chouhan/pysql 23 | ``` 24 | #### Npm Command 25 | Go to [https://www.npmjs.com/package/pysql](https://www.npmjs.com/package/pysql) or use command 26 | ```sh 27 | $ npm i pysql 28 | ``` 29 | 30 | #### Snippet Extention for VS Code 31 | Install From Here [https://marketplace.visualstudio.com/items?itemName=rohit-chouhan.pysql](https://marketplace.visualstudio.com/items?itemName=rohit-chouhan.pysql) 32 | 33 | [![IMAGE ALT TEXT HERE](https://i.ibb.co/L9LNWb8/pysql.png)](https://marketplace.visualstudio.com/items?itemName=rohit-chouhan.pysql) 34 | # Table of contents 35 | - [Connecting a Server](#connecting-a-server) 36 | - [Create a Database in Server](#create-a-database-in-server) 37 | - [Drop Database](#drop--database) 38 | - [Connecting a Database](#connecting-a-database) 39 | - [Creating Table in Database](#creating-table-in-database) 40 | - [Drop Table in Database](#drop-table-in-database) 41 | - [Selecting data from Table](#selecting-data-from-table) 42 | - [Add New Column to Table](#add-new-column-to-table) 43 | - [Modify Column to Table](#modify-column-to-table) 44 | - [Drop Column from Table](#drop-column-from-table) 45 | - [Manual Execute Query](#manual-execute-query) 46 | - [Inserting data](#inserting-data) 47 | - [Updating data](#updating-data) 48 | - [Deleting data](#deleting-data) 49 | 50 | 51 | ### Connecting a Server 52 | ------------ 53 | To connect a database with localhost server or phpmyadmin, use connect method to establish your python with database server. 54 | 55 | ```python 56 | import pysql 57 | 58 | db = pysql.connect( 59 | "host", 60 | "username", 61 | "password" 62 | ) 63 | ``` 64 | ### Create a Database in Server 65 | ------------ 66 | Creating database in server, to use this method 67 | 68 | ```python 69 | import pysql 70 | 71 | db = pysql.connect( 72 | "host", 73 | "username", 74 | "password" 75 | ) 76 | pysql.createDb(db,"demo") 77 | #execute: CREATE DATABASE demo 78 | ``` 79 | ### Drop Database 80 | ------------ 81 | To drop database use this method . 82 | ##### Syntex Code - 83 | ```python 84 | pysql.dropDb([connect_obj,"table_name"]) 85 | ``` 86 | ##### Example Code - 87 | ```python 88 | pysql.dropDb([db,"demo"]) 89 | #execute:DROP DATABASE demo 90 | ``` 91 | ### Connecting a Database 92 | ------------ 93 | To connect a database with localhost server or phpmyadmin, use connect method to establish your python with database server. 94 | 95 | ```python 96 | import pysql 97 | 98 | db = pysql.connect( 99 | "host", 100 | "username", 101 | "password", 102 | "database" 103 | ) 104 | ``` 105 | ### Creating Table in Database 106 | ------------ 107 | To create table in database use this method to pass column name as key and data type as value. 108 | ##### Syntex Code - 109 | ```python 110 | 111 | pysql.createTable([db,"table_name_to_create"],{ 112 | "column_name":"data_type", 113 | "column_name":"data_type" 114 | }) 115 | ``` 116 | ##### Example Code - 117 | ```python 118 | 119 | pysql.createTable([db,"details"],{ 120 | "id":"int(11) primary", 121 | "name":"text", 122 | "email":"varchar(50)", 123 | "address":"varchar(500)" 124 | }) 125 | ``` 126 | ##### 2nd Example Code - 127 | Use can use any Constraint with Data Value 128 | ```python 129 | 130 | pysql.createTable([db,"details"],{ 131 | "id":"int NOT NULL PRIMARY KEY", 132 | "name":"varchar(20) NOT NULL", 133 | "email":"varchar(50)", 134 | "address":"varchar(500)" 135 | }) 136 | ``` 137 | ### Drop Table in Database 138 | ------------ 139 | To drop table in database use this method . 140 | ##### Syntex Code - 141 | ```python 142 | pysql.dropTable([connect_obj,"table_name"]) 143 | ``` 144 | ##### Example Code - 145 | ```python 146 | pysql.dropTable([db,"users"]) 147 | #execute:DROP TABLE users 148 | ``` 149 | ### Selecting data from Table 150 | ------------ 151 | For Select data from table, you have to mention the connector object with table name. pass column names in set. 152 | ##### Syntex `For All Data (*)`- 153 | ```python 154 | records = pysql.selectAll([db,"table_name"]) 155 | for x in records: 156 | print(x) 157 | ``` 158 | ##### Example - - 159 | ```python 160 | records = pysql.selectAll([db,"details"]) 161 | for x in records: 162 | print(x) 163 | #execute: SELECT * FROM details 164 | ``` 165 | ##### Syntex `For Specific Column`- 166 | ```python 167 | records = pysql.select([db,"table_name"],{"column","column"}) 168 | for x in records: 169 | print(x) 170 | ``` 171 | ##### Example - - 172 | ```python 173 | records = pysql.select([db,"details"],{"name","email"}) 174 | for x in records: 175 | print(x) 176 | #execute: SELECT name, email FROM details 177 | ``` 178 | 179 | ##### Syntex `Where and Where Not`- 180 | ```python 181 | #For Where Column=Data 182 | records = pysql.selectWhere([db,"table_name"],{"column","column"},("column","data")) 183 | 184 | #For Where Not Column=Data (use ! with column) 185 | records = pysql.selectWhere([db,"table_name"],{"column","column"},("column!","data")) 186 | for x in records: 187 | print(x) 188 | ``` 189 | ##### Example - - 190 | ```python 191 | records = pysql.selectWhere([db,"details"],{"name","email"},("county","india")) 192 | for x in records: 193 | print(x) 194 | #execute: SELECT name, email FROM details WHERE country='india' 195 | ``` 196 | ### Add New Column to Table 197 | ------------ 198 | To add column in table, use this method to pass column name as key and data type as value. 199 | Note: you can only add one column only one call 200 | ##### Syntex Code - 201 | ```python 202 | 203 | pysql.addColumn([db,"table_name"],{ 204 | "column_name":"data_type" 205 | }) 206 | ``` 207 | ##### Example Code - 208 | ```python 209 | 210 | pysql.addColumn([db,"details"],{ 211 | "email":"varchar(50)" 212 | }) 213 | #execute: ALTER TABLE details ADD email varchar(50); 214 | ``` 215 | ### Modify Column to Table 216 | ------------ 217 | To modify data type of column table, use this method to pass column name as key and data type as value. 218 | ##### Syntex Code - 219 | ```python 220 | pysql.modifyColumn([db,"table_name"],{ 221 | "column_name":"new_data_type" 222 | }) 223 | ``` 224 | ##### Example Code - 225 | ```python 226 | pysql.modifyColumn([db,"details"],{ 227 | "email":"text" 228 | }) 229 | #execute: ALTER TABLE details MODIFY COLUMN email text; 230 | ``` 231 | ### Drop Column from Table 232 | ------------ 233 | Note: you can only add one column only one call 234 | ##### Syntex Code - 235 | ```python 236 | pysql.dropColumn([db,"table_name"],"column_name") 237 | ``` 238 | ##### Example Code - 239 | ```python 240 | pysql.dropColumn([db,"details"],"name") 241 | #execute: ALTER TABLE details DROP COLUMN name 242 | ``` 243 | ### Manual Execute Query 244 | ------------ 245 | To execute manual SQL Query to use this method. 246 | ##### Syntex Code - 247 | ```python 248 | pysql.query(connector_object,your_query) 249 | ``` 250 | ##### Example Code - 251 | ```python 252 | pysql.query(db,"INSERT INTO users (name) VALUES ('Rohit')") 253 | ``` 254 | 255 | ### Inserting data 256 | ------------ 257 | For Inserting data in database, you have to mention the connector object with table name, and data as sets. 258 | ##### Syntex - 259 | ```python 260 | data = { 261 | "db_column":"Data for Insert", 262 | "db_column":"Data for Insert" 263 | } 264 | pysql.insert([db,"table_name"],data) 265 | ``` 266 | ##### Example Code - 267 | ```python 268 | data = { 269 | "name":"Komal Sharma", 270 | "contry":"India" 271 | } 272 | pysql.insert([db,"users"],data) 273 | ``` 274 | 275 | ### Updating data 276 | ------------ 277 | For Update data in database, you have to mention the connector object with table name, and data as tuple. 278 | ##### Syntex `For Updating All Data`- 279 | ```python 280 | data = ("column","data to update") 281 | pysql.updateAll([db,"users"],data) 282 | ``` 283 | ##### Example - - 284 | ```python 285 | data = ("name","Rohit") 286 | pysql.updateAll([db,"users"],data) 287 | #execute: UPDATE users SET name='Rohit' 288 | ``` 289 | ##### Syntex `For Updating Data (Where and Where Not)`- 290 | ```python 291 | data = ("column","data to update") 292 | #For Where Column=Data 293 | where = ("column","data") 294 | 295 | #For Where Not Column=Data (use ! with column) 296 | where = ("column!","data") 297 | pysql.update([db,"users"],data,where) 298 | ``` 299 | ##### Example - 300 | ```python 301 | data = ("name","Rohit") 302 | where = ("id",1) 303 | pysql.update([db,"users"],data,where) 304 | #execute: UPDATE users SET name='Rohit' WHERE id=1 305 | ``` 306 | ### Deleting data 307 | ------------ 308 | For Delete data in database, you have to mention the connector object with table name. 309 | ##### Syntex `For Delete All Data`- 310 | ```python 311 | pysql.deleteAll([db,"table_name"]) 312 | ``` 313 | ##### Example - - 314 | ```python 315 | pysql.deleteAll([db,"users"]) 316 | #execute: DELETE FROM users 317 | ``` 318 | ##### Syntex `For Deleting Data (Where and Where Not)`- 319 | ```python 320 | where = ("column","data") 321 | 322 | pysql.delete([db,"table_name"],where) 323 | ``` 324 | ##### Example - 325 | ```python 326 | #For Where Column=Data 327 | where = ("id",1) 328 | 329 | #For Where Not Column=Data (use ! with column) 330 | where = ("id!",1) 331 | pysql.delete([db,"users"],where) 332 | #execute: DELETE FROM users WHERE id=1 333 | ``` 334 | ## --- Finish --- 335 | #### Change Logs 336 | ```sh 337 | [19/06/2021] 338 | - ConnectSever() removed and merged to Connect() 339 | - deleteAll() [Fixed] 340 | - dropTable() [Added] 341 | - dropDb() [Added] 342 | 343 | [20/06/2021] 344 | - Where Not Docs [Added] 345 | ``` 346 | 347 | The module is designed by [Rohit Chouhan](https://www.linkedin.com/in/itsrohitchouhan/), contact us for any bug report, feature or business inquiry. 348 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@rohit-chouhan/pysql", 3 | "version": "1.0.3", 4 | "description": "PySQL is database framework for Python (v3.x) Language, Which is based on Python module mysql.connector, this module can help you to make your code more short and more easier.", 5 | "main": "pysql.py", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "framework","python","sql","database" 11 | ], 12 | "author": "Rohit Chouhan", 13 | "license": "Apache-2.0 License", 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/rohit-chouhan/pysql.git" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/rohit-chouhan/pysql/issues" 20 | }, 21 | "homepage": "https://github.com/rohit-chouhan/pysql#readme", 22 | "publishConfig": { "registry": "https://npm.pkg.github.com/" } 23 | } 24 | -------------------------------------------------------------------------------- /pysql.py: -------------------------------------------------------------------------------- 1 | _C='ALTER TABLE ' 2 | _B='SELECT {} FROM {}' 3 | _A=',' 4 | import mysql.connector 5 | def table(x):global table;table=str(x) 6 | def connect(*A): 7 | if len(A)==3:B=mysql.connector.connect(host=A[0],user=A[1],password=A[2]) 8 | else:B=mysql.connector.connect(host=A[0],user=A[1],password=A[2],database=A[3]) 9 | return B 10 | def query(x,y):A=x.cursor();A.execute(y);x.commit() 11 | def createDb(x,y):A=x.cursor();A.execute('CREATE DATABASE '+y+'');x.commit() 12 | def select(x,y): 13 | B=[] 14 | for D in y:B.append(D) 15 | E=_A.join(B);C=x[0].cursor();A=_B;A=A.format(E,x[1]);C.execute(A);return C.fetchall() 16 | def selectAll(x):B=x[0].cursor();A=_B;A=A.format('*',x[1]);B.execute(A);return B.fetchall() 17 | def selectWhere(x,y,z): 18 | B=[] 19 | for D in y:B.append(D) 20 | E=_A.join(B);C=x[0].cursor() 21 | if type(z[1])==str:A="SELECT {} FROM {} WHERE {}='{}'" 22 | else:A='SELECT {} FROM {} WHERE {}={}' 23 | A=A.format(E,x[1],z[0],z[1]);C.execute(A);return C.fetchall() 24 | def dropTable(x):A=x[0].cursor();B='DROP TABLE {}';A.execute(B.format(x[1]));x[0].commit() 25 | def dropDb(x):A=x[0].cursor();B='DROP DATABASE {}';A.execute(B.format(x[1]));x[0].commit() 26 | def createTable(db,data): 27 | A=[] 28 | for B in data:A.append(B+' '+data[B]) 29 | C=_A.join(A);D='CREATE TABLE '+db[1]+' ({})';E=D.format(C);F=db[0].cursor();F.execute(E);db[0].commit() 30 | def addColumn(db,data): 31 | A=[] 32 | for B in data:A.append(B);A.append(data[B]) 33 | C=_C+db[1]+' ADD {} {}';D=C.format(A[0],A[1]);E=db[0].cursor();E.execute(D);db[0].commit() 34 | def modifyColumn(db,data): 35 | A=[] 36 | for B in data:A.append(B);A.append(data[B]) 37 | C=_C+db[1]+' MODIFY {} {}';D=C.format(A[0],A[1]);E=db[0].cursor();E.execute(D);db[0].commit() 38 | def dropColumn(db,data):A='ALTER TABLE {} DROP COLUMN {}';A=A.format(db[1],data);B=db[0].cursor();B.execute(A);db[0].commit() 39 | def insert(db,data): 40 | J='"';A=[];B=[];C=[] 41 | for D in data:A.append(D);B.append(str(J+data[D]+J));C.append(str('%s')) 42 | E=_A.join(A);F=_A.join(B);K=_A.join(C);G='INSERT INTO '+db[1]+' ({}) VALUES ({})';H=G.format(E,F);I=db[0].cursor();I.execute(H);db[0].commit() 43 | def updateAll(x,d): 44 | B=x[0].cursor() 45 | if type(d[1])==str:A="UPDATE {} SET {}='{}'" 46 | else:A='UPDATE {} SET {}={}' 47 | B.execute(A.format(x[1],d[0],d[1]));x[0].commit() 48 | def update(x,d,c): 49 | B=x[0].cursor() 50 | if type(d[1])==str: 51 | if type(c[1])==str:A="UPDATE {} SET {}='{}' WHERE {}='{}'" 52 | else:A="UPDATE {} SET {}='{}' WHERE {}={}" 53 | elif type(c[1])==str:A="UPDATE {} SET {}={} WHERE {}='{}'" 54 | else:A='UPDATE {} SET {}={} WHERE {}={}' 55 | B.execute(A.format(x[1],d[0],d[1],c[0],c[1]));x[0].commit() 56 | def delete(x,d): 57 | B=x[0].cursor() 58 | if type(d[1])==str:A="DELETE FROM {} WHERE {}='{}'" 59 | else:A='DELETE FROM {} WHERE {}={}' 60 | B.execute(A.format(x[1],d[0],d[1]));x[0].commit() 61 | def deleteAll(x):A=x[0].cursor();B='DELETE FROM {}';A.execute(B.format(x[1]));x[0].commit() 62 | --------------------------------------------------------------------------------