| Recommend this page to a friend! |
| DrasticTools | > | All threads | > | Primary Key/Unique Index Problem | > | (Un) Subscribe thread alerts |
| |||||||||||||||
Hello
First i want to say i like your grid i think you did a awesome job. On to the problem. First here are the starting parameters. I have a database table with two fields ID and Name ID and Name both have Primary Keys This is because id must be auto increment Name must also be so that no duplicate entries can exist. This can also be done with using a index in either case the grid will fail. Second i can get the grid to show up just fine and can sort either column and so on. The problem is with editing and adding rows. With the grid as is with starting parameters. The id field is what is editable not the name field. I can add a row like this but can not enter a name in the name field. If i change constructor too say Name field is editable then it works but only on the web page the database will not update the new name but it will add the new record id so a row is created but with no value in the name field. This happens both for using the name field as a primary key along with the id field or by getting rid of the primary key in the name field and just creating a unique index on name field. If i have neither a primary key or a unique index for the name field then the grid works like it is supposed too. Now i could create a enum field for name, but then i wind up with a situation where the enum is not editable via the grid. Too actually edit the enum the only way i know is to actually use the alter table statement with all previous values of the enum in the syntax. I have never found a actual solution to edit a enum properly outside of the alter table statement. So is there a work around for using more then one primary key or a unique index?
Dear Tink,
The current version of drasticSrcMySQL.class.php has a rather simple mechanism to detect which column to use as "id" column. It takes either a primary key or one of the unique keys, which comes last. In your case the algorithm takes the wrong column as id, the name column. I made the mechanism a little more advanced so that it gives preference to the column with the primary key instead of the column with unique keys. This would solve your problem if you make the name column just unique (not primary!). The fix will be included in the coming version of DrasticTools. However, I would you to test it out first. Would you be so kind to email your adress to drasticdata, see http://www.drasticdata.nl In that case I will mail you a beta release with the fix in it to test it out. regards, Olav
Hello
thx for the quick reply. Im a little confused at your request of possible work around. From what i gather you want me to use the name field as a unique field. I have done that too. As long as the id field also has the primary key also it still fails. I have not tried it with just the name field being unique with the id field being just another field without being either primary or unique. In my case as the id field has to have auto increment even if i just changed the fields to be like that. With the id field being just a regular numeric field with no conditions and the name field being a unique field. Will result in some bad situations for me as i have other sql calls based on the id field being a auto increment which requires being a primary key. My technial knowledge of java is very small i primarily a novice php coder maybe a bit more then a novice but i would not call myself a professional code php developer but i can usually work my way around things or with enough time figure a result out. I love the idea of ajax but then that requires more knowledge of java and as i stated before it is very small. It would be great i think if it was possible if the option of actually choosing the primary or unique key was possible. I think that would not only solve my problem but possibly others. One last question though if you dont mind. I noticed in your examples you are using a enum type field. Which reslut in a dropdown menu which is very nice indeed. Enum type fields are nice but the ability to update them is very limited to a ALTER TABLE statement. I have never been able to develop a enum script that would allow you to update the enum via a form. I have noticed that phpmyadmin has the abililty to use a form to update the enum but i have never been able to figure out what they are doing. I have looked for a result of this for so long with no solution. Is it possible for you to add such a option of updating a enum type field? In my case that would solve the primary key unique key situation as i could then just change those fields to enum the added dropdown menu display in your grid would solve all of the related issues i am having right now. I tried the email addy on phpclasses here that is listed for you and looked on your web site for a contact link. The email addy here came up with a permanent error for that email addy. On your web site i could find no contact link for a email addy there. So please contact me from my addy below. You could reach me at this email addy [email protected] Again thx for your quick replay. |
info at phpclasses dot org.
