SQL表字段名为“Language”,给出了SQL错误 - delphi

时间:2016-08-08 17:31:40

标签: sql delphi insert

我正在为学校构建一个应用程序,以一种整洁和用户友好的方式显示和添加表格。在编写“添加新记录”部分时,我遇到了这个错误

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentBreadCrumbs fbc = (FragmentBreadCrumbs) findViewById(...);
    int color = ...;
    FragmentBreadCrumbsUtils.setTextColor(fbc, color);
}


public class FragmentBreadCrumbsUtils {

    private static final Field FRAGMENT_BREAD_CRUMBS_TEXT_COLOR = findField();
    private static Field findField() {
        try {
            Field f = FragmentBreadCrumbs.class.getDeclaredField("mTextColor");
            f.setAccessible(true);
            return f;
        } catch (Throwable t) {
            // don't fail for any reason, just log it
            Log.e("FragmentBreadCrumbsUtils",
                "Couldn't find mTextColor field in FragmentBreadCrumbs",
                t);
        }
        return null;
    }

    public static void setTextColor(FragmentBreadCrumbs fbc, int color) {
        if (FRAGMENT_BREAD_CRUMBS_TEXT_COLOR == null) {
            return; // can't do anything, we don't have the field
        }

        try {
            FRAGMENT_BREAD_CRUMBS_TEXT_COLOR.set(fbc, color);
        } catch (Throwable t) {
            // don't fail for any reason, just log it
            Log.e("FragmentBreadCrumbsUtils",
                "Couldn't set mTextColor field in FragmentBreadCrumbs",
                t);
        }
    }
}

我尝试通过手动浏览我输入的字段列表来修复它,发现即使这个字段与所有其他字段完全相同,也只有一个出错。如果我故意将字段拼写错误,我会收到另一个错误。我的代码看起来像这样:

webix.toExcel($$("table1"), $$("table2"));

请帮助,因为我一整天都在努力解决这个问题并且没有任何进展。

此致

1 个答案:

答案 0 :(得分:4)

[]或""向RDBM表示该词是列名而不是保留关键字。语言是SQL中的保留关键字。

为了更好的衡量,我还将参数名称更改为Lang,因为您将参数分配标识为问题位置。

with dmInfo do
begin
  qryInfo.SQL.Clear;
  qryInfo.SQL.Add('INSERT INTO tblGymnast');
  qryInfo.SQL.Add('(GymnastID, Surname, Name, NickName, FamilyID, PosCode, CellNo, SAGFID, Photo, StartDate, BirthDate, Gender, Race, Category, IDNum, UpgrdTo, SchoolID, LevelID, TransID, DokterID, MedNum, MedID, [Language])');

  qryInfo.SQL.Add(' VALUES(:GymnastID, :Surname, :Name, :NickName, :FamilyID, :PosCode, :CellNo, :SAGFID, :Photo, :StartDate, :BirthDate, :Gender, :Race, :Category, :IDNum, :UpgrdTo, :SchoolID, :LevelID, :TransID, :DokterID, :MedNum, :MedID, :Lang)');

      qryInfo.Parameters.ParamByName('GymnastID').Value:= 'a';
      qryInfo.Parameters.ParamByName('Surname').Value:= 'a';
      qryInfo.Parameters.ParamByName('Name').Value:= 'a';
      qryInfo.Parameters.ParamByName('NickName').Value:= 'a';
      qryInfo.Parameters.ParamByName('FamilyID').Value:= 'a';
      qryInfo.Parameters.ParamByName('PosCode').Value:= 'a';
      qryInfo.Parameters.ParamByName('CellNo').Value:= 'a';
      qryInfo.Parameters.ParamByName('SAGFID').Value:= 'a';
      qryInfo.Parameters.ParamByName('Photo').Value:= 'a';
      qryInfo.Parameters.ParamByName('StartDate').Value:= 'a';
      qryInfo.Parameters.ParamByName('BirthDate').Value:= 'a';
      qryInfo.Parameters.ParamByName('Gender').Value:= 'a';
      qryInfo.Parameters.ParamByName('Lang').Value:= 'a'; //This gives the error
      qryInfo.Parameters.ParamByName('Race').Value:= 'a';
      qryInfo.Parameters.ParamByName('Category').Value:= 'a';
      qryInfo.Parameters.ParamByName('IDNum').Value:= 'a';
      qryInfo.Parameters.ParamByName('UpgrdTo').Value:= 'a';
      qryInfo.Parameters.ParamByName('SchoolID').Value:= 'a';
      qryInfo.Parameters.ParamByName('LevelID').Value:= 'a';
      qryInfo.Parameters.ParamByName('TransID').Value:= 'a';
      qryInfo.Parameters.ParamByName('DokterID').Value:= 'a';
      qryInfo.Parameters.ParamByName('MedNum').Value:= 'a';
      qryInfo.Parameters.ParamByName('MedID').Value:= 'a';

  qryInfo.ExecSQL;
end;