@@ -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 )
0 commit comments