Changeset 340 for tools


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

Location:
tools/dbc_export
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tools/dbc_export/DBCExport.lpi

    r339 r340  
    22<CONFIG>
    33  <ProjectOptions>
     4    <PathDelim Value="/"/>
    45    <Version Value="7"/>
    56    <General>
     
    1617      <Language Value=""/>
    1718      <CharSet Value=""/>
    18       <StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion=""/>
    1919    </VersionInfo>
    2020    <PublishOptions>
     
    2727      <local>
    2828        <FormatVersion Value="1"/>
     29        <CommandLineParams Value="-f ../../../trunk/source/3.3.0/dbc/GameTips.dbc -n test.dbc -c usuuuuuuuuuuuuuuuu -q &quot;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&quot;"/>
    2930        <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
    3031      </local>
     
    3536        <IsPartOfProject Value="True"/>
    3637        <UnitName Value="DBCExport"/>
    37         <CursorPos X="1" Y="35"/>
    38         <TopLine Value="22"/>
     38        <CursorPos X="1" Y="200"/>
     39        <TopLine Value="180"/>
    3940        <EditorIndex Value="0"/>
    40         <UsageCount Value="39"/>
     41        <UsageCount Value="45"/>
    4142        <Loaded Value="True"/>
    4243        <SyntaxHighlighter Value="Delphi"/>
     
    4748        <CursorPos X="1" Y="1"/>
    4849        <TopLine Value="1"/>
    49         <UsageCount Value="28"/>
     50        <UsageCount Value="27"/>
    5051        <SyntaxHighlighter Value="Delphi"/>
    5152      </Unit1>
     
    5455        <CursorPos X="14" Y="719"/>
    5556        <TopLine Value="703"/>
    56         <UsageCount Value="14"/>
     57        <UsageCount Value="13"/>
    5758      </Unit2>
    5859      <Unit3>
     
    6061        <CursorPos X="23" Y="36"/>
    6162        <TopLine Value="33"/>
    62         <UsageCount Value="13"/>
     63        <UsageCount Value="12"/>
    6364      </Unit3>
    6465      <Unit4>
     
    6768        <CursorPos X="1" Y="1"/>
    6869        <TopLine Value="1"/>
    69         <UsageCount Value="28"/>
     70        <UsageCount Value="27"/>
    7071        <SyntaxHighlighter Value="Delphi"/>
    7172      </Unit4>
     
    7475        <CursorPos X="24" Y="6"/>
    7576        <TopLine Value="1"/>
    76         <UsageCount Value="8"/>
     77        <UsageCount Value="7"/>
    7778        <SyntaxHighlighter Value="None"/>
    7879      </Unit5>
     
    8283        <CursorPos X="3" Y="166"/>
    8384        <TopLine Value="164"/>
    84         <UsageCount Value="9"/>
     85        <UsageCount Value="8"/>
    8586      </Unit6>
    8687      <Unit7>
     
    8889        <CursorPos X="22" Y="196"/>
    8990        <TopLine Value="184"/>
    90         <UsageCount Value="11"/>
     91        <UsageCount Value="10"/>
    9192      </Unit7>
    9293      <Unit8>
     
    9596        <CursorPos X="12" Y="100"/>
    9697        <TopLine Value="66"/>
    97         <UsageCount Value="11"/>
     98        <UsageCount Value="10"/>
    9899      </Unit8>
    99100      <Unit9>
     
    101102        <CursorPos X="1" Y="1"/>
    102103        <TopLine Value="51"/>
    103         <UsageCount Value="11"/>
     104        <UsageCount Value="10"/>
    104105      </Unit9>
    105106      <Unit10>
     
    108109        <CursorPos X="9" Y="79"/>
    109110        <TopLine Value="51"/>
    110         <UsageCount Value="10"/>
     111        <UsageCount Value="9"/>
    111112      </Unit10>
    112113      <Unit11>
     
    114115        <IsPartOfProject Value="True"/>
    115116        <UnitName Value="USqlDatabase"/>
    116         <CursorPos X="1" Y="1"/>
    117         <TopLine Value="71"/>
    118         <EditorIndex Value="4"/>
    119         <UsageCount Value="30"/>
     117        <CursorPos X="14" Y="34"/>
     118        <TopLine Value="16"/>
     119        <EditorIndex Value="3"/>
     120        <UsageCount Value="36"/>
    120121        <Loaded Value="True"/>
    121122        <SyntaxHighlighter Value="Delphi"/>
     
    125126        <IsPartOfProject Value="True"/>
    126127        <UnitName Value="UDBC"/>
    127         <CursorPos X="21" Y="54"/>
    128         <TopLine Value="60"/>
    129         <EditorIndex Value="2"/>
    130         <UsageCount Value="30"/>
     128        <CursorPos X="1" Y="130"/>
     129        <TopLine Value="116"/>
     130        <EditorIndex Value="1"/>
     131        <UsageCount Value="36"/>
    131132        <Loaded Value="True"/>
    132133        <SyntaxHighlighter Value="Delphi"/>
     
    135136        <Filename Value="ReadMe.txt"/>
    136137        <IsPartOfProject Value="True"/>
    137         <CursorPos X="1" Y="8"/>
     138        <CursorPos X="51" Y="8"/>
    138139        <TopLine Value="1"/>
    139         <EditorIndex Value="3"/>
    140         <UsageCount Value="30"/>
     140        <EditorIndex Value="2"/>
     141        <UsageCount Value="36"/>
    141142        <Loaded Value="True"/>
    142143        <SyntaxHighlighter Value="None"/>
    143144      </Unit13>
    144145      <Unit14>
    145         <Filename Value="/usr/share/fpcsrc/packages/fcl-base/src/custapp.pp"/>
     146        <Filename Value="../../../../../usr/share/fpcsrc/packages/fcl-base/src/custapp.pp"/>
    146147        <UnitName Value="CustApp"/>
    147         <CursorPos X="1" Y="63"/>
    148         <TopLine Value="47"/>
    149         <EditorIndex Value="1"/>
     148        <CursorPos X="15" Y="42"/>
     149        <TopLine Value="28"/>
    150150        <UsageCount Value="15"/>
    151         <Loaded Value="True"/>
    152151      </Unit14>
    153152    </Units>
    154     <JumpHistory Count="22" HistoryIndex="21">
     153    <JumpHistory Count="30" HistoryIndex="29">
    155154      <Position1>
    156         <Filename Value="UDBC.pas"/>
    157         <Caret Line="1" Column="1" TopLine="1"/>
     155        <Filename Value="DBCExport.pas"/>
     156        <Caret Line="188" Column="1" TopLine="174"/>
    158157      </Position1>
    159158      <Position2>
    160159        <Filename Value="DBCExport.pas"/>
    161         <Caret Line="11" Column="21" TopLine="1"/>
     160        <Caret Line="189" Column="1" TopLine="175"/>
    162161      </Position2>
    163162      <Position3>
    164163        <Filename Value="DBCExport.pas"/>
    165         <Caret Line="100" Column="22" TopLine="72"/>
     164        <Caret Line="190" Column="1" TopLine="176"/>
    166165      </Position3>
    167166      <Position4>
    168167        <Filename Value="DBCExport.pas"/>
    169         <Caret Line="71" Column="3" TopLine="55"/>
     168        <Caret Line="191" Column="1" TopLine="177"/>
    170169      </Position4>
    171170      <Position5>
    172         <Filename Value="UDBC.pas"/>
    173         <Caret Line="1" Column="10" TopLine="1"/>
     171        <Filename Value="DBCExport.pas"/>
     172        <Caret Line="192" Column="1" TopLine="178"/>
    174173      </Position5>
    175174      <Position6>
    176         <Filename Value="UDBC.pas"/>
    177         <Caret Line="8" Column="29" TopLine="1"/>
     175        <Filename Value="DBCExport.pas"/>
     176        <Caret Line="193" Column="1" TopLine="179"/>
    178177      </Position6>
    179178      <Position7>
    180179        <Filename Value="DBCExport.pas"/>
    181         <Caret Line="15" Column="38" TopLine="8"/>
     180        <Caret Line="194" Column="1" TopLine="180"/>
    182181      </Position7>
    183182      <Position8>
    184183        <Filename Value="DBCExport.pas"/>
    185         <Caret Line="46" Column="12" TopLine="35"/>
     184        <Caret Line="188" Column="1" TopLine="174"/>
    186185      </Position8>
    187186      <Position9>
    188187        <Filename Value="DBCExport.pas"/>
    189         <Caret Line="64" Column="1" TopLine="46"/>
     188        <Caret Line="83" Column="1" TopLine="69"/>
    190189      </Position9>
    191190      <Position10>
    192191        <Filename Value="DBCExport.pas"/>
    193         <Caret Line="62" Column="52" TopLine="46"/>
     192        <Caret Line="186" Column="20" TopLine="166"/>
    194193      </Position10>
    195194      <Position11>
    196195        <Filename Value="DBCExport.pas"/>
    197         <Caret Line="103" Column="33" TopLine="87"/>
     196        <Caret Line="83" Column="1" TopLine="69"/>
    198197      </Position11>
    199198      <Position12>
    200199        <Filename Value="DBCExport.pas"/>
    201         <Caret Line="102" Column="10" TopLine="81"/>
     200        <Caret Line="186" Column="19" TopLine="166"/>
    202201      </Position12>
    203202      <Position13>
    204203        <Filename Value="DBCExport.pas"/>
    205         <Caret Line="19" Column="13" TopLine="3"/>
     204        <Caret Line="83" Column="1" TopLine="69"/>
    206205      </Position13>
    207206      <Position14>
    208207        <Filename Value="DBCExport.pas"/>
    209         <Caret Line="103" Column="33" TopLine="87"/>
     208        <Caret Line="180" Column="1" TopLine="166"/>
    210209      </Position14>
    211210      <Position15>
    212211        <Filename Value="DBCExport.pas"/>
    213         <Caret Line="47" Column="31" TopLine="27"/>
     212        <Caret Line="186" Column="20" TopLine="174"/>
    214213      </Position15>
    215214      <Position16>
    216215        <Filename Value="DBCExport.pas"/>
    217         <Caret Line="35" Column="22" TopLine="27"/>
     216        <Caret Line="82" Column="1" TopLine="69"/>
    218217      </Position16>
    219218      <Position17>
    220219        <Filename Value="DBCExport.pas"/>
    221         <Caret Line="50" Column="37" TopLine="37"/>
     220        <Caret Line="188" Column="1" TopLine="166"/>
    222221      </Position17>
    223222      <Position18>
    224223        <Filename Value="DBCExport.pas"/>
    225         <Caret Line="112" Column="13" TopLine="100"/>
     224        <Caret Line="187" Column="73" TopLine="173"/>
    226225      </Position18>
    227226      <Position19>
    228227        <Filename Value="DBCExport.pas"/>
    229         <Caret Line="113" Column="5" TopLine="107"/>
     228        <Caret Line="188" Column="1" TopLine="174"/>
    230229      </Position19>
    231230      <Position20>
    232231        <Filename Value="DBCExport.pas"/>
    233         <Caret Line="60" Column="61" TopLine="44"/>
     232        <Caret Line="186" Column="20" TopLine="174"/>
    234233      </Position20>
    235234      <Position21>
    236235        <Filename Value="DBCExport.pas"/>
    237         <Caret Line="123" Column="36" TopLine="107"/>
     236        <Caret Line="188" Column="41" TopLine="173"/>
    238237      </Position21>
    239238      <Position22>
    240239        <Filename Value="DBCExport.pas"/>
    241         <Caret Line="34" Column="3" TopLine="18"/>
     240        <Caret Line="187" Column="1" TopLine="173"/>
    242241      </Position22>
     242      <Position23>
     243        <Filename Value="DBCExport.pas"/>
     244        <Caret Line="188" Column="1" TopLine="174"/>
     245      </Position23>
     246      <Position24>
     247        <Filename Value="DBCExport.pas"/>
     248        <Caret Line="189" Column="1" TopLine="175"/>
     249      </Position24>
     250      <Position25>
     251        <Filename Value="DBCExport.pas"/>
     252        <Caret Line="188" Column="32" TopLine="176"/>
     253      </Position25>
     254      <Position26>
     255        <Filename Value="DBCExport.pas"/>
     256        <Caret Line="190" Column="28" TopLine="176"/>
     257      </Position26>
     258      <Position27>
     259        <Filename Value="DBCExport.pas"/>
     260        <Caret Line="187" Column="1" TopLine="173"/>
     261      </Position27>
     262      <Position28>
     263        <Filename Value="DBCExport.pas"/>
     264        <Caret Line="188" Column="1" TopLine="174"/>
     265      </Position28>
     266      <Position29>
     267        <Filename Value="DBCExport.pas"/>
     268        <Caret Line="189" Column="1" TopLine="175"/>
     269      </Position29>
     270      <Position30>
     271        <Filename Value="DBCExport.pas"/>
     272        <Caret Line="190" Column="1" TopLine="176"/>
     273      </Position30>
    243274    </JumpHistory>
    244275  </ProjectOptions>
     
    253284      <SyntaxOptions>
    254285        <SyntaxMode Value="Delphi"/>
     286        <CStyleOperator Value="False"/>
    255287      </SyntaxOptions>
    256288    </Parsing>
  • 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
  • tools/dbc_export/UDBC.pas

    r337 r340  
    3030    procedure LoadColumnStrings(Column: Integer);
    3131    procedure SaveToFile(FileName: string);
     32    procedure SetString(Row, Column: Integer; Text: AnsiString);
    3233  end;
    3334
     
    121122end;
    122123
     124procedure TDBC.SetString(Row, Column: Integer; Text: AnsiString);
     125begin
     126  if VarIsStr(Cells[Row,Column]) then begin
     127    StringBlockSize := StringBlockSize + strlen(Pchar(Text)) - strlen(Pchar(VarToStr(Cells[Row,Column])));
     128    Cells[Row,Column] := Text;
     129  end;
     130end;
     131
    123132function TDBC.DetectColumnType(Column: Integer): TDBCColumnType;
    124133//var
Note: See TracChangeset for help on using the changeset viewer.