Solved

Delphi using Postgresql unique primary key

Posted on 2001-07-12
8
775 Views
Last Modified: 2011-09-20
Hello,

I'm trying to use a postgresql database from my Delphi application. This database has a sequence called 'uniquenumbergenerator' which should create a unique id for every database entry made.
I've tried 2 things to make this work:

1. I used a query with SQL: 'Select nextval('uniquenumbergenerator')';
2. I used the stored procedure nextval with arguments Input: String 'uniquenumbergenerator' and Result: integer

Problems with these things:
1. I tried to Close and Open the query directly behind each other:
Query.Open;
Query.Close;
And then I tried to read the value of the nextval. Executed 2 times within 20 statement behind eachother, this returned me the SAME values!!

2. Same story, I called these procedures within 20 statements from eachother and I got the same values for the unique numbers.

I think this problem has something to do with caching or something like this....

I have installed the postgresql ODBC driver on Windows 98 and everything works with the database, only these requests for unique values occuring behind eachother, do not work.

I am really stuck with this one, because my application cannot run without this problem solved, so that's why I offer 300 points to solve this one.

Greetings,

Martijn Beelen
0
Comment
Question by:martijnbeelen
  • 3
  • 3
  • 2
8 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6278531
Can't you just create a field in the table that does autonumber?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6278545
Also take a look here:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20149488

It's about Interbase, but maybe it can help you...
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 300 total points
ID: 6279721
use the storedproc, with the execproc-method

listening . . .

meikl ;-)
0
 

Author Comment

by:martijnbeelen
ID: 6280028
This works indeed:

StoredProc1.ExecProc;
ID := StoredProc1.ParambyName('ID').AsInteger;

Greetings,

Martijn
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 13

Expert Comment

by:Epsylon
ID: 6280049
:o(
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6280056
hu, thanks for the points :-))

glad that you get it work
good luck again

meikl ;-)

(sorry eps)
0
 

Author Comment

by:martijnbeelen
ID: 6280097
Epsylon,

Could you answer my other question (for 100 points..)

It's called "Connect Delphi to Postgresql"

Martijn
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6280310
ah, now i understand the other q :-)))
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now