Help with writing sql statement to a log file

[b][red]This message was edited by rnojoe23 at 2006-9-12 11:56:53[/red][/b][hr]
I am running a script that inserts records into a SQL 2000 database. I am getting a syntax error and the record fails to make it into the database. I would like to be able to see the whole sql statement so I can determine why its not getting written to the database.

my question is. how do I write a big long sql statement to the log file so I can see it.

here is some of my code

strRet: String;
stlSql: TStringList;

Begin
Writeln(mfilLog,'Starting import of records');

stlSql.Clear
stlSql.Add(INSERT INTO TableA VALUES;
stlSql.Add(more);
stlSql.Add(Even more)
stlSql.Add(lots more)

frmdb.RunTheSql(stlSql,strRet);
If StrRet <> '' then
begin
Writeln(mfilLog,'Unable to insert Record:'+
strFieldA+'/'+strFieldB);
Writeln(mfilLog,' '+StrRet);

The log file reads

Unable to insert Record:12345/AB
[Microsoft][ODBC SQL Server Driver][SQL Server} Line 2: Incorrect syntax near ",".

I tried to add Writeln(mfilLog,' '+stlSql); but that would not compile giving me a "main.pas(785): Incompatible types: 'String' and 'TStringList'. error

Can anyone help me write the stlSql statement to the log file so I can see the exact record that the script is trying to insert into the database

I am running Delphi Version 3

Thank you very much

joe

Comments

  • : [b][red]This message was edited by rnojoe23 at 2006-9-12 11:56:53[/red][/b][hr]
    : I am running a script that inserts records into a SQL 2000 database. I am getting a syntax error and the record fails to make it into the database. I would like to be able to see the whole sql statement so I can determine why its not getting written to the database.
    :
    : my question is. how do I write a big long sql statement to the log file so I can see it.
    :
    : here is some of my code
    :
    : strRet: String;
    : stlSql: TStringList;
    :
    : Begin
    : Writeln(mfilLog,'Starting import of records');
    :
    : stlSql.Clear
    : stlSql.Add(INSERT INTO TableA VALUES;
    : stlSql.Add(more);
    : stlSql.Add(Even more)
    : stlSql.Add(lots more)
    :
    : frmdb.RunTheSql(stlSql,strRet);
    : If StrRet <> '' then
    : begin
    : Writeln(mfilLog,'Unable to insert Record:'+
    : strFieldA+'/'+strFieldB);
    : Writeln(mfilLog,' '+StrRet);
    :
    : The log file reads
    :
    : Unable to insert Record:12345/AB
    : [Microsoft][ODBC SQL Server Driver][SQL Server} Line 2: Incorrect syntax near ",".
    :
    : I tried to add Writeln(mfilLog,' '+stlSql); but that would not compile giving me a "main.pas(785): Incompatible types: 'String' and 'TStringList'. error
    :
    : Can anyone help me write the stlSql statement to the log file so I can see the exact record that the script is trying to insert into the database
    :
    : I am running Delphi Version 3
    :
    : Thank you very much
    :
    : joe
    :
    The TStrings object has a Text property, which holds the complete text in all the lines. The write statement should read:
    [code]
    Writeln(mfilLog,' '+stlSql.Text);
    [/code]
    Also beware that the log will increase with each added line. To remove the line endings from the sql statement, use the StringReplace() function.
  • : : [b][red]This message was edited by rnojoe23 at 2006-9-12 11:56:53[/red][/b][hr]
    : : I am running a script that inserts records into a SQL 2000 database. I am getting a syntax error and the record fails to make it into the database. I would like to be able to see the whole sql statement so I can determine why its not getting written to the database.
    : :
    : : my question is. how do I write a big long sql statement to the log file so I can see it.
    : :
    : : here is some of my code
    : :
    : : strRet: String;
    : : stlSql: TStringList;
    : :
    : : Begin
    : : Writeln(mfilLog,'Starting import of records');
    : :
    : : stlSql.Clear
    : : stlSql.Add(INSERT INTO TableA VALUES;
    : : stlSql.Add(more);
    : : stlSql.Add(Even more)
    : : stlSql.Add(lots more)
    : :
    : : frmdb.RunTheSql(stlSql,strRet);
    : : If StrRet <> '' then
    : : begin
    : : Writeln(mfilLog,'Unable to insert Record:'+
    : : strFieldA+'/'+strFieldB);
    : : Writeln(mfilLog,' '+StrRet);
    : :
    : : The log file reads
    : :
    : : Unable to insert Record:12345/AB
    : : [Microsoft][ODBC SQL Server Driver][SQL Server} Line 2: Incorrect syntax near ",".
    : :
    : : I tried to add Writeln(mfilLog,' '+stlSql); but that would not compile giving me a "main.pas(785): Incompatible types: 'String' and 'TStringList'. error
    : :
    : : Can anyone help me write the stlSql statement to the log file so I can see the exact record that the script is trying to insert into the database
    : :
    : : I am running Delphi Version 3
    : :
    : : Thank you very much
    : :
    : : joe
    : :
    : The TStrings object has a Text property, which holds the complete text in all the lines. The write statement should read:
    : [code]
    : Writeln(mfilLog,' '+stlSql.Text);
    : [/code]
    : Also beware that the log will increase with each added line. To remove the line endings from the sql statement, use the StringReplace() function.
    :


    It Worked, Thank you very very much
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories