Package org.tmatesoft.sqljet.core

Examples of org.tmatesoft.sqljet.core.SqlJetException


                int pageSize;
                int usableSize;
                ISqlJetMemoryPointer page1 = pPage1.aData;
                rc = SqlJetErrorCode.NOTADB;
                if (SqlJetUtility.memcmp(page1, zMagicHeader, 16) != 0) {
                    throw new SqlJetException(rc);
                }
                if (SqlJetUtility.getUnsignedByte(page1, 18) > 1) {
                    pBt.readOnly = true;
                }
                if (SqlJetUtility.getUnsignedByte(page1, 19) > 1) {
                    throw new SqlJetException(rc);
                }

                /*
                 * The maximum embedded fraction must be exactly 25%. And the
                 * minimum embedded fraction must be 12.5% for both leaf-data
                 * and non-leaf-data. The original design allowed these amounts
                 * to vary, but as of version 3.6.0, we require them to be
                 * fixed.
                 */
                if (SqlJetUtility.memcmp(page1, 21, PAGE1_21, 0, 3) != 0) {
                    throw new SqlJetException(rc);
                }

                pageSize = SqlJetUtility.get2byte(page1, 16);
                if (((pageSize - 1) & pageSize) != 0 || pageSize < ISqlJetLimits.SQLJET_MIN_PAGE_SIZE
                        || (ISqlJetLimits.SQLJET_MAX_PAGE_SIZE < 32768)) {
                    throw new SqlJetException(rc);
                }
                assert ((pageSize & 7) == 0);
                usableSize = pageSize - SqlJetUtility.getUnsignedByte(page1, 20);
                if (pageSize != pBt.pageSize) {
                    /*
                     * After reading the first page of the database assuming a
                     * page size of BtShared.pageSize, we have discovered that
                     * the page-size is actually pageSize. Unlock the database,
                     * leave pBt->pPage1 at zero and return SQLITE_OK. The
                     * caller will call this function again with the correct
                     * page-size.
                     */
                    SqlJetMemPage.releasePage(pPage1);
                    pBt.usableSize = usableSize;
                    pBt.pageSize = pageSize;
                    freeTempSpace(pBt);
                    pBt.pageSize = pBt.pPager.setPageSize(pBt.pageSize);
                    return;
                }
                if (usableSize < 500) {
                    throw new SqlJetException(rc);
                }
                pBt.pageSize = pageSize;
                pBt.usableSize = usableSize;
                pBt.autoVacuum = (SqlJetUtility.get4byte(page1, 36 + 4 * 4) > 0);
                pBt.incrVacuum = (SqlJetUtility.get4byte(page1, 36 + 7 * 4) > 0);
View Full Code Here


     * org.tmatesoft.sqljet.core.ISqlJetBtree#beginTrans(org.tmatesoft.sqljet
     * .core.SqlJetTransactionMode)
     */
    public void beginTrans(SqlJetTransactionMode mode) throws SqlJetException {

        SqlJetException rc = null;

        enter();

        try {

            pBt.db = db;
            integrity();

            /*
             * If the btree is already in a write-transaction, or it is already
             * in a read-transaction and a read-transaction is requested, this
             * is a no-op.
             */
            if (inTrans == TransMode.WRITE || (inTrans == TransMode.READ && mode == SqlJetTransactionMode.READ_ONLY)) {
                return;
            }

            /* Write transactions are not possible on a read-only database */
            if (pBt.readOnly && mode != SqlJetTransactionMode.READ_ONLY) {
                throw new SqlJetException(SqlJetErrorCode.READONLY);
            }

            /*
             * If another database handle has already opened a write transaction
             * on this shared-btree structure and a second write transaction is
             * requested, return SQLITE_BUSY.
             */
            if (pBt.inTransaction == TransMode.WRITE && mode != SqlJetTransactionMode.READ_ONLY) {
                throw new SqlJetException(SqlJetErrorCode.BUSY);
            }

            if (mode == SqlJetTransactionMode.EXCLUSIVE) {
                Iterator<SqlJetBtreeLock> pIter;
                for (pIter = pBt.pLock.iterator(); pIter.hasNext();) {
                    if (pIter.next().pBtree != this) {
                        throw new SqlJetException(SqlJetErrorCode.BUSY);
                    }
                }
            }

            int nBusy = 0;
            do {
                try {

                    if (pBt.pPage1 == null) {
                        do {
                            lockBtree();
                        } while (pBt.pPage1 == null);
                    }

                    if (mode != SqlJetTransactionMode.READ_ONLY) {
                        if (pBt.readOnly) {
                            throw new SqlJetException(SqlJetErrorCode.READONLY);
                        } else {
                            pBt.pPager.begin(mode == SqlJetTransactionMode.EXCLUSIVE);
                            newDatabase();
                        }
                    }

                    if (mode != SqlJetTransactionMode.READ_ONLY)
                        pBt.inStmt = false;

                } catch (SqlJetException e) {
                    rc = e;
                    pBt.unlockBtreeIfUnused();
                }

            } while (rc != null && rc.getErrorCode() == SqlJetErrorCode.BUSY && pBt.inTransaction == TransMode.NONE
                    && invokeBusyHandler(nBusy) && (nBusy++) > -1);

            if (rc == null) {
                if (inTrans == TransMode.NONE) {
                    pBt.nTransaction++;
View Full Code Here

            pBt.db = this.db;
            assert (this.inTrans == TransMode.WRITE);
            assert (!pBt.inStmt);
            assert (!pBt.readOnly);
            if (this.inTrans != TransMode.WRITE || pBt.inStmt || pBt.readOnly) {
                throw new SqlJetException(SqlJetErrorCode.INTERNAL);
            } else {
                assert (pBt.inTransaction == TransMode.WRITE);
                /*
                 * At the pager level, a statement transaction is a savepoint
                 * with an index greater than all savepoints created explicitly
View Full Code Here

                /* Move the page currently at pgnoRoot to pgnoMove. */
                pRoot = pBt.getPage(pgnoRoot, false);
                try {
                    pBt.ptrmapGet(pgnoRoot, eType, iPtrPage);
                    if (eType[0] == SqlJetBtreeShared.PTRMAP_ROOTPAGE || eType[0] == SqlJetBtreeShared.PTRMAP_FREEPAGE) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                } catch (SqlJetException e) {
                    SqlJetMemPage.releasePage(pRoot);
                    throw e;
                }
View Full Code Here

        nFromPageSize = pBtFrom.pageSize;

        assert (pTo.inTrans == TransMode.WRITE);
        assert (pFrom.inTrans == TransMode.WRITE);
        if (pBtTo.pCursor != null) {
            throw new SqlJetException(SqlJetErrorCode.BUSY);
        }

        nToPage = pBtTo.pPager.getPageCount();
        nFromPage = pBtFrom.pPager.getPageCount();
        iSkip = pBtTo.PENDING_BYTE_PAGE();
View Full Code Here

        enter();
        try {
            pBt.db = this.db;
            assert (pBt.inTransaction == TransMode.WRITE && this.inTrans == TransMode.WRITE);
            if (!pBt.autoVacuum) {
                throw new SqlJetException(SqlJetErrorCode.DONE);
            } else {
                pBt.invalidateAllOverflowCache();
                pBt.incrVacuumStep(0, pBt.pPager.imageSize());
            }
        } finally {
View Full Code Here

         * database. This is because in auto-vacuum mode the backend may* need
         * to move another root-page to fill a gap left by the deleted* root
         * page. If an open cursor was using this page a problem would* occur.
         */
        if (pBt.pCursor != null) {
            throw new SqlJetException(SqlJetErrorCode.LOCKED);
        }

        pPage = pBt.getPage(iTable, false);
        try {
            clearTable(iTable, null);
View Full Code Here

                mem.setTypeFlag(SqlJetVdbeMemFlags.Blob);
            } else if ("byte[]".equalsIgnoreCase(value.getClass().getCanonicalName())) {
                mem.setStr(SqlJetUtility.wrapPtr((byte[]) value), encoding);
                mem.setTypeFlag(SqlJetVdbeMemFlags.Blob);
            } else {
                throw new SqlJetException(SqlJetErrorCode.MISUSE, "Bad value #" + i + " " + value.toString());
            }
            fields.add(mem);
        }
        return new SqlJetBtreeRecord(fields);
    }
View Full Code Here

             * before the end* of the record (when all fields present), then we
             * must be dealing* with a corrupt database.
             */
            if (zIdx.getPointer() > zEndHdr.getPointer() || offset[0] > payloadSize
                    || (zIdx.getPointer() == zEndHdr.getPointer() && offset[0] != payloadSize)) {
                throw new SqlJetException(SqlJetErrorCode.CORRUPT);
            }

        } finally {
            cursor.leaveCursor();
        }
View Full Code Here

         */
        assert (!PTRMAP_ISPAGE(PENDING_BYTE_PAGE()));

        assert (autoVacuum);
        if (key == 0) {
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }
        iPtrmap = PTRMAP_PAGENO(key);
        pDbPage = pPager.getPage(iPtrmap);
        offset = PTRMAP_PTROFFSET(iPtrmap, key);
        pPtrmap = pDbPage.getData();
View Full Code Here

TOP

Related Classes of org.tmatesoft.sqljet.core.SqlJetException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.