Trouble passing a string as a SQLite ExecSQL command

Posted by Hackbrew on Stack Overflow See other posts from Stack Overflow or by Hackbrew
Published on 2014-08-18T16:18:02Z Indexed on 2014/08/18 16:21 UTC
Read the original article Hit count: 251

Filed under:
|

I keep getting the ERROR: near "PassWord": syntax error when trying to execute the ExecSQL() statement. The command looks good in the output of the text file. In fact, I copied & pasted the command directly into SQLite Database Browser and the commend executed properly. Here's the code that's producing the error:

procedure TForm1.Button1Click(Sender: TObject);
var i, iFieldSize: integer;
    sFieldName, sFieldType, sFieldList, sExecSQL: String;
    names: TStringList;
    f1: Textfile;
begin
  //Open Source table - Table1 has 8 fields but has only two different field types ftString and Boolean
  Table1.TableName:= 'PWFile';
  Table1.Open;
  //FDConnection1.ExecSQL('drop table PWFile');
  sFieldList := '';
  names := TStringList.Create;
  for i := 0 to Table1.FieldCount - 1 do
    begin
      sFieldName := Table1.FieldDefList.FieldDefs[i].Name;
      sFieldType := GetEnumName(TypeInfo(TFieldType),ord(Table1.FieldDefList.FieldDefs[i].DataType));
      iFieldSize := Table1.FieldDefList.FieldDefs[i].Size;
      if sFieldType = 'ftString' then sFieldType := 'NVARCHAR' + '(' + IntToStr(iFieldSize) + ')';
      if sFieldType = 'ftBoolean' then sFieldType := 'INTEGER';
      names.Add(sFieldName + ' ' + sFieldType);
      if sFieldList = '' then sFieldList := sFieldName + ' ' + sFieldType
       else sFieldList := sFieldList + ', ' + sFieldName + ' ' + sFieldType;
    end;
  ListBox1.Items.Add(sFieldList);
  sExecSQL := 'create table IF NOT EXISTS PWFile (' + sFieldList + ')';
  // 08/18/2014 - Entered this to log the SQLite FDConnection1.ExecSQL Command to a file
  AssignFile(f1, 'C:\Users\Test User\Documents\SQLite_Command.txt');
  Rewrite(f1);
  Writeln(f1, sExecSQL);
    { insert code here that would require a Flush before closing the file }
  Flush(f1);  { ensures that the text was actually written to file }
  CloseFile(f1);
  FDConnection1.ExecSQL(sFieldList);
  Table1.Close;
end;

Here's the actual command that gets executed: create table IF NOT EXISTS PWFile (PassWord NVARCHAR(10), PassName NVARCHAR(10), Dept NVARCHAR(10), Active NVARCHAR(1), Admin INTEGER, Shred INTEGER, Reports INTEGER, Maintain INTEGER)

© Stack Overflow or respective owner

Related posts about sqlite

Related posts about delphi