SQL restore questions?

Ruslan Zasukhin sunshine at public.kherson.ua
Tue Aug 5 12:59:57 CDT 2003


on 8/4/03 22:24, Chuck at rwc1717 at shaw.ca wrote:

> 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!

Excellent !!!
This can be added to viSQL or vStudio.

Just I think it is danger do ReadAll, because db cab be huge.
 

> Now the questions:
> 
> Should I flush more, like every 100 records or does it matter?

Actually since you create NEW db, it is not problem to loose something on
crash, because in any case you can start again.

> 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:-).

-- 
Best regards,
Ruslan Zasukhin      [ I feel the need...the need for speed ]
-------------------------------------------------------------
e-mail: ruslan at paradigmasoft.com
web: http://www.paradigmasoft.com

To subscribe to the Valentina mail list go to:
http://lists.macserve.net/mailman/listinfo/valentina
-------------------------------------------------------------



More information about the Valentina mailing list