Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-02

Connecting to a database from a commandline pascal program

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Terry A. Haimann

Hello,

I am trying to write a command Line Pascal program to connect to a MySQL database using the ZeosDBO Library. I am sure I have done something stupid.

I have it now so that it will compile, but it crashes as soon as I try to modify my TZConnection variable.

I have it defined as:

	MyConnection:		TZconnection;

And code is defined as:

	WriteLn('2');
	MyConnection.Create(Nil);
	// MyQuery.Create(Nil);
	WriteLn('2.0);
	MyConnection := '127.0.0.1';
	WriteLn('2.1');
	MyConnection.Protocol	:= 'mysql';
	WriteLn('2.2');
	MyConnection.Database 	:= 'MyDatabase';
	WriteLn('2.3');
	MyConnection.User	:= 'MyUser';
	WriteLn('2.4');
	MyConnection.Password 	:= 'MyPass';
	WriteLn('2.5');
	MyConnection.Connected := True;
	WriteLn('2.6');

It never hits 2.0, so I believe it is dying on the create. Am I doing the create wrong? I can't find any examples as too doing this, I have tried googling it. Most of the examples I see are doing this from Lazarus. Not from a command line Free Pascal program.

Thanks in advance, Terry H.

Reply by email

DaWorm
to Terry A. Haimann

Wouldn't this...

MyConnection.Create(Nil);
// MyQuery.Create(Nil);

... be more like...

MyConnection := TZConnection.Create();
MyQuery := TQuery.Create();

Then at the end you'd need...

MyQuery.Free();
MyConnection.Free();

Jeff

Terry A. Haimann wrote 43 lines
Hello, I am trying to write a command Line Pascal program to connect to a MySQL database using the ZeosDBO Library. I am sure I have done something stupid. I have it now so that it will compile, but it crashes as soon as I try to modify my TZConnection variable. I have it defined as: MyConnection: TZconnection; And code is defined as: WriteLn('2'); MyConnection.Create(Nil); // MyQuery.Create(Nil); WriteLn('2.0); MyConnection := '127.0.0.1'; WriteLn('2.1'); MyConnection.Protocol := 'mysql'; WriteLn('2.2'); MyConnection.Database := 'MyDatabase'; WriteLn('2.3'); MyConnection.User := 'MyUser'; WriteLn('2.4'); MyConnection.Password := 'MyPass'; WriteLn('2.5'); MyConnection.Connected := True; WriteLn('2.6'); It never hits 2.0, so I believe it is dying on the create. Am I doing the create wrong? I can't find any examples as too doing this, I have tried googling it. Most of the examples I see are doing this from Lazarus. Not from a command line Free Pascal program. Thanks in advance, Terry H. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Mark Morgan Lloyd
to Terry A. Haimann: I am trying to write a command Line Pascal program to connect to a MySQL database using…
Terry A. Haimann wrote 9 lines
Hello, I am trying to write a command Line Pascal program to connect to a MySQLdatabase using the ZeosDBO Library. I am sure I have done somethingstupid. I have it now so that it will compile, but it crashes as soon as I tryto modify my TZConnection variable. I have it defined as: MyConnection: TZconnection; And code is defined as: WriteLn('2'); MyConnection.Create(Nil); // MyQuery.Create(Nil); WriteLn('2.0); MyConnection := '127.0.0.1'; WriteLn('2.1'); MyConnection.Protocol := 'mysql'; WriteLn('2.2'); MyConnection.Database := 'MyDatabase'; WriteLn('2.3'); MyConnection.User := 'MyUser'; WriteLn('2.4'); MyConnection.Password := 'MyPass'; WriteLn('2.5'); MyConnection.Connected := True; WriteLn('2.6'); It never hits 2.0, so I believe it is dying on the create. Am I doingthe create wrong? I can't find any examples as too doing this, I havetried googling it. Most of the examples I see are doing this fromLazarus. Not from a command line Free Pascal program.
Shouldn't that be  MyConnection := TZconnection.Create(nil);
Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email