Add mysql.table_exists() convenience function
				
					
				
			This commit is contained in:
		
							parent
							
								
									72c03a8ac9
								
							
						
					
					
						commit
						5a7a122e2d
					
				
					 1 changed files with 10 additions and 0 deletions
				
			
		|  | @ -93,6 +93,16 @@ def grant_access(c, dbname, username): | |||
|     sql(c, 'grant all on `{}`.* to {}'.format(dbname, username)) | ||||
| 
 | ||||
| 
 | ||||
| def table_exists(c, tblname, dbname): | ||||
|     """ | ||||
|     Determine if given table exists in given DB. | ||||
|     """ | ||||
|     # TODO: should avoid sql injection here... | ||||
|     query = "SELECT TABLE_NAME FROM TABLES WHERE TABLE_SCHEMA = '{}' AND TABLE_NAME = '{}'".format(dbname, tblname) | ||||
|     name = sql(c, query, database='information_schema').stdout.strip() | ||||
|     return name == tblname | ||||
| 
 | ||||
| 
 | ||||
| def sql(c, sql, database=''): | ||||
|     """ | ||||
|     Execute some SQL. | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar