Einzelnen Beitrag anzeigen

JRichmann

Registriert seit: 8. Dez 2009
Ort: Pattensen
57 Beiträge
 
Delphi XE5 Architect
 
#3

AW: MySQL Duplicate Entry Auto-Inc

  Alt 29. Dez 2015, 15:19
Ja... aber es ist aufgrund der Struktur der Klassen und Threads sicher nicht so sehr einfach lesbar bzw. verständlich.

Delphi-Quellcode:
function TSQLObjectRTTI.ComposeInsert(cl: TClass; idFieldName: String;
  forceId: Boolean): String;
var
  sep: String;
  fieldInfo: TFieldInfo;
  rttiType: TRttiType;
  props: TArray<TRttiProperty>;
  prop: TRttiProperty;
  fields, values: String;
begin
  rttiType := GetTypeInfo(cl);

  fields := '';
  values := '';

  props := rttiType.GetProperties;
  for prop in props do
  begin
    if prop.Visibility = TMemberVisibility.mvPublished then
      if not IsBlob(prop.PropertyType) then
      begin
        if fields <> 'then sep := ' , ';
        if SameText(idFieldName, prop.Name) then
        begin
          if forceId then
          begin
            fields := fields + sep + '`' + prop.Name + '`';
            values := values + sep + ':' + prop.Name;
          end;
        end
        else
        begin
          fields := fields + sep + '`' + prop.Name + '`';
          values := values + sep + ':' + prop.Name;
        end;
      end;
  end;


  Result := Format('INSERT INTO %s (%s) VALUES (%s)',
                    [
                      ClassToTableName(cl),
                      fields,
                      values
                    ]);
end;
Jörg Richmann

Geändert von TBx (31. Dez 2015 um 09:20 Uhr) Grund: Delphi-Tags eingefügt
  Mit Zitat antworten Zitat