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




------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to