Package org.tmatesoft.sqljet.core

Examples of org.tmatesoft.sqljet.core.SqlJetException


            pPgno[0] = SqlJetUtility.get4byte(pPtrmap, offset + 1);

        pDbPage.unref();

        if (pEType[0] < 1 || pEType[0] > 5)
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
    }
View Full Code Here


                        ppPage = pTrunk;
                        pTrunk = null;
                        TRACE("ALLOCATE: %d trunk - %d free pages left\n", pPgno[0], n - 1);
                    } else if (k > usableSize / 4 - 2) {
                        /* Value of k is out of range. Database corruption */
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    } else if (searchList && nearby == iTrunk) {
                        /*
                         * The list is being searched and this trunk page is the
                         * page to allocate, regardless of whether it has
                         * leaves.
                         */
                        assert (pPgno[0] == iTrunk);
                        ppPage = pTrunk;
                        searchList = false;
                        pTrunk.pDbPage.write();
                        if (k == 0) {
                            if (pPrevTrunk == null) {
                                SqlJetUtility.memcpy(pPage1.aData, 32, pTrunk.aData, 0, 4);
                            } else {
                                SqlJetUtility.memcpy(pPrevTrunk.aData, 0, pTrunk.aData, 0, 4);
                            }
                        } else {
                            /*
                             * The trunk page is required by the caller but it
                             * contains pointers to free-list leaves. The first
                             * leaf becomes a trunk page in this case.
                             */
                            SqlJetMemPage pNewTrunk;
                            int iNewTrunk = SqlJetUtility.get4byte(pTrunk.aData, 8);
                            pNewTrunk = getPage(iNewTrunk, false);
                            try {
                                pNewTrunk.pDbPage.write();
                            } catch (SqlJetException e) {
                                SqlJetMemPage.releasePage(pNewTrunk);
                                throw e;
                            }
                            SqlJetUtility.memcpy(pNewTrunk.aData, 0, pTrunk.aData, 0, 4);
                            SqlJetUtility.put4byte(pNewTrunk.aData, 4, k - 1);
                            SqlJetUtility.memcpy(pNewTrunk.aData, 8, pTrunk.aData, 12, (k - 1) * 4);
                            SqlJetMemPage.releasePage(pNewTrunk);
                            if (pPrevTrunk == null) {
                                SqlJetUtility.put4byte(pPage1.aData, 32, iNewTrunk);
                            } else {
                                pPrevTrunk.pDbPage.write();
                                SqlJetUtility.put4byte(pPrevTrunk.aData, 0, iNewTrunk);
                            }
                        }
                        pTrunk = null;
                        TRACE("ALLOCATE: %d trunk - %d free pages left\n", pPgno[0], n - 1);
                    } else {
                        /* Extract a leaf from the trunk */
                        int closest;
                        int iPage;
                        ISqlJetMemoryPointer aData = pTrunk.aData;
                        pTrunk.pDbPage.write();
                        if (nearby > 0) {
                            int i, dist;
                            closest = 0;
                            dist = SqlJetUtility.get4byte(aData, 8) - nearby;
                            if (dist < 0)
                                dist = -dist;
                            for (i = 1; i < k; i++) {
                                int d2 = SqlJetUtility.get4byte(aData, 8 + i * 4) - nearby;
                                if (d2 < 0)
                                    d2 = -d2;
                                if (d2 < dist) {
                                    closest = i;
                                    dist = d2;
                                }
                            }
                        } else {
                            closest = 0;
                        }

                        iPage = SqlJetUtility.get4byte(aData, 8 + closest * 4);
                        if (!searchList || iPage == nearby) {
                            int nPage;
                            pPgno[0] = iPage;
                            nPage = getPageCount();
                            if (pPgno[0] > nPage) {
                                /* Free page off the end of the file */
                                throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                            }
                            TRACE("ALLOCATE: %d was leaf %d of %d on trunk %d" + ": %d more free pages\n", pPgno[0],
                                    closest + 1, k, pTrunk.pgno, n - 1);
                            if (closest < k - 1) {
                                SqlJetUtility.memcpy(aData, 8 + closest * 4, aData, 4 + k * 4, 4);
                            }
                            SqlJetUtility.put4byte(aData, 4, k - 1);
                            ppPage = getPage(pPgno[0], true);
                            ppPage.pDbPage.dontRollback();
                            try {
                                ppPage.pDbPage.write();
                            } catch (SqlJetException e) {
                                SqlJetMemPage.releasePage(ppPage);
                            }
                            searchList = false;
                        }
                    }
                    SqlJetMemPage.releasePage(pPrevTrunk);
                    pPrevTrunk = null;
                } while (searchList);

            } else {
                /*
                 * There are no pages on the freelist, so create a new page at
                 * the end of the file
                 */
                int nPage = getPageCount();
                pPgno[0] = nPage + 1;

                if (autoVacuum && PTRMAP_ISPAGE(pPgno[0])) {
                    /*
                     * IfpPgno refers to a pointer-map page, allocate two new
                     * pages at the end of the file instead of one. The first
                     * allocated page becomes a new pointer-map page, the second
                     * is used by the caller.
                     */
                    TRACE("ALLOCATE: %d from end of file (pointer-map page)\n", pPgno[0]);
                    assert (pPgno[0] != PENDING_BYTE_PAGE());
                    pPgno[0]++;
                    if (pPgno[0] == PENDING_BYTE_PAGE()) {
                        pPgno[0]++;
                    }
                }

                assert (pPgno[0] != PENDING_BYTE_PAGE());
                ppPage = getPage(pPgno[0], false);
                try {
                    ppPage.pDbPage.write();
                } catch (SqlJetException e) {
                    SqlJetMemPage.releasePage(ppPage);
                }
                TRACE("ALLOCATE: %d from end of file\n", pPgno[0]);
            }

            assert (pPgno[0] != PENDING_BYTE_PAGE());

        } finally {
            // end_allocate_page:
            SqlJetMemPage.releasePage(pTrunk);
            SqlJetMemPage.releasePage(pPrevTrunk);
        }

        if (ppPage.pDbPage.getRefCount() > 1) {
            SqlJetMemPage.releasePage(ppPage);
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }
        ppPage.isInit = false;
        return ppPage;

    }
View Full Code Here

            short[] eType = { 0 };
            int[] iPtrPage = { 0 };

            nFreeList = SqlJetUtility.get4byte(pPage1.aData, 36);
            if (nFreeList == 0 || nFin == iLastPg) {
                throw new SqlJetException(SqlJetErrorCode.DONE);
            }

            ptrmapGet(iLastPg, eType, iPtrPage);
            if (eType[0] == PTRMAP_ROOTPAGE) {
                throw new SqlJetException(SqlJetErrorCode.CORRUPT);
            }

            if (eType[0] == PTRMAP_FREEPAGE) {
                if (nFin == 0) {
                    /*
 
View Full Code Here

            int iFree;
            final int pgsz = pageSize;
            int nOrig = getPageCount();

            if (PTRMAP_ISPAGE(nOrig)) {
                throw new SqlJetException(SqlJetErrorCode.CORRUPT);
            }
            if (nOrig == PENDING_BYTE_PAGE()) {
                nOrig--;
            }
            nFree = SqlJetUtility.get4byte(pPage1.aData, 36);
View Full Code Here

        ISqlJetMemoryPointer pCell;
        int i;

        assert (mutex.held());
        if (pgno > pPager.getPageCount()) {
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }

        try {

            pPage = getAndInitPage(pgno);
View Full Code Here

        ISqlJetPage pDbPage = null;
        SqlJetMemPage pPage = null;

        assert (mutex.held());
        if (pgno == 0) {
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }

        /*
         * It is often the case that the page we want is already in cache.* If
         * so, get it directly. This saves us from having to call*
         * pagerPagecount() to make sure pgno is within limits, which results*
         * in a measureable performance improvements.
         */
        try {
            pDbPage = pPager.lookupPage(pgno);
            if (pDbPage != null) {
                /* Page is already in cache */
                pPage = pageFromDbPage(pDbPage, pgno);
            } else {
                /* Page not in cache. Acquire it. */
                if (pgno > pPager.getPageCount()) {
                    throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                }
                pPage = getPage(pgno, false);
            }
            if (!pPage.isInit) {
                pPage.initPage();
View Full Code Here

        } else if (ISqlJetUnaryExpression.Operation.decode(ast.getText()) != null && ast.getChildCount() == 1) {
            return new SqlJetUnaryExpression(ast);
        } else if ("collate".equals(op)) {
            return new SqlJetCollateExpression(ast);
        }
        throw new SqlJetException(SqlJetErrorCode.ERROR, "Invalid expression");
    }
View Full Code Here

        /*
         * Check for errors
         */
        if (pPager.errCode != null) {
            throw new SqlJetException(pPager.errCode);
        }
        if (pPager.readOnly) {
            throw new SqlJetException(SqlJetErrorCode.PERM);
        }

        assert (!pPager.setMaster);

        /*
 
View Full Code Here

                primaryKeyColumns.addAll(pk.getColumns());
                if (pk.getColumns().size() == 1) {
                    final String n = pk.getColumns().get(0);
                    final ISqlJetColumnDef c = getColumn(n);
                    if (null == c) {
                        throw new SqlJetException(SqlJetErrorCode.ERROR, "Wrong column '" + n + "' in PRIMARY KEY");
                    } else if (c.hasExactlyIntegerType()) {
                        rowIdPrimaryKeyColumnName = n;
                        rowIdPrimaryKeyColumnIndex = getColumnNumber(n);
                        rowIdPrimaryKey = true;
                        b = true;
View Full Code Here

        return new SqlJetConnection(fileName);
    }

    public SqlJetPreparedStatement prepare(String sql) throws SqlJetException {
        if (sql == null || sql.trim().length() == 0) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "SQL statement is empty");
        }
        return new SqlJetPreparedStatement(db, sql);
    }
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.