Ignore:
Timestamp:
Feb 27, 2010, 6:25:07 PM (14 years ago)
Author:
maron
Message:

Přidání parametru sql_query, připojení k databázi, nahrazování původních textů texty z databáze

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/dbc_export/DBCExport.pas

    r339 r340  
    2424    NewDBCFileName: string;
    2525    ColumnTypeDefinition: string;
     26    SQLquery: string;
    2627    DisplayData: Boolean;
    2728    constructor Create(TheOwner: TComponent); override;
     
    2930    procedure WriteHelp; virtual;
    3031    procedure ShowDBC;
     32    procedure LoadDBC;
     33    procedure SaveDBC;
     34    procedure ReplaceText;
     35    function GetIDbyEntry(entry: integer; var DBRows: TDBRows): integer;
    3136  end;
    3237
     
    6974    Database.Hostname := GetOptionValue('t', 'host');
    7075  end else Database.Hostname := 'localhost';
     76  if HasOption('q', 'sql_query') then begin
     77    SQLquery := GetOptionValue('q', 'sql_query');
     78  end;
    7179end;
    7280
     
    7482begin
    7583  ParseParameters;
     84
     85  LoadDBC;
     86
    7687  ShowDBC;
     88
     89  ReplaceText;
     90
     91  SaveDBC;
    7792
    7893  // Stop program loop
     
    105120  WriteLn('  -c --coltypedef  DBC column type definition string (u - uint32, s - string)');
    106121  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
    107124end;
    108125
     
    111128  X, Y: Integer;
    112129  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 
     130begin
     131  with DBC do begin
    125132      // Display DBC data
    126133      if DisplayData then
     
    132139        WriteLn(Text);
    133140      end;
    134 
    135       SaveToFile(NewDBCFileName);
     141  end;
     142end;
     143
     144procedure TDBCExport.LoadDBC;
     145var
     146  I: Integer;
     147begin
     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
    136158    end else WriteLn('File ' + DBCFileName + ' not exists.');
     159  end;
     160end;
     161
     162procedure TDBCExport.SaveDBC;
     163begin
     164  with DBC do begin
     165    SaveToFile(NewDBCFileName);
    137166    Free;
    138167  end;
     168end;
     169
     170
     171//function get data from database and replace text in dbc
     172procedure TDBCExport.ReplaceText;
     173var
     174  DBRows : TDbRows;
     175  Text: String;
     176  X, Y, I: Integer;
     177  IndexRowData: Integer;
     178begin
     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;
     206end;
     207
     208function TDBCExport.GetIDbyEntry(entry: integer; var DBRows: TDBRows): integer;
     209var
     210 i: integer;
     211 Count: integer;
     212begin
     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;
    139224end;
    140225
Note: See TracChangeset for help on using the changeset viewer.