Changeset 13 for trunk/DbEngines/UEngineXML.pas
- Timestamp:
- Mar 17, 2015, 12:09:11 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DbEngines/UEngineXML.pas
r12 r13 7 7 uses 8 8 Classes, SysUtils, DOM, XMLRead, XMLWrite, UDatabase, UXMLUtils, FileUtil, 9 UHtmlClasses ;9 UHtmlClasses, USqlDatabase, SpecializedDictionary; 10 10 11 11 type … … 29 29 procedure LoadFromFile(FileName: string); 30 30 procedure SaveToFile(FileName: string); 31 function GetNextPart(var Text: string): string; 31 32 public 33 procedure Query(DbRows: TDbRows; Text: string); override; 32 34 procedure Load; override; 33 35 procedure Save; override; … … 280 282 end; 281 283 284 function TDatabaseXML.GetNextPart(var Text: string): string; 285 begin 286 if Pos(' ', Text) > 0 then begin 287 Result := Trim(Copy(Text, 1, Pos(' ', Text) - 1)); 288 Delete(Text, 1, Pos(' ', Text)); 289 end else begin 290 Result := Text; 291 Text := ''; 292 end; 293 end; 294 295 procedure TDatabaseXML.Query(DbRows: TDbRows; Text: string); 296 var 297 Command: string; 298 Columns: string; 299 TableName: string; 300 Table: TTable; 301 NewRecord: TDictionaryStringString; 302 I: Integer; 303 F: Integer; 304 begin 305 Command := GetNextPart(Text); 306 if Command = 'SELECT' then begin 307 Columns := GetNextPart(Text); 308 Command := GetNextPart(Text); 309 if Command = 'FROM' then begin 310 TableName := GetNextPart(Text); 311 end; 312 Table := Database.Tables.SearchByName(TableName); 313 if Assigned(Table) then begin 314 DbRows.Count := 0; 315 if Columns = '*' then begin 316 for I := 0 to Table.Records.Count - 1 do begin 317 NewRecord := TDictionaryStringString.Create; 318 for F := 0 to Table.Fields.Count - 1 do 319 NewRecord.Add(TField(Table.Fields[F]).Name, TValue(TRecord(Table.Records[I]).Values[I]).GetString); 320 DbRows.Add(NewRecord); 321 end; 322 end else 323 if Columns = 'COUNT(*)' then begin 324 NewRecord := TDictionaryStringString.Create; 325 NewRecord.Add('COUNT(*)', IntToStr(Table.Records.Count)); 326 DbRows.Add(NewRecord); 327 end else raise Exception.Create('Unsupported columns ' + Columns + ' specification'); 328 end else raise Exception.Create('Table ' + TableName + ' not found.'); 329 end else raise Exception.Create('Unsupported SQL command ' + Command); 330 end; 331 282 332 procedure TDatabaseXML.Load; 283 333 begin
Note:
See TracChangeset
for help on using the changeset viewer.