Comments (7)
Is there the possibility that someone inserted some records in the table without using p4a sequences management functions?
from p4a.
Exactly that. Sure it is a solution to use the p4a management functions also for all non p4a inserts. But I think with a few changes p4a can also "recover" the _seq id correctly. Probably something like "SELECT max($PK) FROM $table;" could work.
from p4a.
This mask will allow you to manually reset the ID tables. It's possible to add elements of this code to the construct section of a mask to fix any issues between a manual insertion and the mask opening. If data is incoming simultaneous to the mask being open, I guess you'd need to check on an onSave event.
It's a clunky solution to a real problem I've come across in about 3 projects i the last 12 months or so. It would be great if this whole method of indexing was dumped for something more robust.
build("p4a_db_source", "s1") ->setTable("rota") ->setPk("id"); $this->build("p4a_db_source", "s2") ->setTable("service_users") ->setPk("id"); $this->build("p4a_db_source", "s3") ->setTable("staff") ->setPk("id"); $this->build("p4a_db_source", "s4") ->setTable("worktypes") ->setPk("id"); $this->build("p4a_db_source", "s5") ->setTable("leave") ->setPk("id"); $this->build("p4a_button", "btn_resync") ->setLabel("resync") ->implement("onclick", $this, "resync_seq_table"); $this->frame->anchor($this->btn_resync); $this->display("menu", P4A::singleton()->menu); $this->setTitle(P4A::singleton()->storename." :: Tables Repairer"); } public function resync_seq_table() { $res = $this->s1->resync_seq(); $res = $this->s2->resync_seq(); $res = $this->s3->resync_seq(); $res = $this->s4->resync_seq(); $res = $this->s5->resync_seq(); } ``` } ?>from p4a.
... and the library file to go with it
./p4a/libraries/p4a_db_source_resync_seq.php
getTable(); $pKField = $source->getPk(); $seqTable = $table."_".$pKField."_seq"; $lastId = P4A_DB::singleton()->fetchOne("SELECT MAX($pKField) FROM `$table`;"); $query = "DROP TABLE IF EXISTS `$seqTable`"; $resQ1 = P4A_DB::singleton()->query($query); $query = "CREATE TABLE `$seqTable` ( `id` int(11) NOT NULL auto_increment, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=$lastId"; $resQ2 = P4A_DB::singleton()->query($query); $query = "INSERT INTO `$seqTable` VALUES ($lastId)"; $resQ3 = P4A_DB::singleton()->query($query); return ($resQ1 && $resQ2 && $resQ3); } ?>from p4a.
actually you should use p4a's functions to get a new sequence number when you're using those table from outside.
btw with p4a3 it should be able to use autoincrement primary keys instead of p4a's sequences (with were made strictly for data portability between different db engines), you could try disabling P4A_AUTO_DB_SEQUENCES, what do you think?
from p4a.
Thanks. Yes, I think this is the best solution and I set P4A_AUTO_DB_SEQUENCES in /p4a/p4a/constants.php to false. It seems to work fine. Probably the default setting should be "false", if the database engine supports it. Do you know if there is any database engine, where P4A_AUTO_DB_SEQUENCES should be true?
from p4a.
it's true for historical reasons and now we cannot change this value cause it would break existing data. :)
it should be true for a specific database engine, the problem is data portability between engines.
from p4a.
Related Issues (20)
- Contribs HOT 3
- Just a small modification :) HOT 1
- How to add a js to specific mask
- The multivalue fields are not refresing HOT 2
- AJAX call doesn't finish HOT 8
- P4A 3.8.5 calendar (...) bug HOT 3
- Some weird error in CKEditor and Chrome HOT 9
- More AJAX HOT 2
- Dependency Injection as feature request
- Composer PHP as autoloader, feature request HOT 1
- Add field type "timestamp" in db_source.php
- Accessibility (?) HOT 9
- Add a audit trail that can be shown online
- use field type select if a field has an foreign key
- NOTICE "Non-static" on startup HOT 1
- Mask's scalability HOT 1
- Use db field comment for automatic Tooltip HOT 1
- add a "copy record" button HOT 5
- Modeldriven development for P4A - suggestion HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p4a.