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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.