Changeset 31 for trunk/UAcronym.pas
- Timestamp:
- Jul 13, 2016, 10:34:13 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UAcronym.pas
r30 r31 7 7 uses 8 8 Classes, SysUtils, Contnrs, XMLConf, XMLRead, XMLWrite, DOM, UXMLUtils, 9 SpecializedList, fphttpclient, Dialogs ;9 SpecializedList, fphttpclient, Dialogs, odbcconn, sqldb; 10 10 11 11 type … … 132 132 end; 133 133 134 TImportFormatKind = (ifkParse, ifkMSAccess); 135 134 136 { TImportFormat } 135 137 … … 137 139 Id: Integer; 138 140 Name: string; 141 Kind: TImportFormatKind; 139 142 Block: TImportPattern; 140 143 ItemPatterns: TImportPatterns; … … 172 175 function DownloadHTTP(URL: string; Stream: TStream): Boolean; 173 176 procedure Process; 177 procedure ProcessTextParse; 178 procedure ProcessMSAccess; 174 179 procedure Assign(Source: TImportSource); 175 180 procedure SaveToNode(Node: TDOMNode); … … 230 235 end; 231 236 237 { TImportSourceMSAccess } 238 239 procedure TImportSource.ProcessMSAccess; 240 var 241 ODBCConnection1: TODBCConnection; 242 SQLTransaction1: TSQLTransaction; 243 SQLQuery1: TSQLQuery; 244 NewAcronym: TAcronymEntry; 245 begin 246 ItemCount := 0; 247 ODBCConnection1 := TODBCCOnnection.Create(nil); 248 SQLQuery1 := TSQLQuery.Create(nil); 249 SQLTransaction1 := TSQLTransaction.Create(nil); 250 try 251 ODBCConnection1.Driver := 'Microsoft Access Driver (*.mdb, *.accdb)'; 252 ODBCConnection1.Params.Add('DBQ=' + URL); 253 ODBCConnection1.Params.Add('Locale Identifier=1031'); 254 ODBCConnection1.Params.Add('ExtendedAnsiSQL=1'); 255 ODBCConnection1.Params.Add('CHARSET=ansi'); 256 ODBCConnection1.Connected := True; 257 ODBCConnection1.KeepConnection := True; 258 259 SQLTransaction1.DataBase := ODBCConnection1; 260 SQLTransaction1.Action := caCommit; 261 SQLTransaction1.Active := True; 262 263 SQLQuery1.DataBase := ODBCConnection1; 264 SQLQuery1.UsePrimaryKeyAsKey := False; 265 SQLQuery1.SQL.Text := 'SELECT Acronym,Meaning FROM data1'; 266 SQLQuery1.Open; 267 268 NewAcronym := TAcronymEntry.Create; 269 while not SQLQuery1.EOF do begin 270 NewAcronym.Name := SQLQuery1.FieldByName('Acronym').AsString; 271 NewAcronym.Meaning := SQLQuery1.FieldByName('Meaning').AsString; 272 Sources.AcronymDb.AddAcronym(NewAcronym.Name, NewAcronym.Meaning); 273 SQLQuery1.Next; 274 Inc(ItemCount); 275 end; 276 NewAcronym.Free; 277 finally 278 SQLQuery1.Free; 279 SQLTransaction1.Free; 280 ODBCConnection1.Free; 281 end; 282 end; 283 232 284 { TImportPatterns } 233 285 … … 321 373 end; 322 374 375 procedure TImportSource.Process; 376 begin 377 case Format.Kind of 378 ifkParse: ProcessTextParse; 379 ifkMSAccess: ProcessMSAccess; 380 else raise Exception.Create('Unsupported import format'); 381 end; 382 end; 383 323 384 function StripHTML(S: string): string; 324 385 var … … 346 407 I: Integer; 347 408 begin 409 Kind := Source.Kind; 348 410 Name := Source.Name; 349 411 Block.StartString := Source.Block.StartString; … … 364 426 WriteInteger(Node, 'Id', Id); 365 427 WriteString(Node, 'Name', Name); 428 WriteInteger(Node, 'Kind', Integer(Kind)); 366 429 WriteString(Node, 'BlockStartString', Block.StartString); 367 430 WriteString(Node, 'BlockEndString', Block.EndString); … … 378 441 Id := ReadInteger(Node, 'Id', 0); 379 442 Name := ReadString(Node, 'Name', ''); 443 Kind := TImportFormatKind(ReadInteger(Node, 'Kind', 0)); 380 444 Block.StartString := ReadString(Node, 'BlockStartString', ''); 381 445 Block.EndString := ReadString(Node, 'BlockEndString', ''); … … 513 577 { TImportSource } 514 578 515 procedure TImportSource.Process ;579 procedure TImportSource.ProcessTextParse; 516 580 var 517 581 Stream: TMemoryStream;
Note:
See TracChangeset
for help on using the changeset viewer.