Пример #1
0
        public void CreateBasicTableColumnIndex4OnWindows7ThrowsException()
        {
            if (!EsentVersion.SupportsWindows7Features)
            {
                return;
            }

            var tablecreate = new JET_TABLECREATE {
                szTableName = "table"
            };

            string directory = SetupHelper.CreateRandomDirectory();
            string database  = Path.Combine(directory, "test.db");

            using (var instance = new Instance("Windows7CreateBasicTableColumnIndex4"))
            {
                instance.Parameters.Recovery           = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.MaxTemporaryTables = 0;
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, database, string.Empty, out dbid, CreateDatabaseGrbit.None);
                    using (var transaction = new Transaction(session))
                    {
                        try
                        {
                            Windows8Api.JetCreateTableColumnIndex4(session, dbid, tablecreate);
                            Assert.Fail("JetCreateTableColumnIndex4() is supposed to throw an exception on Win7.");
                        }
                        catch (InvalidOperationException)
                        {
                        }
                    }
                }
            }
        }
Пример #2
0
        public void CreateTableColumnIndex4OnWindows7ThrowsException()
        {
            if (!EsentVersion.SupportsWindows7Features)
            {
                return;
            }

            var columncreates = new JET_COLUMNCREATE[]
            {
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col1_short",
                    coltyp       = JET_coltyp.Short,
                    cbMax        = 2,
                },
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col2_longtext",
                    coltyp       = JET_coltyp.LongText,
                    cp           = JET_CP.Unicode,
                },
            };

            const string Index1Name        = "firstIndex";
            const string Index1Description = "+col1_short\0-col2_longtext\0";

            const string Index2Name        = "secondIndex";
            const string Index2Description = "+col2_longtext\0-col1_short\0";

            var indexcreates = new JET_INDEXCREATE[]
            {
                new JET_INDEXCREATE
                {
                    szIndexName = Index1Name,
                    szKey       = Index1Description,
                    cbKey       = Index1Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 99,
                },
                new JET_INDEXCREATE
                {
                    szIndexName = Index2Name,
                    szKey       = Index2Description,
                    cbKey       = Index2Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 79,
                },
            };

            var tablecreate = new JET_TABLECREATE()
            {
                szTableName    = "tableBigBang",
                ulPages        = 23,
                ulDensity      = 75,
                cColumns       = columncreates.Length,
                rgcolumncreate = columncreates,
                rgindexcreate  = indexcreates,
                cIndexes       = indexcreates.Length,
                cbSeparateLV   = 100,
                cbtyp          = JET_cbtyp.Null,
                grbit          = CreateTableColumnIndexGrbit.None,
            };

            string directory = SetupHelper.CreateRandomDirectory();
            string database  = Path.Combine(directory, "test.db");

            using (var instance = new Instance("Windows7CreateTableColumnIndex4"))
            {
                instance.Parameters.Recovery           = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.MaxTemporaryTables = 0;
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, database, string.Empty, out dbid, CreateDatabaseGrbit.None);
                    using (var transaction = new Transaction(session))
                    {
                        try
                        {
                            Windows8Api.JetCreateTableColumnIndex4(session, dbid, tablecreate);
                            Assert.Fail("JetCreateTableColumnIndex4() is supposed to throw an exception on Win7.");
                        }
                        catch (InvalidOperationException)
                        {
                        }
                    }
                }
            }
        }
        public void JetCreateTableColumnIndex4SpaceHints()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            var columncreates = new[]
            {
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col1_short",
                    coltyp       = JET_coltyp.Short,
                    cbMax        = 2,
                    pvDefault    = BitConverter.GetBytes((short)37),
                    cbDefault    = 2,
                },
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col2_longtext",
                    coltyp       = JET_coltyp.LongText,
                    cp           = JET_CP.Unicode,
                },
            };

            const string Index1Name        = "firstIndex";
            const string Index1Description = "+col1_short\0-col2_longtext\0";

            const string Index2Name        = "secondIndex";
            const string Index2Description = "+col2_longtext\0-col1_short\0";

            var spacehintsIndex = new JET_SPACEHINTS()
            {
                ulInitialDensity = 33,
                cbInitial        = 4096,
                grbit            = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward,
                ulMaintDensity   = 44,
                ulGrowth         = 144,
                cbMinExtent      = 1024 * 1024,
                cbMaxExtent      = 3 * 1024 * 1024,
            };

            var spacehintsSeq = new JET_SPACEHINTS()
            {
                ulInitialDensity = 33,
                cbInitial        = 4096,
                grbit            = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward,
                ulMaintDensity   = 44,
                ulGrowth         = 144,
                cbMinExtent      = 1024 * 1024,
                cbMaxExtent      = 3 * 1024 * 1024,
            };

            var spacehintsLv = new JET_SPACEHINTS()
            {
                ulInitialDensity = 33,
                cbInitial        = 4096,
                grbit            = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward,
                ulMaintDensity   = 44,
                ulGrowth         = 144,
                cbMinExtent      = 1024 * 1024,
                cbMaxExtent      = 3 * 1024 * 1024,
            };

            var indexcreates = new JET_INDEXCREATE[]
            {
                new JET_INDEXCREATE
                {
                    szIndexName = Index1Name,
                    szKey       = Index1Description,
                    cbKey       = Index1Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 99,
                    pSpaceHints = spacehintsIndex,
                },
                new JET_INDEXCREATE
                {
                    szIndexName = Index2Name,
                    szKey       = Index2Description,
                    cbKey       = Index2Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 79,
                },
            };

            var tablecreate = new JET_TABLECREATE()
            {
                szTableName    = "tableBigBang",
                ulPages        = 23,
                ulDensity      = 75,
                cColumns       = columncreates.Length,
                rgcolumncreate = columncreates,
                rgindexcreate  = indexcreates,
                cIndexes       = indexcreates.Length,
                cbSeparateLV   = 100,
                cbtyp          = JET_cbtyp.Null,
                grbit          = CreateTableColumnIndexGrbit.None,
                pSeqSpacehints = spacehintsSeq,
                pLVSpacehints  = spacehintsLv,
            };

            Api.JetBeginTransaction(this.sesid);
            Windows8Api.JetCreateTableColumnIndex4(this.sesid, this.dbid, tablecreate);

            var tableCreated = new JET_TABLEID()
            {
                Value = tablecreate.tableid.Value
            };

            Assert.AreNotEqual <JET_TABLEID>(JET_TABLEID.Nil, tableCreated);

            // 1 table, 2 columns, 2 indices = 5 objects.
            Assert.AreEqual <int>(tablecreate.cCreated, 5);

            Api.JetCloseTable(this.sesid, tableCreated);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
        }
        public void JetCreateTableColumnIndex4WithInvalidIndexName()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            var columncreates = new JET_COLUMNCREATE[]
            {
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col1_short",
                    coltyp       = JET_coltyp.Short,
                    cbMax        = 2,
                },
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col2_longtext",
                    coltyp       = JET_coltyp.LongText,
                    cp           = JET_CP.Unicode,
                },
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col1_short2",
                    coltyp       = JET_coltyp.Short,
                    cbMax        = 2,
                },
            };

            const string Index1Name        = "firstIndex";
            const string Index1Description = "+col1_short\0-col2_longtext\0";

            const string Index2Name        = "secondIndex";
            const string Index2Description = "+col2_longtext\0-col1_short\0";

            const string Index3Name        = "[BAD!NAME]";
            const string Index3Description = "+col1_short2\0-col2_longtext\0";

            var indexcreates = new JET_INDEXCREATE[]
            {
                new JET_INDEXCREATE
                {
                    szIndexName = Index1Name,
                    szKey       = Index1Description,
                    cbKey       = Index1Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 99,
                },
                new JET_INDEXCREATE
                {
                    szIndexName = Index2Name,
                    szKey       = Index2Description,
                    cbKey       = Index2Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 99,
                },
                new JET_INDEXCREATE
                {
                    szIndexName = Index3Name,
                    szKey       = Index3Description,
                    cbKey       = Index3Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 99,
                },
            };

            var tablecreate = new JET_TABLECREATE()
            {
                szTableName    = "tableBigBang",
                ulPages        = 23,
                ulDensity      = 75,
                cColumns       = columncreates.Length,
                rgcolumncreate = columncreates,
                rgindexcreate  = indexcreates,
                cIndexes       = indexcreates.Length,
                cbSeparateLV   = 100,
                cbtyp          = JET_cbtyp.Null,
                grbit          = CreateTableColumnIndexGrbit.None,
            };

            Api.JetBeginTransaction(this.sesid);

            bool hitException = false;

            try
            {
                Windows8Api.JetCreateTableColumnIndex4(this.sesid, this.dbid, tablecreate);
            }
            catch (EsentInvalidNameException)
            {
                hitException = true;
            }

            Assert.IsTrue(hitException);
            Assert.AreEqual(JET_err.Success, tablecreate.rgindexcreate[0].err);
            Assert.AreEqual(JET_err.Success, tablecreate.rgindexcreate[1].err);
            Assert.AreEqual(JET_err.InvalidName, tablecreate.rgindexcreate[2].err);

            Api.JetRollback(this.sesid, RollbackTransactionGrbit.None);
        }
        public void JetCreateTemplateTableColumnIndex4()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            var columncreates = new JET_COLUMNCREATE[]
            {
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col1_short",
                    coltyp       = JET_coltyp.Short,
                    cbMax        = 2,
                },
                new JET_COLUMNCREATE()
                {
                    szColumnName = "col2_longtext",
                    coltyp       = JET_coltyp.LongText,
                    cp           = JET_CP.Unicode,
                },
            };

            const string Index1Name        = "firstIndex";
            const string Index1Description = "+col1_short\0-col2_longtext\0";

            const string Index2Name        = "secondIndex";
            const string Index2Description = "+col2_longtext\0-col1_short\0";

            var indexcreates = new JET_INDEXCREATE[]
            {
                new JET_INDEXCREATE
                {
                    szIndexName = Index1Name,
                    szKey       = Index1Description,
                    cbKey       = Index1Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 99,
                },
                new JET_INDEXCREATE
                {
                    szIndexName = Index2Name,
                    szKey       = Index2Description,
                    cbKey       = Index2Description.Length + 1,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 79,
                },
            };

            var tablecreateTemplate = new JET_TABLECREATE()
            {
                szTableName    = "tableOld",
                ulPages        = 23,
                ulDensity      = 75,
                cColumns       = columncreates.Length,
                rgcolumncreate = columncreates,
                rgindexcreate  = indexcreates,
                cIndexes       = indexcreates.Length,
                cbSeparateLV   = 100,
                cbtyp          = JET_cbtyp.Null,
                grbit          = CreateTableColumnIndexGrbit.TemplateTable,
            };

            Api.JetBeginTransaction(this.sesid);
            Windows8Api.JetCreateTableColumnIndex4(this.sesid, this.dbid, tablecreateTemplate);

            var tableCreated = new JET_TABLEID()
            {
                Value = tablecreateTemplate.tableid.Value
            };

            Assert.AreNotEqual <JET_TABLEID>(JET_TABLEID.Nil, tableCreated);

            // 1 table, 2 columns, 2 indices = 5 objects.
            Assert.AreEqual <int>(tablecreateTemplate.cCreated, 5);

            Assert.AreNotEqual(tablecreateTemplate.rgcolumncreate[0].columnid, JET_COLUMNID.Nil);
            Assert.AreNotEqual(tablecreateTemplate.rgcolumncreate[1].columnid, JET_COLUMNID.Nil);

            var tablecreateChild = new JET_TABLECREATE()
            {
                szTableName         = "tableNew",
                szTemplateTableName = "tableOld",
                ulPages             = 23,
                ulDensity           = 75,
                rgcolumncreate      = null,
                cColumns            = 0,
                rgindexcreate       = null,
                cIndexes            = 0,
                cbSeparateLV        = 100,
                cbtyp = JET_cbtyp.Null,
                grbit = CreateTableColumnIndexGrbit.None,
            };

            Windows8Api.JetCreateTableColumnIndex4(this.sesid, this.dbid, tablecreateChild);

            var tableidChild = new JET_TABLEID()
            {
                Value = tablecreateChild.tableid.Value
            };

            Assert.AreNotEqual <JET_TABLEID>(JET_TABLEID.Nil, tableidChild);

            // 1 table = 1 object
            Assert.AreEqual <int>(tablecreateChild.cCreated, 1);

            Api.JetCloseTable(this.sesid, tableCreated);
            Api.JetCloseTable(this.sesid, tableidChild);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
        }