This is a follow up feature request based on http://drupal.org/node/169982. As we have already introduce drupal_write_record(), which abstracted most database related stuff, where provide a handy and powerful interface for most developers, we may also hope to apply this idea for "drop record". The patch attached provide an implementation of drupal_drop_record() based on this consideration.

On the other hand, we may move down the level of SQL builder into database abstraction level, and so left application level abstraction clean (drupal_write_record()/drupal_drop_record()). There is a lot of benefit, which mentioned in http://buytaert.net/scaling-with-mysql-replication#comment-2206. On the hand, as the required syntax of INSERT/UPDATE/DELETE is sometime case-by-case due to different database-specific requirement, moving the SQL builder into database abstraction level can provide more flexibility within our feature development and research.

The patch comes with few modification:

  1. Review drupal_write_record(): remove useless code, coding style clean up, and make use of db_query_insert()/db_query_update()
  2. Add drupal_drop_record(): clone handling from drupal_write_record(), and make use of db_query_delete()
  3. Add db_query_inert(), db_query_update() and db_query_delete() for mysql/mysqli/pgsql: INSER/UPDATE/DELETE query builders. I keep these functions input as "raw" mode (e.g. placeholder as "%s" syntax) but not in schema API level (e.g. field type as "text" syntax) for avoiding the highly integration with schema API: this is not the duty of database abstraction level, but application level, and so keep it as "raw" as it can
  4. Update node_delete(): make use of drupal_drop_record() as a demonstration

Comments

hswong3i’s picture

StatusFileSize
new15.34 KB

patch reroll due to minor coding style update.

moshe weitzman’s picture

Title: Missing feature from schema API: drupal_drop_record + INSERT/UPDATE/DELETE abstraction » INSERT/UPDATE/DELETE DB abstraction and drupal_drop_record
Version: 6.x-dev » 7.x-dev
hswong3i’s picture

Version: 7.x-dev » 6.x-dev

@moshe: May I have more information about the needs of postpone this issue? I can't see the different of this issue with drupal_write_record(): it just just to complete the existing handling. We need write record, and so as drop record? They are always a pair, isn't it?

hswong3i’s picture

Title: INSERT/UPDATE/DELETE DB abstraction and drupal_drop_record » drupal_drop_record and INSERT/UPDATE/DELETE DB abstraction

I guess this is the correct order of priority of my concern about this issue. INSERT/UPDATE/DELETE API is just a bonus of drupal_write_record() (and drupal_drop_record() that I am now proposing).

BTW, as we are able to handle the query builder better within DB level, I can't see the reason of not implement it: they are handy enough, and won't break any existing code implementation; they are even transparency to normal developers if they use drupal_write_record() and drupal_drop_record() :)

Crell’s picture

Version: 6.x-dev » 7.x-dev

1) This is coming in later than drupal_write_record(), and any new features post-freeze need a very strong justification. You saw how hard it was to get drupal_write_record() implemented.

2) The need here is not as strong as it was for drupal_write_record().

3) This is already slated for inclusion in Drupal 7. Heck, it's already written for Drupal 7, with more robust handling of UPDATE and DELETE queries.

I'm tempted to "won't fix" this.

hswong3i’s picture

Version: 7.x-dev » 6.x-dev
Priority: Normal » Critical

1. I can't see why it is not strong enough: we are planed for drupal_drop_record(), but just miss it. The constant "SAVED_DELETED" is already preserved (common.inc: 25), and also used in taxonomy (taxonomy.module: 220) with very lossy coding style. We won't hope to use this constant without any helper function as abstraction, which similar to the case of drupal_write_record().

2. The demo for node_delete() show that we will able to handle the DELETE action as simple as using drupal_write_record(). On the other hand, ADD/DROP actions are always considered as pair. Without drupal_drop_record(), contribute developers may feel very confuse about this double standard (Add by handy helper function, but manually drop is required...)

3. Seems there is no direct relationship of this INSERT/UPDATE/DELETE API implementation with yours version: your version is target for PDO which should belongs to D7 (very robust, I really love it), but I am working for D6 which duel with existing database abstraction requirement. On the other hand, if this is something that we are able to implement with no pain (transparency, and just a split version of what drupal_write_record() does) even within current development cycle, I can't see a strong reason for postponing it :(

I think this issue is even "critical" now, as we are really miss out an important function (drupal_drop_record()) for standardize both the ADD/DROP handling, which will introduce confuse to contribute developers :(

JirkaRybka’s picture

Priority: Critical » Normal

At the very least, I think this is not critical. Critical means that something is broken.

moshe weitzman’s picture

Version: 6.x-dev » 7.x-dev

no features for 6, especially ones that don't have compelling arguments. we can't make major changes to the DB API at this stage.

hswong3i’s picture

Version: 7.x-dev » 6.x-dev

@moshe: I think that should be different concern about drupal_drop_record() and INSERT/UPDATE/DELETE abstraction.

According to drupal_drop_record(), it is something that we are now missing, even it is not as important as drupal_write_record(). They should always considered as a pair-up handling with no question. Since it is just a clone to drupal_write_record(), I am strongly suggest about reconsidering its possibility within D6.

On the other hand, INSERT/UPDATE/DELETE abstraction should be consider in different way: if we feel not happy about this 3 simple functions, just not implement them, and let drupal_drop_record() alive in D6. They are just a bonus. BTW, according to existing founding of Crell, this abstraction is very meaningful which should be implemented (on someday, with some sort of implementation). Even it is scheduled for D7 with the help of PDO powerful "?" placeholder, my implementation is just what we needed for based on our existing database abstraction layer requirement. Moreover, we should even seems it as the "split" handling of query builder which is currently existed within drupal_write_record(): it is nothing special other than this.

Finally, they are all optional API, which similar as drupal_write_record(): we will not died even don't have drupal_write_record(), and able to wait for it in D7; but we let it be, based on many different concerns. We don't need to force anyone to use these new feature. It won't break any existing handling, and the use of helper functions (db_query_insert(), etc) are even transparency. They don't CHANGE any existing DB API. I am not blame on the slide in of drupal_write_record() (it is very powerful and handy, and I really love it, as the point of view of normal contribute developer), but I am confusing about this double standard of similar issue.

It sounds too pity if we need to wait for this until D7 :(

moshe weitzman’s picture

Version: 6.x-dev » 7.x-dev

hswongi - you are stubborn beyond belief. the patch as it stands now makes unacceptable DB API changes for d6. thats non negotiable. if you want to submit a less intrusive patch, then do so.

we always have great code which "is a pity" because it gets left out. thats what a code freeze is all about.

Anonymous’s picture

@hswong3i: Your idea may be good but to butt heads with the code freeze is worthless. New features, which this is, belongs in the next working patch version which is 7.x.

hswong3i’s picture

Title: drupal_drop_record and INSERT/UPDATE/DELETE DB abstraction » Missing feature: drupal_drop_record()
Version: 7.x-dev » 6.x-dev
StatusFileSize
new5.38 KB

This is a simplified version without abstraction for INSERT/UPDATE/DELETE API. It add the missing function drupal_drop_record(), update some coding style in drupal_write_record(), and modify node_delete() as demo handling. The change is transparency to normal developers, which don't break any existing code implementation, but keep the write/drop abstraction as synchronized. Should we give a little bit love to it, in order to complete our existing handling?

hswong3i’s picture

Patch attached is the incremental change for adding INSERT/UPDATE/DELETE abstraction below drupal_write_record() and drupal_drop_record(), as a database dependent implementation. This can indicate clearly about how the bonus abstractions are able to simplify existing handling.

Please feel free to forget about this incremental patch if it is not suitable for D6, I will come back with this abstraction later. BTW, hope for a kindly reconsideration about drupal_drop_record(), as it is very meaningful to normal contribute developers.

hswong3i’s picture

Patch update via latest CVS HEAD, with some syntax tidy up. This patch is now tested for both MySQL 5.0.32 and PostgreSQL 8.1.9 on Debian etch 4.0r1 with PHP 5.2.0-8+etch7, passed with node create, revision update and delete (so both case for INSERT/UPDATE/DELETE). Feature benefit as listed above. Should be trivial to commit.

hswong3i’s picture

A complete "PLUS" version based on #14, with INSERT/UPDATE/DELETE abstraction. Completely tested as case above, passed with no error, and proved as a completely transparency implementation. Should also be trivial to commit.

dries’s picture

Version: 6.x-dev » 7.x-dev

This is D7 material.

hswong3i’s picture

Title: Missing feature: drupal_drop_record() » Siren #3: INSERT/UPDATE/DELETE API + drupal_drop_record()
chx’s picture

Title: Siren #3: INSERT/UPDATE/DELETE API + drupal_drop_record() » INSERT/UPDATE/DELETE API + drupal_drop_record()

As Siren is not a project on Drupal.org but an unofficial fork, I am removing it from issue titles to avoid confusion.

hswong3i’s picture

Category: feature » task
Priority: Normal » Critical
StatusFileSize
new16.11 KB

Since D7 is now open for public development, this patch is reroll via CVS HEAD. The patch include:

  • Add INSER/UPDATE/DELETE API: a simple abstraction which don't degrade any existing performance (please refer to a complete benchmarking result). On the other hand, it is very important for oci8 and pdo_oci implementation (please refer to a functional Oracle driver implementation).
  • Add drupal_drop_record(). Synchronize with drupal_write_record() as a pair-up handling.
  • Enhance drupal_write_record() with INSERT/UPDATE/DELETE API.
  • Enhance cache_set() with INSERT/UPDATE/DELETE API, as an individual example.

Completely tested with MySQL and PostgreSQL.

Crell’s picture

Status: Needs review » Closed (duplicate)

This is now handled by this issue: http://drupal.org/node/225450