Cant remove support of databases in Zeos.inc

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
ssamayoa
Junior Boarder
Junior Boarder
Posts: 29
Joined: 14.01.2006, 19:06

Cant remove support of databases in Zeos.inc

Post by ssamayoa »

I used some time ago Zeos and remember that you can remove support for some database just comment the define in Zeos.inc. I just did it but for my sorprise ZInterbaseToken uses ZPostgreSqlToken which isnt compiled if ENABLE_POSTGRESQL isn't defined. ZPostgreSqlToken uses ZMySqlToken and ZOracleToken uses ZPostgreSqlToken and ZSybaseToken then to get Zeos compiled all defines most be there.

Bottom line is a project with one form with one TZConnection has 700Kb+ of code.

Is still a way to redude this?

Regards.
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

Quite simply you can:

Open unit ZInterbaseToken

Delete ZPostgreSqlToken

Change

TZInterbaseNumberState = class (TZPostgreSQLNumberState)
end;

to

TZInterbaseNumberState = class (TZNumberState)
public
function NextToken(Stream: TStream; FirstChar: Char;
Tokenizer: TZTokenizer): TZToken; override;
end;

Add, at the bottom of the unit,

{ TZInterbaseNumberState }

{**
Return a number token from a reader.
@return a number token from a reader
}
function TZInterbaseNumberState.NextToken(Stream: TStream; FirstChar: Char;
Tokenizer: TZTokenizer): TZToken;
var
TempChar: Char;
FloatPoint: Boolean;
LastChar: Char;

function ReadDecDigits: string;
begin
Result := '';
LastChar := #0;
while Stream.Read(LastChar, 1) > 0 do
begin
if LastChar in ['0'..'9'] then
begin
Result := Result + LastChar;
LastChar := #0;
end
else
begin
Stream.Seek(-1, soFromCurrent);
Break;
end;
end;
end;

begin
FloatPoint := FirstChar = '.';
Result.Value := FirstChar;
Result.TokenType := ttUnknown;
LastChar := #0;

{ Reads the first part of the number before decimal point }
if not FloatPoint then
begin
Result.Value := Result.Value + ReadDecDigits;
FloatPoint := LastChar = '.';
if FloatPoint then
begin
Stream.Read(TempChar, 1);
Result.Value := Result.Value + TempChar;
end;
end;

{ Reads the second part of the number after decimal point }
if FloatPoint then
Result.Value := Result.Value + ReadDecDigits;

{ Reads a power part of the number }
if LastChar in ['e','E'] then
begin
Stream.Read(TempChar, 1);
Result.Value := Result.Value + TempChar;
FloatPoint := True;

Stream.Read(TempChar, 1);
if TempChar in ['0'..'9','-','+'] then
Result.Value := Result.Value + TempChar + ReadDecDigits
else
begin
Result.Value := Copy(Result.Value, 1, Length(Result.Value) - 1);
Stream.Seek(-2, soFromCurrent);
end;
end;

{ Prepare the result }
if Result.Value = '.' then
begin
if Tokenizer.SymbolState <> nil then
Result := Tokenizer.SymbolState.NextToken(Stream, FirstChar, Tokenizer);
end
else
begin
if FloatPoint then
Result.TokenType := ttFloat
else Result.TokenType := ttInteger;
end;
end;


Open unit ZOracleToken

Delete ZPostgreSqlToken

Change

TZOracleNumberState = class (TZPostgreSQLNumberState)
end;

to

TZOracleNumberState = class (TZNumberState)
public
function NextToken(Stream: TStream; FirstChar: Char;
Tokenizer: TZTokenizer): TZToken; override;
end;

Add, at the bottom of the unit,

{ TZOracleNumberState }

{**
Return a number token from a reader.
@return a number token from a reader
}
function TZOracleNumberState.NextToken(Stream: TStream; FirstChar: Char;
Tokenizer: TZTokenizer): TZToken;
var
TempChar: Char;
FloatPoint: Boolean;
LastChar: Char;

function ReadDecDigits: string;
begin
Result := '';
LastChar := #0;
while Stream.Read(LastChar, 1) > 0 do
begin
if LastChar in ['0'..'9'] then
begin
Result := Result + LastChar;
LastChar := #0;
end
else
begin
Stream.Seek(-1, soFromCurrent);
Break;
end;
end;
end;

begin
FloatPoint := FirstChar = '.';
Result.Value := FirstChar;
Result.TokenType := ttUnknown;
LastChar := #0;

{ Reads the first part of the number before decimal point }
if not FloatPoint then
begin
Result.Value := Result.Value + ReadDecDigits;
FloatPoint := LastChar = '.';
if FloatPoint then
begin
Stream.Read(TempChar, 1);
Result.Value := Result.Value + TempChar;
end;
end;

{ Reads the second part of the number after decimal point }
if FloatPoint then
Result.Value := Result.Value + ReadDecDigits;

{ Reads a power part of the number }
if LastChar in ['e','E'] then
begin
Stream.Read(TempChar, 1);
Result.Value := Result.Value + TempChar;
FloatPoint := True;

Stream.Read(TempChar, 1);
if TempChar in ['0'..'9','-','+'] then
Result.Value := Result.Value + TempChar + ReadDecDigits
else
begin
Result.Value := Copy(Result.Value, 1, Length(Result.Value) - 1);
Stream.Seek(-2, soFromCurrent);
end;
end;

{ Prepare the result }
if Result.Value = '.' then
begin
if Tokenizer.SymbolState <> nil then
Result := Tokenizer.SymbolState.NextToken(Stream, FirstChar, Tokenizer);
end
else
begin
if FloatPoint then
Result.TokenType := ttFloat
else Result.TokenType := ttInteger;
end;
end;
Last edited by seawolf on 05.12.2008, 12:50, edited 1 time in total.
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

About Oracle and Sybase

Unit ZOracleToken;

delete ZSybaseToken

Change

TZOracleCommentState = class (TZSybaseCommentState)
end;

to

TZOracleCommentState = class (TZCppCommentState)
public
function NextToken(Stream: TStream; FirstChar: Char;
Tokenizer: TZTokenizer): TZToken; override;
end;

Add, at the end of the unit

{ TZOralceCommentState }

{**
Gets an oracle specific comments like # or /* */.
@return either just a slash token, or the results of
delegating to a comment-handling state
}
function TOracleCommentState.NextToken(Stream: TStream; FirstChar: Char;
Tokenizer: TZTokenizer): TZToken;
var
ReadChar: Char;
ReadNum: Integer;
begin
Result.Value := FirstChar;
Result.TokenType := ttUnknown;

if FirstChar = '-' then
begin
ReadNum := Stream.Read(ReadChar, 1);
if (ReadNum > 0) and (ReadChar = '-') then
begin
Result.TokenType := ttComment;
Result.Value := '--' + GetSingleLineComment(Stream);
end
else
begin
if ReadNum > 0 then
Stream.Seek(-1, soFromCurrent);
end;
end
else if FirstChar = '/' then
begin
ReadNum := Stream.Read(ReadChar, 1);
if (ReadNum > 0) and (ReadChar = '*') then
begin
Result.TokenType := ttComment;
Result.Value := '/*' + GetMultiLineComment(Stream);
end
else
begin
if ReadNum > 0 then
Stream.Seek(-1, soFromCurrent);
end;
end;

if (Result.TokenType = ttUnknown) and (Tokenizer.SymbolState <> nil) then
Result := Tokenizer.SymbolState.NextToken(Stream, FirstChar, Tokenizer);
end;
ssamayoa
Junior Boarder
Junior Boarder
Posts: 29
Joined: 14.01.2006, 19:06

Post by ssamayoa »

Jezz!

It should be a less complex way to do that!

I exepcted to see the compilation of those requiered units, a minor change on the position of the defines test but it seems that not.

I'm testing UniDAC which supports various databases, its approach is that for each supported server there is a component. Could be the way should go?

Thanks anyway.

Regards.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

As long as we don't remove the dependencies between the tokenizers it's better to compile them anyway, even if support for the specified database is disabled. I doubt it would make much difference in size. (It's a choise between inherit from an existing object you don't really need or duplicate the code because you need the functionalty anyhow)

Did the commit in testing branch (SVN rev. 536) now. In about a week I'l merge it into Trunk and the 6.6-patches branch, so it will be included in next 6.6 maintenance release.

Mark
Image
Post Reply