Need to execute huge scripts like that found at https://github.com/unee-t/bz-database/tree/master/scripts I filed a (closed) bug here https://github.com/go-sql-driver/mysql/issues/789 Currently it appears I need to manually rewrite the scripts which is a gigantic time sink!
评论:
SeerUD:
icholy:This is a great place to start: http://go-database-sql.org/
From there, just read the SQL files using
os.Open
, read all of the SQL from it, and then run it like you would any other query.
kai:You can always just execute the mysql cli tools using os/exec
edit: this is the dns param you're looking for https://github.com/go-sql-driver/mysql#multistatements
icholy:thanks, though even with multistatements enabled, I'm a little confused how SQL scripts with backticks get escaped.
kai:What are you talking about? An SQL "script" is just a query in a file.
icholy:So you're right. Reading in the file
ioutil.ReadFile("sql/script.sql")
and executing as a string seems work with the DNS option?multiStatements=true
configured.
kai:I think you meant to say "thank you for doing my job for me"
icholy:Thanks for being patronising! It's DSN btw, not dns. Thankfully we don't work together.
dgryski:You're an incompetent piece of shit
kjwabn:Well, that escalated quickly..
Please reconsider your wording.
kai:you can use xorm. http://xorm.io/
Gigaftp:I don't see a function to run a script...
Not hard to implement. Read the file in as a string, ex3cute query string. Profit.
