Skip to content

Commit 9b94fd7

Browse files
committed
CODE
1 parent 9a86a8c commit 9b94fd7

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
LICENCE
2+
README.txt
3+
setup.py
4+
dist
5+
src/quicksql.egg-info
6+
build

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
#### QuickSQL directly establishes connection between python and mysqlserver. And gives you simple interface to execute mysql commands easily.
33
## How to use?
44

5-
* ### Use 'quicksql' keyword to import
5+
### Use 'quicksql' keyword to import
66

7-
```import quicksql```
7+
``` from quicksql import quicksql```
88

99

10-
* ### Creating instance of module
10+
### Creating instance of module
1111
```DB = quicksql('host', port, 'username', 'password', 'database-name')```
1212

1313

1414

15-
* ### quicksql only have one method which is 'query'
15+
### quicksql only have one method which is 'query'
1616

1717
> pass your 'mysql commnad' as a string in query method to execute query.
1818
@@ -26,4 +26,3 @@
2626
## Bugs & Feedback
2727
#### Github - [Visit Here](https://github.com/Anas-Dew/QuickSQL)
2828

29-

src/quicksql/__init__.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
__version__ = '1.0.0'
2+
3+
import mysql.connector as mysql
4+
5+
def contains_word(search_string, target_word):
6+
return f'{target_word}' in f'{search_string}'
7+
8+
class quicksql:
9+
10+
def __init__(self, host:str, port:int, user:str, password:str, database:str):
11+
12+
self.SQL = mysql.Connect(host=f'{host}', port=port,
13+
user=f'{user}', password=f'{password}',
14+
database=f'{database}')
15+
16+
def query(self, MyQuery:str):
17+
18+
try :
19+
20+
if contains_word(MyQuery, 'select') == True :
21+
22+
MyQuery = f'{MyQuery}'
23+
24+
sql_cursor = self.SQL.cursor()
25+
sql_cursor.execute(MyQuery)
26+
27+
print('Query OK')
28+
29+
else :
30+
31+
sql_cursor = self.SQL.cursor()
32+
sql_cursor.execute(MyQuery)
33+
self.SQL.commit()
34+
35+
print('Query OK')
36+
37+
except mysql.errors.IntegrityError:
38+
39+
print('Primary Key Duplicate Error')
40+
except :
41+
42+
print("SQL Command Error")
43+
44+
45+
46+
47+
if __name__ == "__main__" :
48+
49+
pass

0 commit comments

Comments
 (0)