Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/lisk/LiskDAO.php
| Show First 20 Lines • Show All 1,143 Lines • ▼ Show 20 Lines | public function update() { | ||||
| foreach ($map as $key => $value) { | foreach ($map as $key => $value) { | ||||
| if (!empty($binary[$key])) { | if (!empty($binary[$key])) { | ||||
| $map[$key] = qsprintf($conn, '%C = %nB', $key, $value); | $map[$key] = qsprintf($conn, '%C = %nB', $key, $value); | ||||
| } else { | } else { | ||||
| $map[$key] = qsprintf($conn, '%C = %ns', $key, $value); | $map[$key] = qsprintf($conn, '%C = %ns', $key, $value); | ||||
| } | } | ||||
| } | } | ||||
| $map = implode(', ', $map); | |||||
| $id = $this->getID(); | $id = $this->getID(); | ||||
| $conn->query( | $conn->query( | ||||
| 'UPDATE %R SET %Q WHERE %C = '.(is_int($id) ? '%d' : '%s'), | 'UPDATE %R SET %LQ WHERE %C = '.(is_int($id) ? '%d' : '%s'), | ||||
| $this, | $this, | ||||
| $map, | $map, | ||||
| $this->getIDKeyForUse(), | $this->getIDKeyForUse(), | ||||
| $id); | $id); | ||||
| // We can't detect a missing object because updating an object without | // We can't detect a missing object because updating an object without | ||||
| // changing any values doesn't affect rows. We could jiggle timestamps | // changing any values doesn't affect rows. We could jiggle timestamps | ||||
| // to catch this for objects which track them if we wanted. | // to catch this for objects which track them if we wanted. | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | foreach ($data as $key => $value) { | ||||
| pht( | pht( | ||||
| "Unable to insert or update object of class %s, field '%s' ". | "Unable to insert or update object of class %s, field '%s' ". | ||||
| "has a non-scalar value.", | "has a non-scalar value.", | ||||
| get_class($this), | get_class($this), | ||||
| $key), | $key), | ||||
| $parameter_exception); | $parameter_exception); | ||||
| } | } | ||||
| } | } | ||||
| $data = implode(', ', $data); | |||||
| switch ($mode) { | |||||
| case 'INSERT': | |||||
| $verb = qsprintf($conn, 'INSERT'); | |||||
| break; | |||||
| case 'REPLACE': | |||||
| $verb = qsprintf($conn, 'REPLACE'); | |||||
| break; | |||||
| default: | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Insert mode verb "%s" is not recognized, use INSERT or REPLACE.', | |||||
| $mode)); | |||||
| } | |||||
| $conn->query( | $conn->query( | ||||
| '%Q INTO %R (%LC) VALUES (%Q)', | '%Q INTO %R (%LC) VALUES (%LQ)', | ||||
| $mode, | $verb, | ||||
| $this, | $this, | ||||
| $columns, | $columns, | ||||
| $data); | $data); | ||||
| // Only use the insert id if this table is using auto-increment ids | // Only use the insert id if this table is using auto-increment ids | ||||
| if ($id_mechanism === self::IDS_AUTOINCREMENT) { | if ($id_mechanism === self::IDS_AUTOINCREMENT) { | ||||
| $this->setID($conn->getInsertID()); | $this->setID($conn->getInsertID()); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 768 Lines • Show Last 20 Lines | |||||