mIRC Home    About    Download    Register    News    Help

Print Thread
#247664 20/08/14 01:23 AM
Joined: May 2014
Posts: 13
S
Shakar Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2014
Posts: 13
Hey there,
I was looking in the forums but I couldn't find anything like this.
Is there any sort of script/snippet/way that allows me to convert an ini to .sql? or some sort of 1-line text files that I can use LOAD DATA INFILE?

Thank you very much in advance,
Regards,

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
The structure of an ini file does not lend itself to a database - unless your database is tables with only an index and a single additional field? Doing it "automatically" would only be useful in this instance; and you'd still need to factor in the data types. Otherwise you'll need to create a more custom solution.

Code:
var %in = $1, %out = $2

var %t = 1, %tables = $ini(%in,0)
while (%t <= %tables) {
  var %table = $ini(%in,%t)
  var %i = 1, %items = $readini(%in,%table,0)
  while (%i <= %items) {
    var %item = $ini(%in,%table,%i)
    var %value = $readini(%in,n,%table,%item)
    write %out INSERT INTO %table VALUES( %item , %value )
    inc %i
  }
  inc %t
}

Joined: May 2014
Posts: 13
S
Shakar Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2014
Posts: 13
Thank you very much!

That's exactly what I needed!


Link Copied to Clipboard