Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix some issues with UPDATE changes in the session module. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | sessions |
Files: | files | file ages | folders |
SHA1: |
57862efe718fdc93401998f905851129 |
User & Date: | dan 2011-03-12 17:22:46.000 |
Context
2011-03-14
| ||
19:49 | Fix handling of return values from the conflict handler. Document the conflict handler arguments and return codes in sqlite3session.h. (check-in: cbbb274e50 user: dan tags: sessions) | |
2011-03-12
| ||
17:22 | Fix some issues with UPDATE changes in the session module. (check-in: 57862efe71 user: dan tags: sessions) | |
2011-03-11
| ||
19:05 | Add the sqlite3changeset_apply() function. Does not yet handle all cases. (check-in: 2b19be7bf7 user: dan tags: sessions) | |
Changes
Changes to ext/session/sqlite3session.c.
︙ | |||
663 664 665 666 667 668 669 | 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | - + - + - + - + - - - - + + - - + - - + + + + + + + | if( *pRc==SQLITE_OK ){ SessionBuffer buf2 = {0, 0, 0}; int bNoop = 1; int i; u8 *pCsr = p->aRecord; sessionAppendByte(pBuf, SQLITE_UPDATE, pRc); for(i=0; i<sqlite3_column_count(pStmt); i++){ |
︙ | |||
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 | 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | if( rc==SQLITE_OK ){ rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, ppStmt, 0); } sqlite3_free(buf.aBuf); } return rc; } static int sessionConstraintConflict( sqlite3 *db, /* Database handle */ sqlite3_changeset_iter *pIter, /* Changeset iterator */ u8 *abPK, /* Primary key flags array */ sqlite3_stmt *pSelect, /* SELECT statement from sessionSelectRow() */ int(*xConflict)(void *, int, sqlite3_changeset_iter*), void *pCtx ){ int res; int rc; int i; int nCol; int op; const char *zDummy; sqlite3changeset_op(pIter, &zDummy, &nCol, &op); assert( op==SQLITE_UPDATE || op==SQLITE_INSERT ); /* Bind the new.* PRIMARY KEY values to the SELECT statement. */ for(i=0; i<nCol; i++){ if( abPK[i] ){ sqlite3_value *pVal; if( op==SQLITE_UPDATE ) rc = sqlite3changeset_old(pIter, i, &pVal); else rc = sqlite3changeset_new(pIter, i, &pVal); if( rc!=SQLITE_OK ) return rc; sqlite3_bind_value(pSelect, i+1, pVal); } } if( SQLITE_ROW==sqlite3_step(pSelect) ){ /* There exists another row with the new.* primary key. */ pIter->pConflict = pSelect; res = xConflict(pCtx, SQLITE_CHANGESET_CONFLICT, pIter); pIter->pConflict = 0; sqlite3_reset(pSelect); }else{ /* No other row with the new.* primary key. */ rc = sqlite3_reset(pSelect); if( rc==SQLITE_OK ){ res = xConflict(pCtx, SQLITE_CHANGESET_CONSTRAINT, pIter); } } return rc; } int sqlite3changeset_apply( sqlite3 *db, int nChangeset, void *pChangeset, int(*xConflict)( void *pCtx, /* Copy of fifth arg to _apply() */ |
︙ | |||
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 | 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 | + + + + + + + + + | sqlite3_stmt *pDelete = 0; /* DELETE statement */ sqlite3_stmt *pUpdate = 0; /* DELETE statement */ sqlite3_stmt *pInsert = 0; /* INSERT statement */ sqlite3_stmt *pSelect = 0; /* SELECT statement */ rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0); if( rc!=SQLITE_OK ) return rc; sqlite3changeset_start(&pIter, nChangeset, pChangeset); while( SQLITE_ROW==sqlite3changeset_next(pIter) ){ int op; const char *zThis; sqlite3changeset_op(pIter, &zThis, &nCol, &op); if( zTab==0 || sqlite3_strnicmp(zThis, zTab, nTab+1) ){ sqlite3_free(azCol); rc = sessionTableInfo(db, zThis, nCol, &zTab, &azCol, &abPK); nTab = strlen(zTab); sqlite3_finalize(pDelete); sqlite3_finalize(pUpdate); sqlite3_finalize(pInsert); sqlite3_finalize(pSelect); pSelect = pUpdate = pInsert = pDelete = 0; if( (rc = sessionSelectRow(db, zTab, nCol, azCol, abPK, &pSelect)) || (rc = sessionUpdateRow(db, zTab, nCol, azCol, abPK, &pUpdate)) || (rc = sessionDeleteRow(db, zTab, nCol, azCol, abPK, &pDelete)) ){ break; } } if( op==SQLITE_DELETE ){ int res; int i; rc = sessionDeleteRow(db, zTab, nCol, azCol, abPK, &pDelete); for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
︙ | |||
1555 1556 1557 1558 1559 1560 1561 | 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 | - + | rc = sqlite3changeset_old(pIter, i, &pOld); if( rc==SQLITE_OK ){ rc = sqlite3changeset_new(pIter, i, &pNew); } if( rc==SQLITE_OK ){ if( pOld ) sqlite3_bind_value(pUpdate, i*3+1, pOld); sqlite3_bind_int(pUpdate, i*3+2, !!pNew); |
︙ | |||
1588 1589 1590 1591 1592 1593 1594 | 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 | + + + + - + + + + + + + + + + + + + + + + + + + + + + | }else{ rc = sqlite3_reset(pSelect); if( rc==SQLITE_OK ){ res = xConflict(pCtx, SQLITE_CHANGESET_NOTFOUND, pIter); } } }else if( rc==SQLITE_CONSTRAINT ){ /* This may be a CONSTRAINT or CONFLICT error. It is a CONFLICT if ** the only problem is a duplicate PRIMARY KEY, or a CONSTRAINT ** otherwise. */ int bPKChange = 0; |
︙ | |||
1620 1621 1622 1623 1624 1625 1626 | 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 | - - + - - - - - - - - - - - - - - - + + - - - - - - | } } if( rc!=SQLITE_OK ) break; sqlite3_step(pInsert); rc = sqlite3_reset(pInsert); if( rc==SQLITE_CONSTRAINT && xConflict ){ |
︙ |
Changes to test/session1.test.
︙ | |||
255 256 257 258 259 260 261 262 263 | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | + + - + + + - - + + + + - + + + - - + + - | # Test UPDATE changesets. # do_execsql_test 3.3.1 { CREATE TABLE t4(a, b, c, PRIMARY KEY(b, c)); INSERT INTO t4 VALUES(1, 2, 3); INSERT INTO t4 VALUES(4, 5, 6); INSERT INTO t4 VALUES(7, 8, 9); INSERT INTO t4 VALUES(10, 11, 12); } do_db2_test 3.3.2 { |