DELPHI - Change sql text

hello,
I use this script to create a database, the script is saved in a file.sql, I change the name of the database "db1" to "db2" or "db3" or whatever, maybe I should work on the file. sql but I experience to do so.
SET FOREIGN_KEY_CHECKS=0;

DROP DATABASE IF EXISTS `db1`;

CREATE DATABASE `db1`
    CHARACTER SET 'latin1'
    COLLATE 'latin1_swedish_ci';

USE `db1`;

DROP TABLE IF EXISTS `accessori`;

CREATE TABLE `accessori` (
  `idAccessori` int(10) NOT NULL auto_increment,
  `Accessori` varchar(50) default NULL,
  PRIMARY KEY  (`idAccessori`),
  UNIQUE KEY `idAccessori` (`idAccessori`)
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=latin1;

Open in new window

danz67Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
Hi there,

What do you need?
The above is mysql code, do you want to convert to Oracle/MS SQL Server/Firebird/BlackfishSQL?
0
danz67Author Commented:
I wrote the code that is saved to a file that is loaded from a component and then executed.
Should I just change the name of the database working directly on the file that contains the script, the file is db.sql (I think like a file.txt)
0
cyberkiwiCommented:
I see, if a component is linked to the file, thus loading and executing it, then you are better off making changes to the file directly. For such a small file, you can use TStringList.LoadFromFile, update it then SaveToFile to close it.
0
danz67Author Commented:
Ok but how update the file?
0
cyberkiwiCommented:
Here's a sample

var
  sl: TStringList;
begin
  sl := TStringList.Create;
  try
    sl.LoadFromFile("filename.txt");
    sl.Text := StringReplace(sl.Text, '`db1`', '`db2`', [rfReplaceAll]);
    sl.SaveToFile("filename.txt");
  finally
    sl.Free;
  end;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.