LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to ensure only one record exist with the same name. (https://www.linuxquestions.org/questions/programming-9/how-to-ensure-only-one-record-exist-with-the-same-name-49722/)

meluser 03-13-2003 09:14 PM

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

GtkUser 03-13-2003 09:20 PM

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;
}


Hko 03-14-2003 06:17 PM

I think he was talking SQL .....

Dark_Helmet 03-14-2003 07:00 PM

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).

j-ray 03-18-2003 07:07 AM

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

Tinkster 03-18-2003 02:12 PM

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 ;)


All times are GMT -5. The time now is 11:50 PM.