Changeset 359 for tools/dbc_export/DBCExport.pas
- Timestamp:
- Mar 5, 2010, 8:46:18 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/dbc_export/DBCExport.pas
r348 r359 7 7 cthreads, 8 8 {$ENDIF}{$ENDIF} 9 Classes, SysUtils, CustApp 10 { you can add units after this }, 9 Classes, SysUtils, CustApp, 11 10 USqlDatabase, UDBC, Variants; 12 11 … … 27 26 IndexTable: array of integer; 28 27 SQLquery: string; 29 CharSet: string;30 28 DisplayData: Boolean; 31 29 constructor Create(TheOwner: TComponent); override; … … 37 35 procedure ReplaceText; 38 36 procedure CreateIndexTable(var DbRows: TDbRows); 39 function GetIDbyEntry( entry: integer; var DBRows: TDBRows): integer;37 function GetIDbyEntry(Entry: Integer; var DBRows: TDBRows): Integer; 40 38 end; 41 39 … … 79 77 end else Database.Hostname := 'localhost'; 80 78 if HasOption('a', 'Charset') then begin 81 Charset:= GetOptionValue('a', 'Charset');82 end else Charset:= 'utf8';79 Database.Encoding := GetOptionValue('a', 'Charset'); 80 end else Database.Encoding := 'utf8'; 83 81 if HasOption('q', 'sql_query') then begin 84 82 SQLquery := GetOptionValue('q', 'sql_query'); … … 89 87 begin 90 88 ParseParameters; 91 92 89 LoadDBC; 93 94 90 ShowDBC; 95 96 91 ReplaceText; 97 98 92 SaveDBC; 99 100 // Stop program loop 101 Terminate; 93 Terminate; // Stop program loop 102 94 end; 103 95 … … 128 120 WriteLn(' -c --coltypedef DBC column type definition string (u - uint32, s - string)'); 129 121 WriteLn(' -d --display Display DBC data'); 130 WriteLn(' -q --sql_query SQL select when entry is ID first column in dbc file and text1,text2... is texts columns');122 WriteLn(' -q --sql_query SQL select when entry is ID first column in dbc file and text1,text2... is texts columns'); 131 123 // SELECT T.entry as entry,T.Text as text1 FROM (SELECT * FROM gametips WHERE (Complete = 1) AND ((Language = 1)) AND (User IN (459,670,602,462,1,400,638,592,624,610,769,331,131,704,2,499,641,660,578,337,304,277,208,613,768,754,590,606,26,618,739,503,601,607,585,596,765,320,547,687)) AND VersionStart <= 9947 AND VersionEnd >= 9947) AS T GROUP BY T.entry 132 124 end; … … 165 157 LastIndexStringColumns:=I; 166 158 end; 167 168 169 159 end else WriteLn('File ' + DBCFileName + ' not exists.'); 170 160 end; … … 180 170 end; 181 171 182 183 //function get data from database and replace text in dbc 172 // Function get data from database and replace text in DBC 184 173 procedure TDBCExport.ReplaceText; 185 174 var 186 175 DBRows : TDbRows; 187 Text: String;188 X, Y, I, entry: Integer;176 Text: string; 177 X, Y, I, Entry: Integer; 189 178 IndexRowData: Integer; 190 179 begin 191 180 with DBC do begin 192 if (SQLquery <> '') then begin; 193 181 if (SQLquery <> '') then begin 194 182 Database.Connect; 195 // Database.Query('CHARACTER SET '+CharSet);196 Database.Query('SET NAMES '+CharSet);197 183 DBRows := Database.Query(SQLquery); 198 CharSet:=Database.Charset;199 184 200 185 CreateIndexTable(DBRows); 201 186 202 203 187 for Y := 0 to Length(DBC.Cells) - 1 do begin 204 entry :=Cells[Y,0]; 205 if (Length(IndexTable) > entry) then 206 IndexRowData:= IndexTable[entry] 207 else IndexRowData:= 0; 208 209 I := 1; 210 188 Entry := Cells[Y, 0]; 189 if (Length(IndexTable) > Entry) then 190 IndexRowData := IndexTable[entry] 191 else IndexRowData := 0; 192 193 I := 1; 211 194 if (IndexRowData <> 0) then begin 212 195 for X := 1 to Length(ColumnTypeDefinition) do begin 213 196 if ColumnTypeDefinition[X] = 's' then begin 214 Text:=DBRows.Data[IndexRowData-1].Values['text'+IntToStr(I)]; 215 SetString(Y,X-1,Text); 216 I:=I+1; 217 if (LastIndexStringColumns = X) then 218 Break; 197 Text := DBRows.Data[IndexRowData - 1].Values['text' + IntToStr(I)]; 198 SetString(Y, X - 1, Text); 199 I := I + 1; 200 if (LastIndexStringColumns = X) then Break; 219 201 end; 220 202 end; 221 203 end; 222 223 204 end; 224 225 226 205 DBRows.Destroy; 227 206 end; 228 207 end; 229 208 end; 230 209 231 // create table index = entry, value = Index-1 DBRows, notfound = 0210 // Create table index = entry, value = Index-1 DBRows, notfound = 0 232 211 procedure TDBCExport.CreateIndexTable(var DbRows: TDbRows); 233 212 var 234 i: integer;235 Count,entry: integer;213 I: Integer; 214 Count, Entry: Integer; 236 215 begin 237 216 try 238 Count:=DBRows.Count; 239 for i:=1 to Count do begin 240 entry:=StrToInt(DBRows.Data[i-1].Values['entry']); 241 242 if (i =127) then 243 SetLength(IndexTable,entry+1); 244 245 if (Length(IndexTable)-1 < entry) then 246 SetLength(IndexTable,entry+1); 247 248 249 IndexTable[entry]:=i; 250 217 Count := DBRows.Count; 218 for I := 1 to Count do begin 219 Entry := StrToInt(DBRows.Data[i - 1].Values['entry']); 220 221 if (I = 127) then SetLength(IndexTable, Entry + 1); 222 223 if (Length(IndexTable) - 1 < Entry) then 224 SetLength(IndexTable, Entry + 1); 225 226 IndexTable[Entry] := I; 251 227 end; 252 228 except … … 254 230 end; 255 231 256 function TDBCExport.GetIDbyEntry(entry: integer; var DBRows: TDBRows): integer; 257 var 258 i: integer; 259 Count: integer; 232 function TDBCExport.GetIDbyEntry(Entry: Integer; var DBRows: TDBRows): Integer; 233 var 234 I: Integer; 260 235 begin 261 236 try 262 Count:=DBRows.Count; 263 for i:=0 to DBRows.Count - 1 do begin 264 if (StrToInt(DBRows.Data[i].Values['entry']) = entry) then begin 265 Result := i; 266 exit; 237 for I := 0 to DBRows.Count - 1 do begin 238 if (StrToInt(DBRows.Data[i].Values['entry']) = Entry) then begin 239 Result := I; 240 Exit; 267 241 end; 268 242 end;
Note:
See TracChangeset
for help on using the changeset viewer.