GreatWizard Posted December 24, 2011 Group: Members Topic Count: 1 Topics Per Day: 0.00 Content Count: 2 Reputation: 0 Joined: 12/15/11 Last Seen: June 7, 2021 Share Posted December 24, 2011 (edited) Hello, Here is the perl script that I have create with regular expressions to convert every database files from TXT to SQL. So in your configuration conf/inter_athena.conf you can activate: use_sql_db: yes Perl script txt2sql (Don't forget to set this file executable) : #!/usr/bin/perl use strict; use warnings; my ($db) = $ARGV[0] =~ '^([^.]+)'; open(my $out, ">$db.sql") || die "Impossible d'écrire le fichier."; while(<>) { next if m!^$|^//!; print $out "REPLACE INTO $db VALUES ("; s/'/''/g; my ($acc) = $_ =~ /[^{]+(.*)/; $acc =~ s/(^|,){s*/$1'/g; $acc =~ s/s*}(,|$)/'$1/g; s/([^,]*),/'$1',/g; s/'(d+|0x[A-F0-9]+)'/$1/ig; s/([^{]+)'{.*/$1$acc/; s/''/NULL/g; s///g; s/"/"/g; s/,$/,NULL/; print $out "$_);n"; } close $out; exit 0; Uses: ### My architecture: #Dir rathena = SVN rAthena cd rathena/db/ ### Convert ~/txt2sql item_db.txt ~/txt2sql item_db_re.txt ~/txt2sql item_db2.txt ~/txt2sql mob_db.txt ~/txt2sql mob_db2.txt ~/txt2sql mob_skill_db.txt ~/txt2sql mob_skill_db2.txt ### Update SQL # user = ragnarok # password = pwet # db = ragnarokdb mysql --user=ragnarok --password=pwet ragnarokdb < item_db.sql mysql --user=ragnarok --password=pwet ragnarokdb < item_db_re.sql mysql --user=ragnarok --password=pwet ragnarokdb < item_db2.sql mysql --user=ragnarok --password=pwet ragnarokdb < mob_db.sql mysql --user=ragnarok --password=pwet ragnarokdb < mob_db2.sql mysql --user=ragnarok --password=pwet ragnarokdb < mob_skill_db.sql # DON'T FORGET TO FLUSH mob_skill_db FIRSTLY mysql --user=ragnarok --password=pwet ragnarokdb < mob_skill_db2.sql # DON'T FORGET TO FLUSH mob_skill_db2 FIRSTLY Merry Christmas ! Edited December 26, 2011 by GreatWizard Quote Link to comment Share on other sites More sharing options...
CalciumKid Posted December 25, 2011 Group: Members Topic Count: 25 Topics Per Day: 0.01 Content Count: 257 Reputation: 253 Joined: 11/29/11 Last Seen: February 21, 2014 Share Posted December 25, 2011 Does this escape single quotes? Quote Link to comment Share on other sites More sharing options...
GreatWizard Posted December 25, 2011 Group: Members Topic Count: 1 Topics Per Day: 0.00 Content Count: 2 Reputation: 0 Joined: 12/15/11 Last Seen: June 7, 2021 Author Share Posted December 25, 2011 (edited) Of course I use it on my server and load database from SQL without problems. Edit: A small example Input Data: 21001,Bellum_Claymore,Bellum Claymore,4,20,,3500,260,,1,0,0x00004082,7,2,34,4,95,1,3,{ bonus2 bAddRace,RC_DemiHuman,80; bonus2 bIgnoreDefRate,RC_DemiHuman,30; if(getrefine()>=6) { bonus2 bAddRace,RC_DemiHuman,40; } if(getrefine()>=9) { autobonus2 "{ bonus bShortWeaponDamageReturn,20; bonus bMagicDamageReturn,20; }",200,1000,BF_WEAPON,"{ specialeffect2 EF_REFLECTSHIELD; }"; } },{},{} Output Data: REPLACE INTO item_db VALUES (21001,'Bellum_Claymore','Bellum Claymore',4,20,NULL,3500,260,NULL,1,0,0x00004082,7,2,34,4,95,1,3,'bonus2 bAddRace,RC_DemiHuman,80; bonus2 bIgnoreDefRate,RC_DemiHuman,30; if(getrefine()>=6) { bonus2 bAddRace,RC_DemiHuman,40; } if(getrefine()>=9) { autobonus2 "{ bonus bShortWeaponDamageReturn,20; bonus bMagicDamageReturn,20; }",200,1000,BF_WEAPON,"{ specialeffect2 EF_REFLECTSHIELD; }"; }',NULL,NULL ); Edited December 26, 2011 by GreatWizard Quote Link to comment Share on other sites More sharing options...
Question
GreatWizard
Hello,
Here is the perl script that I have create with regular expressions to convert every database files from TXT to SQL.
So in your configuration conf/inter_athena.conf you can activate:
Perl script txt2sql (Don't forget to set this file executable) :
Uses:
Merry Christmas !
Edited by GreatWizardLink to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.