Skip to content

Commit bcdd45c

Browse files
committed
Package update
1 parent 84ec6cf commit bcdd45c

7 files changed

Lines changed: 38 additions & 23 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@
220220
</tr>
221221
<tr>
222222
<td>
223-
<code>rename_table(old_table_name, new_table_name)</code>
223+
<code>rename_table(tablename)</code>
224224
</td>
225225
<td>
226-
Rename a table.
226+
Rename db_table attribute table.
227227
</td>
228228
</tr>
229229
<tr>

README.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ get_row(key, value): Select and return a dictionary representin
7373

7474
get_table(): Select and return a list of dictionaries with each dictionary representing a row in the db_table attribute table.
7575

76-
rename_table(old_table_name, new_table_name): Rename a table.
76+
rename_table(tablename): Rename db_table attribute table.
7777

78-
drop_table(table): Drop/delete table in the file database.
78+
drop_table(table): Drop/delete table in the file database.
7979

8080
drop_row(key, value): Drop/delete rows within the db_table attribute table with matching key & value.
8181
The key argument must be a string and a key within the table.

connectwrap/connectwrap.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, db_filepath, db_table):
2323
raise ValueError("The db_filepath argument doesn't have the correct extension! Use .db, .sqlite, or .sqlite3!")
2424

2525
self.db_filepath = str(db_filepath)
26-
self.db_table = db_table
26+
self.db_table = str(db_table)
2727
self.connection = sqlite3.connect(self.db_filepath)
2828
self.connection_cursor = self.connection.cursor()
2929
self.connection_status = bool(True)
@@ -262,26 +262,21 @@ def get_table(self):
262262

263263
return table
264264

265-
# Rename a table.
266-
def rename_table(self, old_table_name, new_table_name):
265+
# Rename db_table attribute table.
266+
def rename_table(self, table):
267267
if (self.connection_status != True):
268268
raise db.DatabaseNotOpenError("Database is not open! The connection status attribute is not set to True!")
269269

270-
if (type(old_table_name) is not str):
271-
raise TypeError("The old_table_name argument isn't a string!")
272-
273-
if (type(new_table_name) is not str):
274-
raise TypeError("The new_table_name argument isn't a string!")
275-
276-
if (db.table_exists(self, old_table_name) == False):
277-
raise db.TableNotFoundError("The old_table_name argument table doesn't exist within the database!")
270+
if (type(table) is not str):
271+
raise TypeError("The tablename argument isn't a string!")
278272

279-
if (db.table_exists(self, new_table_name) == True):
280-
raise db.TableExistsError("The new_table_name argument table already exists within the database!")
273+
if (db.table_exists(self, table) == True):
274+
raise db.TableExistsError("The tablename argument table already exists within the database!")
281275

282-
query = str("ALTER TABLE {0} RENAME TO {1}").format(old_table_name, new_table_name)
276+
query = str("ALTER TABLE {0} RENAME TO {1}").format(self.db_table, table)
283277
db.execute(self, query)
284278
db.commit(self)
279+
self.db_table = table
285280

286281
# Drop/delete table in the database.
287282
def drop_table(self, table):
@@ -354,9 +349,20 @@ def create_table(self, table, **kwargs):
354349
if (type(kwargs[kwarg]) is not str):
355350
raise TypeError("The value in kwargs must be a string!")
356351

357-
if (kwargs[kwarg] != "int" and kwargs[kwarg] != "float" and kwargs[kwarg] != "str" and kwargs[kwarg] != "bytes" and kwargs[kwarg] != "None"):
352+
if (kwargs[kwarg].lower() != "int" and kwargs[kwarg].lower() != "float" and kwargs[kwarg].lower() != "str" and kwargs[kwarg].lower() != "bytes" and kwargs[kwarg].lower().title() != "None"):
358353
raise ValueError("The value in kwargs must be one of the following strings - 'int', 'float', 'str', 'bytes', 'None'")
359354

355+
if (kwargs[kwarg].lower() == "int"):
356+
kwargs[kwarg] = "INTEGER"
357+
elif (kwargs[kwarg].lower() == "float"):
358+
kwargs[kwarg] = "REAL"
359+
elif (kwargs[kwarg].lower() == "str"):
360+
kwargs[kwarg] = "TEXT"
361+
elif (kwargs[kwarg].lower() == "bytes"):
362+
kwargs[kwarg] = "BLOB"
363+
else:
364+
kwargs[kwarg] = "NULL"
365+
360366
if (count < len(kwargs) - 1):
361367
record += (kwarg + " " + kwargs[kwarg] + ",")
362368
else:
@@ -386,9 +392,20 @@ def create_column(self, column, datatype):
386392
if (db.key_exists(self, column) == True):
387393
raise KeyError("The column already exists within the db_table attribute table!")
388394

389-
if (datatype != "int" and datatype != "float" and datatype != "str" and datatype != "bytes" and datatype != "None"):
395+
if (datatype.lower() != "int" and datatype.lower() != "float" and datatype.lower() != "str" and datatype.lower() != "bytes" and datatype.lower().title() != "None"):
390396
raise ValueError("The datatype argument must be one of the following strings - 'int', 'float', 'str', 'bytes', 'None'")
391397

398+
if (datatype.lower() == "int"):
399+
datatype = "INTEGER"
400+
elif (datatype.lower() == "float"):
401+
datatype = "REAL"
402+
elif (datatype.lower() == "str"):
403+
datatype = "TEXT"
404+
elif (datatype.lower() == "bytes"):
405+
datatype = "BLOB"
406+
else:
407+
datatype = "NULL"
408+
392409
query = str("ALTER TABLE {0} ADD {1} {2}").format(self.db_table, column, datatype)
393410
db.execute(self, query)
394411
db.commit(self)

dist/connectwrap-1.1.3.tar.gz

-7.62 KB
Binary file not shown.

dist/connectwrap-1.1.4.tar.gz

7.73 KB
Binary file not shown.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='connectwrap',
8-
version='1.1.3',
8+
version='1.1.4',
99
packages=find_packages(),
1010
license='MIT',
1111
description='A Python package for SQLite database management & object relational mapping.',

test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
# Select a specific row with the key/value args and output to terminal.
4747
demo_database.select_row("position", "Captain")
4848

49-
input("Press enter to continue:")
50-
5149
# Delete the Crew table.
5250
demo_database.drop_table("Crew")
5351

0 commit comments

Comments
 (0)