A place for users and developers of the Xataface to discuss and receive support.
by andperry » Fri May 22, 2009 6:00 am
I have a table with a record ID as the primary key where the record ID is a meaningful mnemonic that is chosen by the user at the time of creating the record. I have noticed that when attempting to create a new record with a record ID that is already in use, the existing record gets overwritten. Is this really right? I would expect an error response if attempting to duplicate a primary key.
Am I missing something?
Thanks,
Andrew.
-
andperry
-
- Posts: 57
- Joined: Wed Feb 18, 2009 9:20 am
- Location: Wirral, UK
by andperry » Sat May 23, 2009 1:08 am
Many thanks for the reply. I've actually already looked at one of the links.
I have tried the recommended action which is to ensure that the field in question is unique, but to no avail. The questions I'm asking are:-
1. Is it a problem with the particular MySQL installation?
2. Is it a bug in Xataface?
3. Do I need to write some validation code?
I can obviously try and write some validation code but this does not seem the ideal option if there is another solution.
Thanks,
Andrew.
-
andperry
-
- Posts: 57
- Joined: Wed Feb 18, 2009 9:20 am
- Location: Wirral, UK
by andperry » Mon May 25, 2009 12:12 am
I've tried a few more things which may hopefully give a better clue as to what is going on.
Firstly I tried inserting two records with the same ID via SQL command lines in phpMyAdmin. As expected the second one failed due to attempted duplication.
I then tried writing a BeforeInsert method for the table so as to try and trap the error if a record already exists with the given ID. BeforeInsert doesn't even get called when trying to add the second record! (I put in a print statement and a die statement just to see if the function code was being entered.) It would appear therefore that on attempting to add the second record, Xataface is going down the route of an edit rather than an insertion.
Any ideas what is wrong?
Many thanks,
Andrew.
-
andperry
-
- Posts: 57
- Joined: Wed Feb 18, 2009 9:20 am
- Location: Wirral, UK
by andperry » Mon May 25, 2009 12:25 am
This might seem trivial but I've just noticed in my previous post that I wrote 'BeforeInsert'. Yes I did get the case correct (i.e. 'beforeInsert') in my code, because along the way I did prove that it was being called when inserting first the record! Thanks.
-
andperry
-
- Posts: 57
- Joined: Wed Feb 18, 2009 9:20 am
- Location: Wirral, UK
by silma » Mon May 25, 2009 1:27 am
Hello,
This is maybe a (really) stupid question but are you sure you insert "new" records ?
I mean, in my own xataface installation, the application used to behave like this : After a new record insertion it show the edition page of the record i'd just inserted, with a message "Record successfully added".
So, when i tried to insert many record successively, i edited many time the first record. (Ok, i was maybe not well woken... )
In order to avoid this, i "forced" the application to show the list page after a new insert, and not the edit page.
Sorry for the english,
Silma
-
silma
-
- Posts: 87
- Joined: Tue Apr 28, 2009 11:47 pm
by andperry » Tue May 26, 2009 1:43 am
Many thanks again for your help. I've managed to find a solution which I will now list for the benefit of anyone else with a similar problem. The table is 'people' and the primary key is 'rec_id' for which I have written the following validation method:-
<PRE>
function rec_id__validate( &$record, $value, &$params=array())
{
$app =&Dataface_Application::getInstance();
$query =&$app->getQuery();
$return_val = true;
if ($query['-action']=='new')
{
$result = mysql_query("SELECT * FROM people WHERE rec_id='$value'");
if (mysql_num_rows($result)>0)
{
$params['message'] = "Duplicate Record ID";
$return_val = false;
}
}
return $return_val;
}
</PRE>
It works a treat and although it seems less than ideal to have to do this, I'm happy to go with it at present, as the application now does what it is meant to be doing.
Steve - If you get a chance to look at this at some point (no hurry and I know you must be very busy), I would still be interested to know what you think. I am curious as to whether there is a problem in Xataface or whether I am doing something wrong.
Thanks,
Andrew.
-
andperry
-
- Posts: 57
- Joined: Wed Feb 18, 2009 9:20 am
- Location: Wirral, UK
by shannah » Tue Jun 02, 2009 10:26 am
andperry wrote:I have a table with a record ID as the primary key where the record ID is a meaningful mnemonic that is chosen by the user at the time of creating the record. I have noticed that when attempting to create a new record with a record ID that is already in use, the existing record gets overwritten. Is this really right? I would expect an error response if attempting to duplicate a primary key.
Am I missing something?
Thanks,
Andrew.
What version of Xataface are you using? This shouldn't be happening.
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by andperry » Sun Jun 07, 2009 12:53 pm
version.txt file says 1.1.5r2 984.
MySQL Version 5.0.82
PHP Version 5.2.9
Hope this is of help. Yes I agree this should not be happening.
-
andperry
-
- Posts: 57
- Joined: Wed Feb 18, 2009 9:20 am
- Location: Wirral, UK
Return to Xataface Users
Who is online
Users browsing this forum: No registered users and 22 guests
|