SQL restore questions?

Chuck rwc1717 at shaw.ca
Mon Aug 4 15:24:01 CDT 2003


Hi Ruslan:
	To take care of the problem with the database structure being in the sql dump 
file...security and all that....one can use either LargeBinaryStringMBS and the 
following

dim f,InDumpFile as FolderItem
dim b as LargeBinaryStreamMBS
dim filestream as TextOutPutStream
dim s as string
dim i,n as integer
dim little as boolean

//using the InDumpFile folderitem after Valentina dump as source

f = GetFolderItem("whatever.sql")
if f.exists then
	f.delete
end if

little = false
b =f.OpenAsLargeBinaryStreamMBS(SystemDataForkNameMBS,false)
b.littleEndian = little

s = b.read(b(length)
b.close
b= Nil

//or one can use after adding 'dim x as TextInputStream' above
//x = f.OpenAsTextFile
//s = x.readall
///either way works....


filestream = GetFolderItem("whatever.sql").CreateTextFile

for i = 1 to len(s)
	if mid(s,i,6) = "INSERT" then
		n = Instr(mid(s,i),");"
		u = trim(mid(s,i,n+1))
		filestream.writeline u  //file must be written to line by line
	end if
next
filestream.close

	The added benefit (beyond making people guess at the db structure) is that 
the file can now be read using REALBasic methods using the 
TextInputStream.ReadAll function instead of the line by line method...
(for some reason MBS doesn't work properly here for this application of restoring)

dim f,InDumpFile as FolderItem
dim fileread as TextInPutStream
dim s as string
dim i,n as integer


f = GetFolderItem("whatever.sql")
fileread = InDumpFile.OpenAsText
s = fileread.ReadAll
for i = 1 to len(s)
	n = Instr(i,s,");")
	u = trim(mid(s,i,n-i+1))
	i = n + 2
	j = mDb.SQLExecute(u)
next
fileread.close
mDB.flush

...all restored!

Now the questions:

	Should I flush more, like every 100 records or does it matter?

	Second, and i probably should ask Christian @ MBS but he is wrting an exam 
an the question is an opinion anyways....should i keep it simple and use the 
TextInputStream.Readall function from REALBasic or the Large Binary StreamMBS 
function.  Do you have any idea of  the different capabilities? And remeber i could 
not use MBS function to restore...the same code failed miserably..what other way is 
there:-).

	



More information about the Valentina mailing list