Solved

Delphi using Postgresql unique primary key

Posted on 2001-07-12
8
782 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:martijnbeelen
ID: 6280028
This works indeed:

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

Greetings,

Martijn
0
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 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