- XDB::execute('INSERT INTO newsletter_art
- SELECT {?}, MAX(aid)+1, {?}, '
- . ($a->_pos ? intval($a->_pos) : 'MAX(pos)+1')
- . ', {?}, {?}, {?}
- FROM newsletter_art AS a
- WHERE a.id = {?}',
- $this->_id, $a->_cid, $a->_title, $a->_body, $a->_append, $this->_id);
- $this->_arts['a' . $a->_aid] = $a;
+ XDB::startTransaction();
+ list($aid, $pos) = XDB::fetchOneRow('SELECT MAX(aid) AS aid, MAX(pos) AS pos
+ FROM newsletter_art AS a
+ WHERE a.id = {?}',
+ $this->_id);
+ $a->_aid = ++$aid;
+ $a->_pos = ($a->_pos ? $a->_pos : ++$pos);
+ XDB::execute('INSERT INTO newsletter_art (id, aid, cid, pos, title, body, append)
+ VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})',
+ $this->_id, $a->_aid, $a->_cid, $a->_pos,
+ $a->_title, $a->_body, $a->_append);
+ XDB::commit();