无法将字符串作为SQLite ExecSQL命令传递

时间:2014-08-18 16:18:03

标签: sqlite delphi

在尝试执行ExecSQL()语句时,我一直收到错误:接近" PassWord":语法错误。该命令在文本文件的输出中看起来很好。事实上,我复制了&将命令直接粘贴到SQLite数据库浏览器中并正确执行该命令。以下是产生错误的代码:

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;

这是执行的实际命令: 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)

1 个答案:

答案 0 :(得分:1)

您没有执行sExecSQL,而是sFieldList