MCPcopy Create free account
hub / github.com/ActiveState/code / SQLSMO

Class SQLSMO

recipes/Python/578977_Python_SQLSMO_/recipe-578977.py:214–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212# -----------------Start of class SQLSMO----------------------------------
213
214class SQLSMO:
215 def __init__(self, conn, datafilepath='', logfilepath='', backupfilepath='' ):
216 self.conn = conn
217 self.datafolder = datafilepath
218 self.logfolder = logfilepath
219 self.logfilename = ''
220 self.backupfile = backupfilepath
221 self.currdb = conn['db']
222 self.defdb = 'master'
223 self.noexecute = 0 #1=no execute, 0=yes to execute
224 self.sqlrestore = ''
225 self.sqlbackup = ''
226
227 self.sqlfilelist = 'SET NOCOUNT ON RESTORE FILELISTONLY FROM DISK = ' + chr(39) + self.backupfile + chr(39)
228 self.sqlfileheader = 'SET NOCOUNT ON RESTORE HEADERONLY FROM DISK = ' + chr(39) + self.backupfile + chr(39)
229 self.sqlxp_fixeddrives = 'SET NOCOUNT ON EXEC master..xp_fixeddrives'
230 self.sqlsphelpdb = 'SET NOCOUNT ON select name, physical_name, (size * 8/1000) as size, data_space_id from ['+ self.currdb + '].sys.database_files'
231
232 self.datafiles_size_existing = 0 #info from existing database --- populated by GetDatabaseInfo
233 self.logfiles_size_existing = 0 #info from existing database --- populated by GetDatabaseInfo
234
235 self.dictdbinfo = {} #info from existing database --- populated by GetDatabaseInfo
236 self.dictfiles = {} #info from backup file --- populated by GetBackupInfo
237 self.dictheader = {} #info from backup file --- populated by GetBackupInfo
238 self.dictfreespace = {} #info on disk space --- populated by GetFreeSpace
239
240 self.datafiles_size = 0 #info from backup file --- populated by GetBackupInfo
241 self.logfiles_size = 0 #info from backup file --- populated by GetBackupInfo
242
243 self.backup_options = {'backup_type': 'DATABASE', 'compression': False} #options for backup_type: LOG, DIFFERENTIAL
244 self.restore_options = {'dated_file_names': False,
245 'original_file_names': False,
246 'restore_type': 'DATABASE', #options: LOG
247 'recovery': 'RECOVERY', #options: NORECOVERY
248 'replace': True #option: False
249 }
250
251 def GetDataseInfo(self):
252 """
253 Returns info about existing database
254 Return values are rows and column names
255 It populates these variables
256 self.logfiles_size_existing
257 self.datafiles_size_existing
258 """
259 self.logfiles_size_existing = 0.0
260 self.datafiles_size_existing = 0.0
261
262 rows, fnames = [], []
263 try:
264 # fnames are: name physical_name size data_space_id
265 rows, fnames = SqlExecute(self.conn, self.sqlsphelpdb)
266 except Exception as inst:
267 print('No existing database information', inst)
268 self.dictdbinfo = {}
269 return rows, fnames
270
271

Callers 2

ActionParsingFunction · 0.90
recipe-578977.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected