Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: silvioprog/jdo
base: d740ec39ce
...
head fork: silvioprog/jdo
compare: 5a1c04829f
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 15, 2012
Silvio Clecio ---- 3bfc306
Silvio Clecio ---- 685d250
Silvio Clecio JDODataBase: implements two constructors, e.g:
  db := TJDODataBase.Create('db.cfg');

or:

  db := TJDODataBase.Create(
    'connectortype=postgresql;databasename=postgres;username=postgres;' +
    'password=postgres;hostname=127.0.0.1');
5a1c048
Showing with 25 additions and 21 deletions.
  1. +23 −20 Core/JDO.pas
  2. +1 −0  Core/JDOConsts.pas
  3. +1 −1  Packages/JDORT.lpk
43 Core/JDO.pas
View
@@ -82,8 +82,8 @@ TJDOQuery = class;
TJDODataBase = class
private
- FConfig: TStrings;
- FConfigFileName: TFileName;
+ FConfigFile: TStrings;
+ FConfig: string;
FConnection: TJDOSQLConnection;
FFields: TFields;
FOnCommit: TNotifyEvent;
@@ -103,8 +103,7 @@ TJDODataBase = class
procedure InternalCreateTransaction;
procedure InternalCreateQuery;
public
- constructor Create(const AConfigFileName: TFileName;
- const AConnect: Boolean = True);
+ constructor Create(const AConfig: string; const AConnect: Boolean = True);
destructor Destroy; override;
procedure LoadConfig;
procedure SetProperties;
@@ -117,8 +116,6 @@ TJDODataBase = class
procedure RestartTrans;
procedure Commit;
procedure Rollback;
- property Config: TStrings read FConfig;
- property ConfigFileName: TFileName read FConfigFileName write FConfigFileName;
property Connection: TJDOSQLConnection read FConnection;
property Transaction: TJDOSQLTransaction read FTransaction;
property Query: TJDOSQLQuery read FQuery;
@@ -399,11 +396,10 @@ procedure TJDOSQLQuery.WriteParams(AJSONFiels, AJSONObject: TJSONObject;
{ TJDODataBase }
-constructor TJDODataBase.Create(const AConfigFileName: TFileName;
- const AConnect: Boolean);
+constructor TJDODataBase.Create(const AConfig: string; const AConnect: Boolean);
begin
- FConfig := TStringList.Create;
- FConfigFileName := AConfigFileName;
+ FConfigFile := TStringList.Create;
+ FConfig := AConfig;
LoadConfig;
InternalCreateConnection;
InternalCreateTransaction;
@@ -415,7 +411,7 @@ constructor TJDODataBase.Create(const AConfigFileName: TFileName;
destructor TJDODataBase.Destroy;
begin
- FConfig.Free;
+ FConfigFile.Free;
FQuery.Free;
FQueries.Free;
FTransaction.Free;
@@ -428,7 +424,7 @@ procedure TJDODataBase.InternalCreateConnection;
VConnectorType: ShortString;
VConnectionDef: TConnectionDef;
begin
- VConnectorType := FConfig.Values[CONNECTOR_TYPE];
+ VConnectorType := FConfigFile.Values[CONNECTOR_TYPE];
if Trim(VConnectorType) = ES then
raise EJDODataBase.Create(Self, SEmptyConnectorTypeError);
VConnectionDef := GetConnectionDef(VConnectorType);
@@ -465,10 +461,17 @@ procedure TJDODataBase.InternalCreateQuery;
procedure TJDODataBase.LoadConfig;
begin
- if not FileExists(FConfigFileName) then
- raise EJDODataBase.CreateFmt(Self, SConfigFileNotFoundError,
- [FConfigFileName]);
- FConfig.LoadFromFile(FConfigFileName);
+ if Pos(CONNECTOR_TYPE, LowerCase(FConfig)) <> 0 then
+ begin
+ FConfigFile.Delimiter := SC;
+ FConfigFile.DelimitedText := FConfig;
+ end
+ else
+ begin
+ if not FileExists(FConfig) then
+ raise EJDODataBase.CreateFmt(Self, SConfigFileNotFoundError, [FConfig]);
+ FConfigFile.LoadFromFile(FConfig);
+ end;
end;
procedure TJDODataBase.SetProperties;
@@ -476,18 +479,18 @@ procedure TJDODataBase.SetProperties;
I: Integer;
VPropName, VToken: ShortString;
begin
- for I := 0 to Pred(FConfig.Count) do
+ for I := 0 to Pred(FConfigFile.Count) do
begin
- VPropName := FConfig.Names[I];
+ VPropName := FConfigFile.Names[I];
VToken := Copy(VPropName, 1, 1);
if (CompareText(VPropName, CONNECTOR_TYPE) = 0) or (VToken = PO) or
(VToken = ES) then
Continue;
if IsPublishedProp(FConnection, VPropName) then
- SetPropValue(FConnection, VPropName, FConfig.Values[VPropName])
+ SetPropValue(FConnection, VPropName, FConfigFile.Values[VPropName])
else
raise EJDODataBase.CreateFmt(Self, SInvalidPropInConfigFile,
- [ExtractFileName(FConfigFileName), VPropName]);
+ [ExtractFileName(FConfig), VPropName]);
end;
end;
1  Core/JDOConsts.pas
View
@@ -31,6 +31,7 @@ interface
PS = '(';
PO = '#';
SP = ' ';
+ SC = ';';
DEFAULT_PRIMARY_KEY = 'id';
CONNECTOR_TYPE = 'connectortype';
SQL_SELECT_TOKEN = 'select ';
2  Packages/JDORT.lpk
View
@@ -19,7 +19,7 @@
</CompilerOptions>
<Description Value="JSON Data Objects RunTime package."/>
<License Value="See the file LICENSE.txt, included in this distribution, for details about the copyright."/>
- <Version Release="1" Build="10"/>
+ <Version Release="1" Build="11"/>
<Files Count="3">
<Item1>
<Filename Value="..\Core\JDO.pas"/>

No commit comments for this range

Something went wrong with that request. Please try again.