270
In every INSERT operation, the field values are checked for a preexisting duplicate.
The primary key field in the table is checked using the isPrimaryKey()function (line
423). If the key is a duplicate, the error HA_ERR_FOUND_DUPP_KEY is returned. The
isPrimaryKey() is implemented in Listing 13-8.
Listing 13-8. ha_pmdk.cc – Checking for duplicate primary keys
462 bool ha_pmdk::isPrimaryKey(void)
463 {
464
bool ret = false;
465
database *db = database::getInstance();
466
table_ *tab;
467
key *k;
468
for (unsigned int i= 0; i < table->s->keys; i++) {
469
KEY* key_info = &table->key_info[i];
470
if (memcmp("PRIMARY",key_info->name.str,sizeof("PRIMARY"))==0) {
471
Field *field = key_info->key_part->field;
472
std::string convertedKey = IdentifyTypeAndConvertToString
(field->ptr, field->type(),field->key_length(),1);
473
if (db->getTable(table->s->table_name.str, &tab)) {
474
if (tab->getKeys(field->field_name.str, &k)) {
475
if (k->verifyKey(convertedKey)) {
476
ret = true;
477
break;
478
}
479
}
480
}
481
}
482
}
483
return ret;
484 }
UPDATE Operation
The server executes UPDATE statements by performing a rnd_init() or index_init()
table scan until it locates a row matching the key value in the WHERE clause of the UPDATE
statement before calling the update_row() method. If the table is an indexed table, the
Chapter 13 enabling persistenCe Using a real-World appliCation
Précédent

- 294/457

Suivant