LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-13-2003, 10:14 PM   #1
meluser
Member
 
Registered: Mar 2003
Posts: 65

Rep: Reputation: 15
how to ensure only one record exist with the same name.


hi,

Could some one tell me how to ensure that only one record with the same name exits. i have a table called imageinfo, with 4 columns, image_id, image_name, image_size and image_date.

I would like to ensure that only one record exist with the same name.

thanks,

Mel
 
Old 03-13-2003, 10:20 PM   #2
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Not sure what you mean. Does this help?

Code:
struct table_t {
  char name [255];
  int id;
  int size;
  int date;
};

int main() {
  struct table_t imageinfo;
  //...
  return 0;
}

Last edited by GtkUser; 03-13-2003 at 10:21 PM.
 
Old 03-14-2003, 07:17 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
I think he was talking SQL .....
 
Old 03-14-2003, 08:00 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
I've never used SQL before, but I did play with Borland's Database Engine in Delphi a little.

So, aside from the brute force approach:
1) Read first record's filename
2) Look for a match in the rest of the database
3) Read second record's filename
4) Look for a match in the rest of the database
5) ...

There was an easier method in Borland:
1) Create a secondary index in the table based on the filename field (secondary indices do not need to contain only unique elements)
2) Sort the table based on this secondary index
3) Any duplicate filenames ought to be found consecutively when you walk through each record in the table

That assumes the filenames are case-sensitive (i.e. File1.img != file1.img).
 
Old 03-18-2003, 08:07 AM   #5
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,456

Rep: Reputation: 104Reputation: 104
1. SQL: u may make the column in the db "unique"
so the db will not allow a 2nd entry with the same value

2. if u manipulate data in a table using a programming language it would be useful to tell as which language u use, right?

i. e. there are different functions to retrieve the number of rows returned by a sql query

cheers, jens
 
Old 03-18-2003, 03:12 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
There's that marvelous thing in SQL called
an index, and one variant thereof supports
the feature unique ;)

Cheers,
Tink

P.S.: Once your database grows you'll
find that indexing also makes read access
much faster ;)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ensure that the complete development environment have been installed? Akhran Debian 3 08-16-2005 06:02 PM
Unable to record mic-in with SoundBlaster Live! while able to record other sources max76230 Linux - Newbie 2 03-14-2005 05:31 AM
how to ensure hdparrm settings are retained over a reboot? zero79 Debian 3 08-09-2004 05:15 PM
com ports, how do I find and ensure they are working Crasherz Linux - Newbie 1 04-09-2004 04:14 AM
pcfg_openfile: unable to check htaccess file, ensure it is readable andy18 Linux - General 4 08-21-2003 02:29 PM


All times are GMT -5. The time now is 01:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration