Examples of ISqlJetMemoryPointer


Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

                     * * comparison function directly
                     */
                    return pColl.cmp(pColl.getUserData(), pMem1.n, pMem1.z, pMem2.n, pMem2.z);
                } else {

                    ISqlJetMemoryPointer v1, v2;
                    int n1, n2;

                    SqlJetVdbeMem c1 = (SqlJetVdbeMem) pMem1.shallowCopy(SqlJetVdbeMemFlags.Ephem);
                    SqlJetVdbeMem c2 = (SqlJetVdbeMem) pMem2.shallowCopy(SqlJetVdbeMemFlags.Ephem);
                    v1 = c1.valueText(pColl.getEnc());
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

        final SqlJetVdbeMem pMem = this;

        int len; /* Maximum length of output string in bytes */

        ISqlJetMemoryPointer zOut; /* Output buffer */
        int zIn; /* Input iterator */
        int zTerm; /* End of input */
        // int z; /* Output iterator */

        // long c;

        assert (pMem.db == null || mutex_held(pMem.db.getMutex()));
        assert (pMem.flags.contains(SqlJetVdbeMemFlags.Str));
        assert (pMem.enc != desiredEnc);
        assert (pMem.enc != null);
        assert (pMem.n >= 0);

        /*
         * If the translation is between UTF-16 little and big endian, then* all
         * that is required is to swap the byte order. This case is handled*
         * differently from the others.
         */
        if (pMem.enc != SqlJetEncoding.UTF8 && desiredEnc != SqlJetEncoding.UTF8) {
            short temp;
            pMem.makeWriteable();
            zIn = 0;
            zTerm = pMem.n & ~1;
            while (zIn < zTerm) {
                temp = (short) SqlJetUtility.getUnsignedByte(pMem.z, zIn);
                SqlJetUtility.putUnsignedByte(pMem.z, zIn, SqlJetUtility.getUnsignedByte(pMem.z, zIn + 1));
                zIn++;
                SqlJetUtility.putUnsignedByte(pMem.z, zIn++, temp);
            }
            pMem.enc = desiredEnc;
            return;
        }

        /* Set len to the maximum number of bytes required in the output buffer. */
        if (desiredEnc == SqlJetEncoding.UTF8) {
            /*
             * When converting from UTF-16, the maximum growth results from*
             * translating a 2-byte character to a 4-byte UTF-8 character.* A
             * single byte is required for the output string* nul-terminator.
             */
            pMem.n &= ~1;
            len = pMem.n * 2 + 1;
        } else {
            /*
             * When converting from UTF-8 to UTF-16 the maximum growth is caused
             * * when a 1-byte UTF-8 character is translated into a 2-byte
             * UTF-16* character. Two bytes are required in the output buffer
             * for the* nul-terminator.
             */
            len = pMem.n * 2 + 2;
        }

        /*
         * Set zIn to point at the start of the input buffer and zTerm to point
         * 1* byte past the end.** Variable zOut is set to point at the output
         * buffer, space obtained* from sqlite3_malloc().
         */
        zOut = SqlJetUtility.translate(pMem.z, pMem.enc, desiredEnc);
        pMem.n = zOut.remaining();

        assert ((pMem.n + (desiredEnc == SqlJetEncoding.UTF8 ? 1 : 2)) <= len);

        pMem.release();
        pMem.flags.removeAll(SqlJetUtility.of(SqlJetVdbeMemFlags.Static, SqlJetVdbeMemFlags.Dyn,
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

        assert (mutex_held(pCur.getCursorDb().getMutex()));

        SqlJetVdbeMem pMem = this;

        /* Data from the btree layer */
        ISqlJetMemoryPointer zData;
        /* Number of bytes available on the local btree page */
        int[] available = { 0 };

        if (key) {
            zData = pCur.keyFetch(available);
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

            final Set<SqlJetFileOpenPermission> permissions) throws SqlJetException {

        ISqlJetFileSystem pVfs; /* The VFS to use for this btree */
        SqlJetBtreeShared pBt = null; /* Shared part of btree structure */
        int nReserve;
        ISqlJetMemoryPointer zDbHeader = SqlJetUtility.allocatePtr(100);

        /*
         * Set the variable isMemdb to true for an in-memory database, or false
         * for a file-based database. This symbol is only required if either of
         * the shared-data or autovacuum features are compiled into the library.
         */
        final boolean isMemdb = filename != null && ISqlJetPager.MEMORY_DB.equals(filename.getPath());

        assert (db != null);

        pVfs = db.getFileSystem();
        this.inTrans = TransMode.NONE;
        this.db = db;

        /*
         * If this Btree is a candidate for shared cache, try to find an
         * existing BtShared object that we can share with
         */
        if (!isMemdb && !db.getFlags().contains(SqlJetDbFlags.Vtab) && filename != null
                && !"".equals(filename.getPath())) {
            if (db.getConfig().isSharedCacheEnabled()) {
                this.sharable = true;
                db.getFlags().add(SqlJetDbFlags.SharedCache);
                final String fullPathname = pVfs.getFullPath(filename);
                synchronized (sharedCacheList) {
                    final Iterator<SqlJetBtreeShared> i = sharedCacheList.iterator();
                    while (i.hasNext()) {
                        pBt = i.next();
                        assert (pBt.nRef > 0);
                        final String pagerFilename = pVfs.getFullPath(pBt.pPager.getFileName());
                        if (fullPathname.equals(pagerFilename) && pVfs == pBt.pPager.getFileSystem()) {
                            this.pBt = pBt;
                            pBt.nRef++;
                            break;
                        }
                    }
                }
            }
        }

        try {
            if (this.pBt == null) {
                /*
                 * The following asserts make sure that structures used by the
                 * btree are the right size. This is to guard against size
                 * changes that result when compiling on a different
                 * architecture.
                 */
                // assert( sizeof(i64)==8 || sizeof(i64)==4 );
                // assert( sizeof(u64)==8 || sizeof(u64)==4 );
                // assert( sizeof(u32)==4 );
                // assert( sizeof(u16)==2 );
                // assert( sizeof(Pgno)==4 );
                pBt = new SqlJetBtreeShared();
                pBt.pPager = new SqlJetPager();
                pBt.pPager.open(pVfs, filename, SqlJetBtreeFlags.toPagerFlags(flags), type, permissions);
                pBt.pPager.readFileHeader(zDbHeader.remaining(), zDbHeader);
                pBt.pPager.setBusyhandler(new ISqlJetBusyHandler() {
                    public boolean call(int number) {
                        return invokeBusyHandler(number);
                    }
                });
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

            nPage = pBt.pPager.getPageCount();
            if (nPage > 0) {

                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) {
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

            return;
        }

        SqlJetMemPage pP1 = pBt.pPage1;
        assert (pP1 != null);
        ISqlJetMemoryPointer data = pP1.aData;
        pP1.pDbPage.write();
        SqlJetUtility.memcpy(data, zMagicHeader, zMagicHeader.remaining());
        assert (zMagicHeader.remaining() == 16);
        SqlJetUtility.put2byte(data, 16, pBt.pageSize);
        SqlJetUtility.putUnsignedByte(data, 18, (byte) 1);
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

                        continue;
                    }

                    pFromPage = pBtFrom.pPager.getPage(iFrom);

                    ISqlJetMemoryPointer zTo = pToPage.getData();
                    ISqlJetMemoryPointer zFrom = pFromPage.getData();
                    int nCopy;

                    int nFrom = 0;
                    int nTo = 0;

                    if (nFromPageSize >= nToPageSize) {
                        nFrom += ((i - 1) * nToPageSize - ((iFrom - 1) * nFromPageSize));
                        nCopy = nToPageSize;
                    } else {
                        nTo += (((iFrom - 1) * nFromPageSize) - (i - 1) * nToPageSize);
                        nCopy = nFromPageSize;
                    }
                    SqlJetUtility.memcpy(zTo, nTo, zFrom, nFrom, nCopy);

                    pFromPage.unref();
                }

                if (pToPage != null) {
                    SqlJetMemPage p = (SqlJetMemPage) pToPage.getExtra();
                    p.isInit = false;
                    pToPage.unref();
                }
            }
        }

        /*
         * If things have worked so far, the database file may need to be*
         * truncated. The complex part is that it may need to be truncated to* a
         * size that is not an integer multiple of nToPageSize - the current*
         * page size used by the pager associated with B-Tree pTo.** For
         * example, say the page-size of pTo is 2048 bytes and the original*
         * number of pages is 5 (10 KB file). If pFrom has a page size of 1024*
         * bytes and 9 pages, then the file needs to be truncated to 9KB.
         */

        ISqlJetFile pFile = pBtTo.pPager.getFile();
        long iSize = (long) nFromPageSize * (long) nFromPage;
        long iNow = (long) ((nToPage > nNewPage) ? nToPage : nNewPage) * (long) nToPageSize;
        long iPending = ((long) pBtTo.PENDING_BYTE_PAGE() - 1) * (long) nToPageSize;

        assert (iSize <= iNow);

        /*
         * Commit phase one syncs the journal file associated with pTo*
         * containing the original data. It does not sync the database file*
         * itself. After doing this it is safe to use OsTruncate() and other*
         * file APIs on the database file directly.
         */
        pBtTo.db = pTo.db;
        pBtTo.pPager.commitPhaseOne(null, true);
        if (iSize < iNow) {
            pFile.truncate(iSize);
        }

        /*
         * The loop that copied data from database pFrom to pTo did not*
         * populate the locking page of database pTo. If the page-size of* pFrom
         * is smaller than that of pTo, this means some data will* not have been
         * copied.** This block copies the missing data from database pFrom to
         * pTo* using file APIs. This is safe because at this point we know that
         * * all of the original data from pTo has been synced into the* journal
         * file. At this point it would be safe to do anything at* all to the
         * database file except truncate it to zero bytes.
         */
        if (nFromPageSize < nToPageSize && iSize > iPending) {
            long iOff;
            for (iOff = iPending; iOff < (iPending + nToPageSize); iOff += nFromPageSize) {
                ISqlJetPage pFromPage = null;
                int iFrom = (int) (iOff / nFromPageSize) + 1;

                if (iFrom == pBtFrom.PENDING_BYTE_PAGE() || iFrom > nFromPage) {
                    continue;
                }

                pFromPage = pBtFrom.pPager.getPage(iFrom);
                ISqlJetMemoryPointer zFrom = pFromPage.getData();
                pFile.write(zFrom, nFromPageSize, iOff);
                pFromPage.unref();
            }
        }

View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

        enter();

        try {

            ISqlJetPage pDbPage = null;
            ISqlJetMemoryPointer pP1;

            pBt.db = this.db;

            /*
             * Reading a meta-data value requires a read-lock on page 1 (and
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

        enter();
        try {
            pBt.db = this.db;
            assert (this.inTrans == TransMode.WRITE);
            assert (pBt.pPage1 != null);
            ISqlJetMemoryPointer pP1 = pBt.pPage1.aData;
            pBt.pPage1.pDbPage.write();
            SqlJetUtility.put4byte(pP1, 36 + idx * 4, value);
            if (idx == 7) {
                assert (pBt.autoVacuum || value == 0);
                assert (value == 0 || value == 1);
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetMemoryPointer

            if (payloadSize == 0) {
                return;
            }

            int i; /* Loop counter */
            ISqlJetMemoryPointer zData; /* Part of the record being decoded */
            /* For storing the record being decoded */
            SqlJetVdbeMem sMem = new SqlJetVdbeMem();

            ISqlJetMemoryPointer zIdx; /* Index into header */
            ISqlJetMemoryPointer zEndHdr; /*
                                           * Pointer to first byte after the
                                           * header
                                           */
            int[] offset = { 0 }; /* Offset into the data */
            int szHdrSz; /* Size of the header size field at start of record */
            int[] avail = { 0 }; /* Number of bytes of available data */

            assert (aType != null);
            assert (aOffset != null);

            /* Figure out how many bytes are in the header */
            if (isIndex) {
                zData = cursor.keyFetch(avail);
            } else {
                zData = cursor.dataFetch(avail);
            }
            /*
             * The following assert is true in all cases accept when* the
             * database file has been corrupted externally.* assert( zRec!=0 ||
             * avail>=payloadSize || avail>=9 );
             */
            szHdrSz = SqlJetUtility.getVarint32(zData, offset);

            /*
             * The KeyFetch() or DataFetch() above are fast and will get the
             * entire* record header in most cases. But they will fail to get
             * the complete* record header if the record header does not fit on
             * a single page* in the B-Tree. When that happens, use
             * sqlite3VdbeMemFromBtree() to* acquire the complete header text.
             */
            if (avail[0] < offset[0]) {
                sMem.fromBtree(cursor, 0, offset[0], isIndex);
                zData = sMem.z;
            }
            zEndHdr = SqlJetUtility.pointer(zData, offset[0]);
            zIdx = SqlJetUtility.pointer(zData, szHdrSz);

            /*
             * Scan the header and use it to fill in the aType[] and aOffset[]*
             * arrays. aType[i] will contain the type integer for the i-th*
             * column and aOffset[i] will contain the offset from the beginning*
             * of the record to the start of the data for the i-th column
             */
            fieldsCount = 0;
            for (i = 0; i < ISqlJetLimits.SQLJET_MAX_COLUMN && zIdx.getPointer() < zEndHdr.getPointer()
                    && offset[0] <= payloadSize; i++, fieldsCount++) {
                aOffset.add(i, offset[0]);
                int[] a = { 0 };
                SqlJetUtility.movePtr(zIdx, SqlJetUtility.getVarint32(zIdx, a));
                aType.add(i, a[0]);
                offset[0] += SqlJetVdbeSerialType.serialTypeLen(a[0]);

                fields.add(i, getField(i));

            }
            sMem.release();
            sMem.flags = SqlJetUtility.of(SqlJetVdbeMemFlags.Null);

            /*
             * If we have read more header data than was contained in the
             * header,* or if the end of the last field appears to be past the
             * end of the* record, or if the end of the last field appears to be
             * 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
TOP
Copyright © 2018 www.massapi.com. 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.