Changeset 340 for tools/dbc_export/DBCExport.pas
- Timestamp:
- Feb 27, 2010, 6:25:07 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/dbc_export/DBCExport.pas
r339 r340 24 24 NewDBCFileName: string; 25 25 ColumnTypeDefinition: string; 26 SQLquery: string; 26 27 DisplayData: Boolean; 27 28 constructor Create(TheOwner: TComponent); override; … … 29 30 procedure WriteHelp; virtual; 30 31 procedure ShowDBC; 32 procedure LoadDBC; 33 procedure SaveDBC; 34 procedure ReplaceText; 35 function GetIDbyEntry(entry: integer; var DBRows: TDBRows): integer; 31 36 end; 32 37 … … 69 74 Database.Hostname := GetOptionValue('t', 'host'); 70 75 end else Database.Hostname := 'localhost'; 76 if HasOption('q', 'sql_query') then begin 77 SQLquery := GetOptionValue('q', 'sql_query'); 78 end; 71 79 end; 72 80 … … 74 82 begin 75 83 ParseParameters; 84 85 LoadDBC; 86 76 87 ShowDBC; 88 89 ReplaceText; 90 91 SaveDBC; 77 92 78 93 // Stop program loop … … 105 120 WriteLn(' -c --coltypedef DBC column type definition string (u - uint32, s - string)'); 106 121 WriteLn(' -d --display Display DBC data'); 122 WriteLn(' -q --sql_query SQL select when entry is ID first column in dbc file and text0,text1... is texts columns'); 123 // SELECT T.entry as entry,T.Text as text0 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 107 124 end; 108 125 … … 111 128 X, Y: Integer; 112 129 Text: string; 113 I: Integer; 114 begin 115 DBC := TDBC.Create; 116 with DBC do begin 117 if FileExists(DBCFileName) then begin 118 LoadFromFile(DBCFileName); 119 120 // Load strings for string columns 121 for I := 1 to Length(ColumnTypeDefinition) do 122 if ColumnTypeDefinition[I] = 's' then 123 LoadColumnStrings(I - 1); 124 130 begin 131 with DBC do begin 125 132 // Display DBC data 126 133 if DisplayData then … … 132 139 WriteLn(Text); 133 140 end; 134 135 SaveToFile(NewDBCFileName); 141 end; 142 end; 143 144 procedure TDBCExport.LoadDBC; 145 var 146 I: Integer; 147 begin 148 DBC := TDBC.Create; 149 with DBC do begin 150 if FileExists(DBCFileName) then begin 151 LoadFromFile(DBCFileName); 152 153 // Load strings for string columns 154 for I := 1 to Length(ColumnTypeDefinition) do 155 if ColumnTypeDefinition[I] = 's' then 156 LoadColumnStrings(I - 1); 157 136 158 end else WriteLn('File ' + DBCFileName + ' not exists.'); 159 end; 160 end; 161 162 procedure TDBCExport.SaveDBC; 163 begin 164 with DBC do begin 165 SaveToFile(NewDBCFileName); 137 166 Free; 138 167 end; 168 end; 169 170 171 //function get data from database and replace text in dbc 172 procedure TDBCExport.ReplaceText; 173 var 174 DBRows : TDbRows; 175 Text: String; 176 X, Y, I: Integer; 177 IndexRowData: Integer; 178 begin 179 with DBC do begin 180 if (SQLquery <> '') then begin; 181 Database.Connect; 182 DBRows := Database.Query(SQLquery); 183 184 185 for Y := 0 to Length(DBC.Cells) - 1 do begin 186 if (Y = 129) then 187 IndexRowData:= GetIDbyEntry(Cells[Y,0],DBRows); 188 IndexRowData:= GetIDbyEntry(Cells[Y,0],DBRows); 189 I := 0; 190 if (IndexRowData <> -1) then begin 191 for X := 0 to Length(ColumnTypeDefinition)-1 do begin 192 if ColumnTypeDefinition[X+1] = 's' then begin 193 Text:=DBRows.Data[IndexRowData].Values['text'+IntToStr(I)]; 194 SetString(Y,X,Text); 195 I:=I+1; 196 end; 197 end; 198 DBRows.Delete(IndexRowData); 199 end; 200 end; 201 202 203 204 end; 205 end; 206 end; 207 208 function TDBCExport.GetIDbyEntry(entry: integer; var DBRows: TDBRows): integer; 209 var 210 i: integer; 211 Count: integer; 212 begin 213 try 214 Count:=DBRows.Count; 215 for i:=0 to DBRows.Count - 1 do begin 216 if (StrToInt(DBRows.Data[i].Values['entry']) = entry) then begin 217 Result := i; 218 exit; 219 end; 220 end; 221 except 222 end; 223 Result := -1; 139 224 end; 140 225
Note:
See TracChangeset
for help on using the changeset viewer.