- Timestamp:
- Mar 5, 2010, 8:46:18 AM (15 years ago)
- Location:
- tools/dbc_export
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/dbc_export/DBCExport.lpi
r348 r359 2 2 <CONFIG> 3 3 <ProjectOptions> 4 <PathDelim Value="/"/>5 4 <Version Value="7"/> 6 5 <General> … … 17 16 <Language Value=""/> 18 17 <CharSet Value=""/> 18 <StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion="0.0.0.0"/> 19 19 </VersionInfo> 20 20 <PublishOptions> … … 31 31 </local> 32 32 </RunParams> 33 <Units Count="1 5">33 <Units Count="17"> 34 34 <Unit0> 35 35 <Filename Value="DBCExport.pas"/> 36 36 <IsPartOfProject Value="True"/> 37 37 <UnitName Value="DBCExport"/> 38 <CursorPos X=" 1" Y="196"/>39 <TopLine Value="1 74"/>38 <CursorPos X="57" Y="16"/> 39 <TopLine Value="144"/> 40 40 <EditorIndex Value="0"/> 41 <UsageCount Value=" 79"/>41 <UsageCount Value="80"/> 42 42 <Loaded Value="True"/> 43 43 <SyntaxHighlighter Value="Delphi"/> … … 115 115 <IsPartOfProject Value="True"/> 116 116 <UnitName Value="USqlDatabase"/> 117 <CursorPos X=" 1" Y="181"/>118 <TopLine Value=" 159"/>117 <CursorPos X="22" Y="166"/> 118 <TopLine Value="276"/> 119 119 <EditorIndex Value="3"/> 120 <UsageCount Value="7 0"/>120 <UsageCount Value="71"/> 121 121 <Loaded Value="True"/> 122 122 <SyntaxHighlighter Value="Delphi"/> … … 129 129 <TopLine Value="89"/> 130 130 <EditorIndex Value="1"/> 131 <UsageCount Value="7 0"/>131 <UsageCount Value="71"/> 132 132 <Loaded Value="True"/> 133 133 <SyntaxHighlighter Value="Delphi"/> … … 139 139 <TopLine Value="1"/> 140 140 <EditorIndex Value="2"/> 141 <UsageCount Value="7 0"/>141 <UsageCount Value="71"/> 142 142 <Loaded Value="True"/> 143 143 <SyntaxHighlighter Value="None"/> … … 150 150 <UsageCount Value="12"/> 151 151 </Unit14> 152 <Unit15> 153 <Filename Value="/usr/share/fpcsrc/rtl/objpas/classes/classesh.inc"/> 154 <CursorPos X="14" Y="253"/> 155 <TopLine Value="234"/> 156 <UsageCount Value="10"/> 157 </Unit15> 158 <Unit16> 159 <Filename Value="/usr/share/fpcsrc/rtl/objpas/classes/lists.inc"/> 160 <CursorPos X="3" Y="544"/> 161 <TopLine Value="542"/> 162 <UsageCount Value="10"/> 163 </Unit16> 152 164 </Units> 153 <JumpHistory Count=" 30" HistoryIndex="29">165 <JumpHistory Count="28" HistoryIndex="27"> 154 166 <Position1> 155 167 <Filename Value="DBCExport.pas"/> 156 <Caret Line=" 203" Column="1" TopLine="189"/>168 <Caret Line="193" Column="16" TopLine="171"/> 157 169 </Position1> 158 170 <Position2> 159 171 <Filename Value="DBCExport.pas"/> 160 <Caret Line=" 204" Column="1" TopLine="190"/>172 <Caret Line="198" Column="37" TopLine="171"/> 161 173 </Position2> 162 174 <Position3> 163 <Filename Value=" DBCExport.pas"/>164 <Caret Line=" 205" Column="1" TopLine="191"/>175 <Filename Value="USqlDatabase.pas"/> 176 <Caret Line="4" Column="18" TopLine="1"/> 165 177 </Position3> 166 178 <Position4> 167 <Filename Value=" DBCExport.pas"/>168 <Caret Line=" 206" Column="1" TopLine="192"/>179 <Filename Value="USqlDatabase.pas"/> 180 <Caret Line="52" Column="24" TopLine="30"/> 169 181 </Position4> 170 182 <Position5> 171 <Filename Value=" DBCExport.pas"/>172 <Caret Line=" 29" Column="5" TopLine="1"/>183 <Filename Value="USqlDatabase.pas"/> 184 <Caret Line="80" Column="45" TopLine="58"/> 173 185 </Position5> 174 186 <Position6> 175 <Filename Value=" DBCExport.pas"/>176 <Caret Line=" 80" Column="18" TopLine="58"/>187 <Filename Value="USqlDatabase.pas"/> 188 <Caret Line="137" Column="21" TopLine="115"/> 177 189 </Position6> 178 190 <Position7> 179 191 <Filename Value="DBCExport.pas"/> 180 <Caret Line=" 81" Column="42" TopLine="59"/>192 <Caret Line="212" Column="30" TopLine="190"/> 181 193 </Position7> 182 194 <Position8> 183 <Filename Value=" USqlDatabase.pas"/>184 <Caret Line=" 34" Column="14" TopLine="8"/>195 <Filename Value="DBCExport.pas"/> 196 <Caret Line="197" Column="32" TopLine="191"/> 185 197 </Position8> 186 198 <Position9> 187 <Filename Value=" USqlDatabase.pas"/>188 <Caret Line=" 52" Column="24" TopLine="30"/>199 <Filename Value="DBCExport.pas"/> 200 <Caret Line="195" Column="1" TopLine="173"/> 189 201 </Position9> 190 202 <Position10> 191 203 <Filename Value="USqlDatabase.pas"/> 192 <Caret Line=" 80" Column="45" TopLine="54"/>204 <Caret Line="181" Column="1" TopLine="159"/> 193 205 </Position10> 194 206 <Position11> 195 207 <Filename Value="USqlDatabase.pas"/> 196 <Caret Line="1 37" Column="21" TopLine="115"/>208 <Caret Line="183" Column="1" TopLine="161"/> 197 209 </Position11> 198 210 <Position12> 199 <Filename Value=" DBCExport.pas"/>200 <Caret Line=" 96" Column="7" TopLine="55"/>211 <Filename Value="USqlDatabase.pas"/> 212 <Caret Line="184" Column="1" TopLine="162"/> 201 213 </Position12> 202 214 <Position13> 203 <Filename Value=" DBCExport.pas"/>204 <Caret Line="1 93" Column="16" TopLine="171"/>215 <Filename Value="USqlDatabase.pas"/> 216 <Caret Line="186" Column="1" TopLine="164"/> 205 217 </Position13> 206 218 <Position14> 207 <Filename Value=" DBCExport.pas"/>208 <Caret Line="1 98" Column="37" TopLine="171"/>219 <Filename Value="USqlDatabase.pas"/> 220 <Caret Line="188" Column="1" TopLine="166"/> 209 221 </Position14> 210 222 <Position15> 211 223 <Filename Value="USqlDatabase.pas"/> 212 <Caret Line=" 4" Column="18" TopLine="1"/>224 <Caret Line="190" Column="1" TopLine="168"/> 213 225 </Position15> 214 226 <Position16> 215 227 <Filename Value="USqlDatabase.pas"/> 216 <Caret Line=" 52" Column="24" TopLine="30"/>228 <Caret Line="193" Column="1" TopLine="171"/> 217 229 </Position16> 218 230 <Position17> 219 231 <Filename Value="USqlDatabase.pas"/> 220 <Caret Line=" 80" Column="45" TopLine="58"/>232 <Caret Line="194" Column="1" TopLine="172"/> 221 233 </Position17> 222 234 <Position18> 223 <Filename Value=" USqlDatabase.pas"/>224 <Caret Line="1 37" Column="21" TopLine="115"/>235 <Filename Value="DBCExport.pas"/> 236 <Caret Line="196" Column="1" TopLine="174"/> 225 237 </Position18> 226 238 <Position19> 227 <Filename Value=" DBCExport.pas"/>228 <Caret Line=" 212" Column="30" TopLine="190"/>239 <Filename Value="USqlDatabase.pas"/> 240 <Caret Line="179" Column="43" TopLine="1"/> 229 241 </Position19> 230 242 <Position20> 231 243 <Filename Value="DBCExport.pas"/> 232 <Caret Line="19 7" Column="32" TopLine="191"/>244 <Caret Line="196" Column="37" TopLine="174"/> 233 245 </Position20> 234 246 <Position21> 235 247 <Filename Value="DBCExport.pas"/> 236 <Caret Line=" 195" Column="1" TopLine="173"/>248 <Caret Line="29" Column="1" TopLine="10"/> 237 249 </Position21> 238 250 <Position22> 239 <Filename Value=" USqlDatabase.pas"/>240 <Caret Line=" 181" Column="1" TopLine="159"/>251 <Filename Value="DBCExport.pas"/> 252 <Caret Line="82" Column="29" TopLine="61"/> 241 253 </Position22> 242 254 <Position23> 243 <Filename Value=" USqlDatabase.pas"/>244 <Caret Line="1 83" Column="1" TopLine="161"/>255 <Filename Value="DBCExport.pas"/> 256 <Caret Line="194" Column="1" TopLine="176"/> 245 257 </Position23> 246 258 <Position24> 247 <Filename Value=" USqlDatabase.pas"/>248 <Caret Line=" 184" Column="1" TopLine="162"/>259 <Filename Value="DBCExport.pas"/> 260 <Caret Line="206" Column="23" TopLine="185"/> 249 261 </Position24> 250 262 <Position25> 251 <Filename Value=" USqlDatabase.pas"/>252 <Caret Line=" 186" Column="1" TopLine="164"/>263 <Filename Value="DBCExport.pas"/> 264 <Caret Line="234" Column="42" TopLine="217"/> 253 265 </Position25> 254 266 <Position26> 255 <Filename Value=" USqlDatabase.pas"/>256 <Caret Line=" 188" Column="1" TopLine="166"/>267 <Filename Value="DBCExport.pas"/> 268 <Caret Line="238" Column="29" TopLine="219"/> 257 269 </Position26> 258 270 <Position27> 259 <Filename Value=" USqlDatabase.pas"/>260 <Caret Line=" 190" Column="1" TopLine="168"/>271 <Filename Value="DBCExport.pas"/> 272 <Caret Line="6" Column="92" TopLine="1"/> 261 273 </Position27> 262 274 <Position28> 263 <Filename Value=" USqlDatabase.pas"/>264 <Caret Line=" 193" Column="1" TopLine="171"/>275 <Filename Value="DBCExport.pas"/> 276 <Caret Line="53" Column="89" TopLine="19"/> 265 277 </Position28> 266 <Position29>267 <Filename Value="USqlDatabase.pas"/>268 <Caret Line="194" Column="1" TopLine="172"/>269 </Position29>270 <Position30>271 <Filename Value="DBCExport.pas"/>272 <Caret Line="196" Column="1" TopLine="174"/>273 </Position30>274 278 </JumpHistory> 275 279 </ProjectOptions> … … 304 308 </CompilerOptions> 305 309 <Debugging> 306 <BreakPoints Count="3">307 <Item1>308 <Source Value="DBCExport.pas"/>309 <Line Value="212"/>310 </Item1>311 <Item2>312 <Source Value="DBCExport.pas"/>313 <Line Value="195"/>314 </Item2>315 <Item3>316 <Source Value="DBCExport.pas"/>317 <Line Value="196"/>318 </Item3>319 </BreakPoints>320 310 <Watches Count="2"> 321 311 <Item1> -
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; -
tools/dbc_export/USqlDatabase.pas
r335 r359 1 1 unit USqlDatabase; 2 2 3 {$mode delphi}{$H+} 3 {$mode Delphi}{$H+} 4 // Upraveno: 16.12.2009 4 5 5 6 interface 6 7 7 8 uses 8 SysUtils, Classes, mysql50, TypInfo;9 SysUtils, Classes, Dialogs, mysql50, TypInfo; 9 10 10 11 type 12 EQueryError = Exception; 13 11 14 TClientCapabilities = (_CLIENT_LONG_PASSWORD, _CLIENT_FOUND_ROWS, 12 15 _CLIENT_LONG_FLAG, _CLIENT_CONNECT_WITH_DB, _CLIENT_NO_SCHEMA, … … 16 19 TSetClientCapabilities = set of TClientCapabilities; 17 20 18 TAssoc Array = class(TStringList)21 TAssociativeArray = class(TStringList) 19 22 private 20 23 function GetValues(Index: string): string; … … 32 35 TDbRows = class(TList) 33 36 private 34 function GetData(Index: Integer): TAssoc Array;35 procedure SetData(Index: Integer; const Value: TAssoc Array);37 function GetData(Index: Integer): TAssociativeArray; 38 procedure SetData(Index: Integer; const Value: TAssociativeArray); 36 39 public 37 property Data[Index: Integer]: TAssoc Array read GetData write SetData; default;40 property Data[Index: Integer]: TAssociativeArray read GetData write SetData; default; 38 41 destructor Destroy; override; 39 42 end; … … 44 47 FSession: PMYSQL; 45 48 FConnected: Boolean; 46 FOnError: TNotifyEvent;47 49 FDatabase: string; 48 50 function GetConnected: Boolean; … … 57 59 UserName: string; 58 60 Password: string; 61 Encoding: string; 59 62 Table: string; 60 63 RepeatLastAction: Boolean; … … 62 65 procedure CreateDatabase; 63 66 procedure CreateTable(Name: string); 64 procedure CreateColumn( ATable, ColumnName: string; ColumnType: TTypeKind);67 procedure CreateColumn(Table, ColumnName: string; ColumnType: TTypeKind); 65 68 function Query(Data: string): TDbRows; 66 69 function Select(ATable: string; Filter: string = '*'; Condition: string = '1'): TDbRows; 67 70 procedure Delete(ATable: string; Condition: string = '1'); 68 procedure Insert(ATable: string; Data: TAssoc Array);69 procedure Update(ATable: string; Data: TAssoc Array; Condition: string = '1');70 procedure Replace(ATable: string; Data: TAssoc Array);71 procedure Insert(ATable: string; Data: TAssociativeArray); 72 procedure Update(ATable: string; Data: TAssociativeArray; Condition: string = '1'); 73 procedure Replace(ATable: string; Data: TAssociativeArray); 71 74 procedure Connect; 72 75 procedure Disconnect; … … 75 78 property LastErrorNumber: Integer read GetLastErrorNumber; 76 79 property Connected: Boolean read GetConnected; 77 property OnError: TNotifyEvent read FOnError write FOnError;78 80 constructor Create; 79 81 destructor Destroy; override; … … 84 86 function MySQLFloatToStr(F: Real): string; 85 87 function MySQLStrToFloat(S: string): Real; 86 function MySQLDateToDateTime(Date: string): TDateTime;87 88 88 89 implementation … … 107 108 { TDataModule2 } 108 109 109 function MySQLDateToDateTime(Date: string): TDateTime;110 begin111 Result := 0;112 end;113 114 110 function MySQLFloatToStr(F: Real): string; 115 111 var … … 117 113 begin 118 114 S := FloatToStr(F); 119 if Pos(',', S) > 0 then S[Pos(',',S)] := '.';115 if Pos(',', S) > 0 then S[Pos(',',S)] := '.'; 120 116 Result := S; 121 117 end; … … 123 119 function MySQLStrToFloat(S: string): Real; 124 120 begin 125 if Pos('.', S) > 0 then S[Pos('.',S)] := ',';121 if Pos('.', S) > 0 then S[Pos('.',S)] := ','; 126 122 Result := StrToFloat(S); 127 123 end; … … 143 139 end else FConnected := False; 144 140 CheckError; 145 Rows := Query('SET NAMES cp1250');141 Rows := Query('SET NAMES ' + Encoding); 146 142 Rows.Free; 147 143 end; 148 144 149 procedure TSqlDatabase.Insert(ATable: string; Data: TAssoc Array);145 procedure TSqlDatabase.Insert(ATable: string; Data: TAssociativeArray); 150 146 var 151 147 DbNames: string; … … 153 149 I: Integer; 154 150 Value: string; 155 DbR ows: TDbRows;151 DbResult: TDbRows; 156 152 begin 157 153 Table := ATable; 158 154 DbNames := ''; 159 155 DbValues := ''; 160 for I := 0 to Data.Count -1 do begin156 for I := 0 to Data.Count - 1 do begin 161 157 Value := Data.ValuesAtIndex[I]; 162 158 StringReplace(Value, '"', '\"', [rfReplaceAll]); … … 167 163 System.Delete(DbNames, 1, 1); 168 164 System.Delete(DbValues, 1, 1); 169 DbR ows:= Query('INSERT INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')');170 DbR ows.Free;165 DbResult := Query('INSERT INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 166 DbResult.Free; 171 167 end; 172 168 … … 176 172 DbResult: PMYSQL_RES; 177 173 DbRow: MYSQL_ROW; 178 type179 PMYSQL_ROW2 = ^TMYSQL_ROW2; // return data as array of strings180 TMYSQL_ROW2 = array[0..MaxInt div SizeOf(pChar) - 1] of pChar;181 174 begin 182 175 //DebugLog('SqlDatabase query: '+Data); … … 194 187 if Assigned(DbResult) then begin 195 188 Result.Count := mysql_num_rows(DbResult); 196 for I := 0 to Result.Count -1 do begin189 for I := 0 to Result.Count - 1 do begin 197 190 DbRow := mysql_fetch_row(DbResult); 198 Result[I] := TAssoc Array.Create;191 Result[I] := TAssociativeArray.Create; 199 192 with Result[I] do begin 200 for II := 0 to mysql_num_fields(DbResult)-1 do begin 201 Add(mysql_fetch_field_direct(DbResult, II)^.name + NameValueSeparator + PMYSQL_ROW2(DbRow)^[II]); 193 for II := 0 to mysql_num_fields(DbResult) - 1 do begin 194 Add(mysql_fetch_field_direct(DbResult, II)^.Name + 195 NameValueSeparator + PChar((DbRow + II)^)); 202 196 end; 203 197 end; … … 215 209 end; 216 210 217 procedure TSqlDatabase.Replace(ATable: string; Data: TAssoc Array);211 procedure TSqlDatabase.Replace(ATable: string; Data: TAssociativeArray); 218 212 var 219 213 DbNames: string; … … 221 215 Value: string; 222 216 I: Integer; 223 DbR ows: TDbRows;217 DbResult: TDbRows; 224 218 begin 225 219 Table := ATable; 226 220 DbNames := ''; 227 221 DbValues := ''; 228 for I := 0 to Data.Count -1 do begin222 for I := 0 to Data.Count - 1 do begin 229 223 Value := Data.ValuesAtIndex[I]; 230 224 StringReplace(Value, '"', '\"', [rfReplaceAll]); … … 235 229 System.Delete(DbNames, 1, 1); 236 230 System.Delete(DbValues, 1, 1); 237 DbR ows:= Query('REPLACE INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')');238 DbR ows.Free;231 DbResult := Query('REPLACE INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 232 DbResult.Free; 239 233 end; 240 234 … … 245 239 end; 246 240 247 procedure TSqlDatabase.Update(ATable: string; Data: TAssoc Array; Condition: string = '1');241 procedure TSqlDatabase.Update(ATable: string; Data: TAssociativeArray; Condition: string = '1'); 248 242 var 249 243 DbValues: string; 250 244 Value: string; 251 245 I: Integer; 252 DbR ows: TDbRows;246 DbResult: TDbRows; 253 247 begin 254 248 Table := ATable; 255 249 DbValues := ''; 256 for I := 0 to Data.Count -1 do begin250 for I := 0 to Data.Count - 1 do begin 257 251 Value := Data.ValuesAtIndex[I]; 258 252 StringReplace(Value, '"', '\"', [rfReplaceAll]); … … 261 255 end; 262 256 System.Delete(DbValues, 1, 1); 263 DbR ows:= Query('UPDATE `' + Table + '` SET (' + DbValues + ') WHERE ' + Condition);264 D BRows.Free;257 DbResult := Query('UPDATE `' + Table + '` SET (' + DbValues + ') WHERE ' + Condition); 258 DbResult.Free; 265 259 end; 266 260 … … 272 266 { TAssocArray } 273 267 274 procedure TAssoc Array.AddKeyValue(Key, Value: string);268 procedure TAssociativeArray.AddKeyValue(Key, Value: string); 275 269 begin 276 270 Add(Key + NameValueSeparator + Value); 277 271 end; 278 272 279 constructor TAssoc Array.Create;273 constructor TAssociativeArray.Create; 280 274 begin 281 275 NameValueSeparator := '|'; 282 276 end; 283 277 284 destructor TAssoc Array.Destroy;278 destructor TAssociativeArray.Destroy; 285 279 begin 286 280 inherited; 287 281 end; 288 282 289 function TAssoc Array.GetAllValues: string;283 function TAssociativeArray.GetAllValues: string; 290 284 var 291 285 I: Integer; 292 286 begin 293 287 Result := ''; 294 for I := 0 to Count -1 do begin288 for I := 0 to Count - 1 do begin 295 289 Result := Result + Names[I] + '=' + ValuesAtIndex[I] + ','; 296 290 end; 297 291 end; 298 292 299 function TAssoc Array.GetValues(Index: string): string;293 function TAssociativeArray.GetValues(Index: string): string; 300 294 begin 301 295 Result := inherited Values[Index]; 302 296 end; 303 297 304 function TAssoc Array.GetValuesAtIndex(Index: Integer): string;298 function TAssociativeArray.GetValuesAtIndex(Index: Integer): string; 305 299 begin 306 300 Result := inherited Values[Names[Index]]; … … 309 303 procedure TSqlDatabase.Delete(ATable: string; Condition: string = '1'); 310 304 var 311 DbR ows: TDbRows;305 DbResult: TDbRows; 312 306 begin 313 307 Table := ATable; 314 DbR ows := Query('DELETE FROM `' + Table + '` WHERE ' + Condition);315 DbR ows.Free;308 DbResult = Query('DELETE FROM `' + Table + '` WHERE ' + Condition); 309 DbResult.Free; 316 310 end; 317 311 … … 331 325 inherited; 332 326 FSession := nil; 333 end; 334 335 procedure TAssocArray.SetValues(Index: string; const Value: string); 327 Encoding := 'utf8'; 328 end; 329 330 procedure TAssociativeArray.SetValues(Index: string; const Value: string); 336 331 begin 337 332 inherited Values[Index] := Value; … … 344 339 I: Integer; 345 340 begin 346 for I := 0 to Count - 1 do Data[I].Free; 341 for I := 0 to Count - 1 do 342 Data[I].Free; 347 343 inherited; 348 344 end; 349 345 350 function TDbRows.GetData(Index: Integer): TAssoc Array;346 function TDbRows.GetData(Index: Integer): TAssociativeArray; 351 347 begin 352 348 Result := Items[Index]; 353 349 end; 354 350 355 procedure TDbRows.SetData(Index: Integer; const Value: TAssoc Array);351 procedure TDbRows.SetData(Index: Integer; const Value: TAssociativeArray); 356 352 begin 357 353 Items[Index] := Value; … … 376 372 begin 377 373 Result := LastErrorNumber <> 0; 378 if Result and Assigned(OnError) then OnError(Self); 374 if Result then 375 raise EQueryError.Create('Database query error: "' + LastErrorMessage + '"'); 379 376 end; 380 377 … … 394 391 begin 395 392 Query('CREATE TABLE `' + Name + '`' + 396 ' (` id` INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`));');397 end; 398 399 procedure TSqlDatabase.CreateColumn( ATable, ColumnName: string;393 ' (`Id` INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`Id`));'); 394 end; 395 396 procedure TSqlDatabase.CreateColumn(Table, ColumnName: string; 400 397 ColumnType: TTypeKind); 401 398 const
Note:
See TracChangeset
for help on using the changeset viewer.