[Gambas-user] import mysql dump EXEC or SHELL?
Jack
jscops at ...11...
Tue Dec 16 12:21:17 CET 2008
Le mardi 16 décembre 2008 12:20:06 wig, vous avez écrit :
> > wig wrote:
> >> Although I can create table by table from within Gambas with
> >> hCon.Databases.Add(sDbName), I wondered if there is a way to "import" a
> >> mysql dump file, so that I can create the tables with data (in one
> >> command).
> >>
> >> Untill now I allways used phpMyAdmin dump/export and import for creating
> >> the database structure and initial data, but I want to integrate it in
> >> my
> >> Gambas application.
> >
> > You could use the EXEC command to run the appropriate mysqlsomething
> > utility (don't recall which)
> >
> > Regards
> > Werner
>
> I couldn't get it to work with EXEC;
>
> sImport = "< " & Application.Path & "/mytables.sql"
> ' ...
> EXEC ["mysql", sUser, sPassword, sHost, sDatabase, sImport]
>
> Everything works fine except the last part that gives the file to read
> from.
>
> I get the general help of mysql, not a specific error like when I change
> the password to a wrong one.
>
> Maybe there is a difference between the normal parameters and the way to
> give the file to import from?
>
>
> I could get it to work with SHELL though:
>
> sImport = "< " & Application.Path & "/mytables.sql"
> '...
> sCommand = "mysql " & sUser & " " & sPassword & " " & sHost & " " &
> sDatabase & " " & sImport
> DEBUG sCommand
> SHELL sCommand WAIT
>
> Ok! Don't know which is the "preferred" way but this works.
>
>
to save your base you can use this Gambas command.
SHELL "mysqldump" & " " & "-u" & " " & db.Login & " " & "-p" & db.Password & "
" & "Name-of-your-base" & " " & "--add-drop-table" & " " & ">" & " " &
User.home & "/Name-of-your-base.sql" & " 2>/tmp/result" WAIT
To restore your base you can use this.
IF IsNull(db.Password) THEN 'if no password
SHELL "mysql" & " " & "-u" & " " & db.login & " " & "Name-of-your-base" &
" " & "<" & Sauves.Text & "/Name-of-your-base.sql" & " 2>/tmp/result" WAIT
ELSE
SHELL "mysql" & " " & "-u" & " " & db.login & " " & "-p" & db.Password & "
" & "Name-of-your-base" & " " & "<" & Sauves.Text & "/Name-of-your-base.sql" &
" 2>/tmp/result" WAIT
ENDIF
Note: 2>/tmp/result is for intercept the command shell error
I hope this script help you.
Cordialement.
Jacky
More information about the User
mailing list