[Lazarus] TPQConnection.CreateDB: ENCODING, OWNER, TEMPLATE, LC_CTYPE, TABLESPACE
silvioprog
silvioprog at gmail.com
Thu Oct 30 02:06:42 CET 2014
On Tue, Oct 28, 2014 at 8:19 AM, Reinier Olislagers <
reinierolislagers at gmail.com> wrote:
> On 28/10/2014 02:03, silvioprog wrote:
> > Today I fixed that using a "mix of codes": creating the database using
> > the original postgre driver for Java, and calling "java -jar create_mydb
> > <params>" via TProcess. Now it worked like a charm!
>
> Please don't raise a bug tracker issue... especially one with a simple
> sample program and PostgreSQL DDL so the issue is easily reproducible
> for devs.
>
Oopss... sorry, I'll do that dude. =)
> It's much better to keep using a workaround using another programming
> language and letting other programmers potentially face the same problem
> than getting it fixed in a newer version of FPC.
> </sarcasm>
>
Yes, but I needed to fix the problem urgently, and unfortunatelly with
SQLdb doesn't worked. =( The final (quick workaround) code was:
procedure TCriadorBanco.Criar(const ADatabase, AOwner, AUser, APassword,
ALocale, ATemplate: string);
var
VJavaExe: string;
VProcess: TProcess;
VResult: TStringList;
begin
VJavaExe :=
{$IFDEF MSWINDOWS}
IncludeTrailingPathDelimiter(GetEnvironmentVariable('JAVA_HOME'))
{$ELSE}
'/usr/'
{$ENDIF};
VJavaExe += 'bin' + DirectorySeparator + path.JAVA_EXE;
if not FileExists(VJavaExe) then
raise ECriadorBanco.CreateFmt(
'Executável do Java não encontrado: "%s".', [VJavaExe]);
if not FileExists(path.CREATE_DB_JAR) then
raise ECriadorBanco.CreateFmt(
'Arquivo JAR não encontrado: "%s".', [path.CREATE_DB_JAR]);
VProcess := TProcess.Create(nil);
VResult := TStringList.Create;
try
VProcess.Executable := path.JAVA_EXE;
VProcess.Options := VProcess.Options + [poWaitOnExit, poUsePipes,
poStderrToOutPut];
VProcess.Parameters.Add('-jar');
VProcess.Parameters.Add(path.CREATE_DB_JAR);
VProcess.Parameters.Add('-d=' + ADatabase);
VProcess.Parameters.Add('-o=' + AOwner);
VProcess.Parameters.Add('-u=' + AUser);
VProcess.Parameters.Add('-p=' + APassword);
VProcess.Parameters.Add('-l=' + ALocale);
VProcess.Parameters.Add('-t=' + ATemplate);
VProcess.Execute;
VResult.LoadFromStream(VProcess.Output);
if (VResult.Count = 2) and (VResult[0] = 'Role successfully created')
and
(VResult[1] = 'Database successfully created') then
else
raise ECriadorBanco.Create(Trim(VResult.Text));
finally
VResult.Free;
VProcess.Free;
end;
end;
> PS: Glad you did find a workaround but... well...
=P~ =D
--
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20141029/88661077/attachment-0003.html>
More information about the Lazarus
mailing list