public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var idColumnCreate = CreateAutoIncrementIdColumn(IdColumnName);
                var identifierColumnCreate = CreateTextColumn(IdentifierColumnName);

                var columns = new JET_COLUMNCREATE[] { idColumnCreate, identifierColumnCreate };

                var primaryIndexKey = CreateIndexKey(IdColumnName);
                var identifierIndexKey = CreateIndexKey(IdentifierColumnName);

                var indexes = new JET_INDEXCREATE[]
                {
                    CreatePrimaryIndex(primaryIndexKey),
                    CreateUniqueTextIndex(IdentifierIndexName, identifierIndexKey)
                };

                var tableCreate = CreateTable(TableName, columns, indexes);

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _idColumnId = idColumnCreate.columnid;
                _identifierColumnId = identifierColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
 protected void GetColumnIds(
     JET_COLUMNCREATE[] columns, out JET_COLUMNID projectColumnId, out JET_COLUMNID projectNameColumnId, out JET_COLUMNID documentColumnId)
 {
     projectColumnId = columns[0].columnid;
     projectNameColumnId = columns[1].columnid;
     documentColumnId = columns[2].columnid;
 }
 public void VerifyValidityCatchesNullColumnName()
 {
     var x = new JET_COLUMNCREATE
     {
         szColumnName = null,
     };
     x.CheckMembersAreValid();
 }
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var projectColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = ProjectColumnName,
                    coltyp = JET_coltyp.Long,
                    grbit = ColumndefGrbit.ColumnNotNULL
                };

                var nameColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = NameColumnName,
                    coltyp = JET_coltyp.Long,
                    grbit = ColumndefGrbit.ColumnNotNULL
                };

                var valueColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = ValueColumnName,
                    coltyp = JET_coltyp.LongBinary,
                    grbit = ColumndefGrbit.None
                };

                var columns = new JET_COLUMNCREATE[] { projectColumnCreate, nameColumnCreate, valueColumnCreate };

                var projectAndNameIndexKey = "+" + ProjectColumnName + "\0+" + NameColumnName + "\0\0";

                var indexes = new JET_INDEXCREATE[]
                {
                    new JET_INDEXCREATE
                    {
                        szIndexName = ProjectAndNameIndexName,
                        szKey = projectAndNameIndexKey,
                        cbKey = projectAndNameIndexKey.Length,
                        grbit = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull,
                        ulDensity = 80
                    }
                };

                var tableCreate = new JET_TABLECREATE()
                {
                    szTableName = TableName,
                    ulPages = 16,
                    ulDensity = 80,
                    rgcolumncreate = columns,
                    cColumns = columns.Length,
                    rgindexcreate = indexes,
                    cIndexes = indexes.Length
                };

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _projectColumnId = projectColumnCreate.columnid;
                _nameColumnId = nameColumnCreate.columnid;
                _valueColumnId = valueColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
 public void VerifyValidityCatchesNegativeCbDefault()
 {
     var x = new JET_COLUMNCREATE
     {
         szColumnName = "column9",
         pvDefault = new byte[0],
         cbDefault = -53,
     };
     x.CheckMembersAreValid();
 }
 public void VerifyValidityCatchesInvalidCbDefault()
 {
     var x = new JET_COLUMNCREATE
     {
         szColumnName = "column9",
         pvDefault = null,
         cbDefault = 1,
     };
     x.CheckMembersAreValid();
 }
 public void VerifyValidityCatchesWrongCbDefault()
 {
     var x = new JET_COLUMNCREATE
     {
         szColumnName = "column9",
         pvDefault = new byte[5],
         cbDefault = 6,
     };
     x.CheckMembersAreValid();
 }
            protected JET_COLUMNCREATE[] CreateProjectColumns(JET_COLUMNCREATE column1, JET_COLUMNCREATE column2)
            {
                var projectColumnCreate = CreateIdColumn(ProjectColumnName);
                var projectNameColumnCreate = CreateIdColumn(ProjectNameColumnName);

                return new JET_COLUMNCREATE[] {
                    projectColumnCreate,
                    projectNameColumnCreate,
                    column1, column2 };
            }
示例#9
0
        public void VerifyValidityCatchesNegativeCbDefault()
        {
            var x = new JET_COLUMNCREATE
            {
                szColumnName = "column9",
                pvDefault    = new byte[0],
                cbDefault    = -53,
            };

            x.CheckMembersAreValid();
        }
示例#10
0
        public void JetColumnCreateToString()
        {
            var columncreate = new JET_COLUMNCREATE
            {
                szColumnName = "ImaginativeColumnName",
                coltyp       = JET_coltyp.Text,
                grbit        = ColumndefGrbit.ColumnFixed
            };

            Assert.AreEqual("JET_COLUMNCREATE(ImaginativeColumnName,Text,ColumnFixed)", columncreate.ToString());
        }
示例#11
0
        public void VerifyValidityCatchesWrongCbDefault()
        {
            var x = new JET_COLUMNCREATE
            {
                szColumnName = "column9",
                pvDefault    = new byte[5],
                cbDefault    = 6,
            };

            x.CheckMembersAreValid();
        }
示例#12
0
        public void VerifyValidityCatchesInvalidCbDefault()
        {
            var x = new JET_COLUMNCREATE
            {
                szColumnName = "column9",
                pvDefault    = null,
                cbDefault    = 1,
            };

            x.CheckMembersAreValid();
        }
            protected JET_COLUMNCREATE[] CreateProjectColumns(JET_COLUMNCREATE column1, JET_COLUMNCREATE column2)
            {
                var projectColumnCreate     = CreateIdColumn(ProjectColumnName);
                var projectNameColumnCreate = CreateIdColumn(ProjectNameColumnName);

                return(new JET_COLUMNCREATE[] {
                    projectColumnCreate,
                    projectNameColumnCreate,
                    column1, column2
                });
            }
示例#14
0
        public void VerifyColumnCreateCanBeSerialized()
        {
            var expected = new JET_COLUMNCREATE
            {
                szColumnName = "col1_short",
                coltyp       = JET_coltyp.Short,
                cbMax        = 2,
                pvDefault    = BitConverter.GetBytes((short)37),
                cbDefault    = 2,
            };

            SerializeAndCompareContent(expected);
        }
示例#15
0
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var nameColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = NameColumnName,
                    coltyp       = JET_coltyp.Long,
                    grbit        = ColumndefGrbit.ColumnNotNULL
                };

                var valueColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = ValueColumnName,
                    coltyp       = JET_coltyp.LongBinary,
                    grbit        = ColumndefGrbit.None
                };

                var columns = new JET_COLUMNCREATE[] { nameColumnCreate, valueColumnCreate };

                var nameIndexKey = "+" + NameColumnName + "\0\0";

                var indexes = new JET_INDEXCREATE[]
                {
                    new JET_INDEXCREATE
                    {
                        szIndexName = NameIndexName,
                        szKey       = nameIndexKey,
                        cbKey       = nameIndexKey.Length,
                        grbit       = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull,
                        ulDensity   = 80
                    }
                };

                var tableCreate = new JET_TABLECREATE()
                {
                    szTableName    = TableName,
                    ulPages        = 16,
                    ulDensity      = 80,
                    rgcolumncreate = columns,
                    cColumns       = columns.Length,
                    rgindexcreate  = indexes,
                    cIndexes       = indexes.Length
                };

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _nameColumnId  = nameColumnCreate.columnid;
                _valueColumnId = valueColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
 public void Setup()
 {
     this.managed = new JET_COLUMNCREATE()
     {
         szColumnName = "column9",
         coltyp = JET_coltyp.Binary,
         cbMax = 0x42,
         grbit = ColumndefGrbit.ColumnAutoincrement,
         pvDefault = null,
         cbDefault = 0,
         cp = JET_CP.Unicode,
         columnid = new JET_COLUMNID { Value = 7 },
         err = JET_err.RecoveredWithoutUndo,
     };
     this.native = this.managed.GetNativeColumnCreate();
 }
示例#17
0
        public void Setup()
        {
            this.nativeSource = new NATIVE_COLUMNCREATE()
            {
                szColumnName = EseInteropTestHelper.MarshalStringToHGlobalAnsi("column9"),
                coltyp       = (uint)JET_coltyp.Binary,
                cbMax        = 0x42,
                grbit        = (uint)ColumndefGrbit.ColumnAutoincrement,
                pvDefault    = IntPtr.Zero,
                cbDefault    = 0,
                cp           = (uint)JET_CP.Unicode,
                columnid     = 7,
                err          = (int)JET_err.RecoveredWithoutUndo,
            };

            this.managedTarget = new JET_COLUMNCREATE();
            this.managedTarget.SetFromNativeColumnCreate(ref this.nativeSource);
        }
示例#18
0
 public void Setup()
 {
     this.managed = new JET_COLUMNCREATE()
     {
         szColumnName = "column9",
         coltyp       = JET_coltyp.Binary,
         cbMax        = 0x42,
         grbit        = ColumndefGrbit.ColumnAutoincrement,
         pvDefault    = null,
         cbDefault    = 0,
         cp           = JET_CP.Unicode,
         columnid     = new JET_COLUMNID {
             Value = 7
         },
         err = JET_err.RecoveredWithoutUndo,
     };
     this.native = this.managed.GetNativeColumnCreate();
 }
        public void Setup()
        {
            this.nativeSource = new NATIVE_COLUMNCREATE()
            {
                szColumnName = Marshal.StringToHGlobalAnsi("column9"),
                coltyp = (uint)JET_coltyp.Binary,
                cbMax = 0x42,
                grbit = (uint)ColumndefGrbit.ColumnAutoincrement,
                pvDefault = IntPtr.Zero,
                cbDefault = 0,
                cp = (uint)JET_CP.Unicode,
                columnid = 7,
                err = (int)JET_err.RecoveredWithoutUndo,
            };

            this.managedTarget = new JET_COLUMNCREATE();
            this.managedTarget.SetFromNativeColumnCreate(this.nativeSource);
        }
示例#20
0
        public void VerifyJetColumncreateInequality()
        {
            var columncreates = new JET_COLUMNCREATE[10];

            for (int i = 0; i < columncreates.Length; ++i)
            {
                columncreates[i] = new JET_COLUMNCREATE
                {
                    szColumnName = "column9",
                    coltyp       = JET_coltyp.Binary,
                    cbMax        = 0x42,
                    grbit        = ColumndefGrbit.ColumnAutoincrement,
                    pvDefault    = BitConverter.GetBytes(253),
                    cbDefault    = 4,
                    cp           = JET_CP.Unicode,
                    columnid     = new JET_COLUMNID
                    {
                        Value = 7
                    },
                    err = JET_err.RecoveredWithoutUndo,
                };
            }

            int j = 1;

            columncreates[j++].szColumnName = "different";
            columncreates[j++].coltyp       = JET_coltyp.LongBinary;
            columncreates[j++].grbit        = ColumndefGrbit.ColumnEscrowUpdate;
            columncreates[j++].pvDefault    = BitConverter.GetBytes(254);
            columncreates[j++].cbDefault--;
            columncreates[j++].cp       = JET_CP.ASCII;
            columncreates[j++].columnid = new JET_COLUMNID
            {
                Value = 8
            };
            columncreates[j++].err = JET_err.UnicodeNormalizationNotSupported;
            columncreates[j++]     = new JET_COLUMNCREATE {
                szColumnName = "another"
            };
            Debug.Assert(j == columncreates.Length, "Didn't fill in all entries of columncreates");
            VerifyAll(columncreates);
        }
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var nameColumnCreate = CreateIdColumn(NameColumnName);
                var valueColumnCreate = CreateBinaryColumn(ValueColumnName);

                var columns = new JET_COLUMNCREATE[] { nameColumnCreate, valueColumnCreate };

                var nameIndexKey = CreateIndexKey(NameColumnName);

                var indexes = new JET_INDEXCREATE[]
                {
                    CreatePrimaryIndex(nameIndexKey)
                };

                var tableCreate = CreateTable(TableName, columns, indexes);

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _nameColumnId = nameColumnCreate.columnid;
                _valueColumnId = valueColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
示例#22
0
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var nameColumnCreate  = CreateIdColumn(NameColumnName);
                var valueColumnCreate = CreateBinaryColumn(ValueColumnName);

                var columns = new JET_COLUMNCREATE[] { nameColumnCreate, valueColumnCreate };

                var nameIndexKey = CreateIndexKey(NameColumnName);

                var indexes = new JET_INDEXCREATE[]
                {
                    CreatePrimaryIndex(nameIndexKey)
                };

                var tableCreate = CreateTable(TableName, columns, indexes);

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _nameColumnId  = nameColumnCreate.columnid;
                _valueColumnId = valueColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
示例#23
0
        public void VerifyJetColumncreateEquality()
        {
            var x = new JET_COLUMNCREATE
            {
                szColumnName = "column9",
                coltyp       = JET_coltyp.Binary,
                cbMax        = 0x42,
                grbit        = ColumndefGrbit.ColumnAutoincrement,
                pvDefault    = BitConverter.GetBytes(253),
                cbDefault    = 4,
                cp           = JET_CP.Unicode,
                columnid     = new JET_COLUMNID
                {
                    Value = 7
                },
                err = JET_err.RecoveredWithoutUndo,
            };

            var y = new JET_COLUMNCREATE
            {
                szColumnName = "column9",
                coltyp       = JET_coltyp.Binary,
                cbMax        = 0x42,
                grbit        = ColumndefGrbit.ColumnAutoincrement,
                pvDefault    = BitConverter.GetBytes(253),
                cbDefault    = 4,
                cp           = JET_CP.Unicode,
                columnid     = new JET_COLUMNID
                {
                    Value = 7
                },
                err = JET_err.RecoveredWithoutUndo,
            };

            TestContentEquals(x, y);
        }
示例#24
0
        public void CreateTableColumnIndex3OnXp()
        {
            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("XpCreateTableColumnIndex3"))
            {
                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))
                    {
                        Api.JetCreateTableColumnIndex3(session, dbid, tablecreate);
                        Assert.AreNotEqual(JET_TABLEID.Nil, tablecreate.tableid);

                        // 1 table, 2 columns, 2 indices = 5 objects.
                        Assert.AreEqual(tablecreate.cCreated, 5);
                        Assert.AreNotEqual(tablecreate.rgcolumncreate[0].columnid, JET_COLUMNID.Nil);
                        Assert.AreNotEqual(tablecreate.rgcolumncreate[1].columnid, JET_COLUMNID.Nil);

                        Api.JetCloseTable(session, tablecreate.tableid);
                        transaction.Commit(CommitTransactionGrbit.LazyFlush);
                    }
                }
            }
        }
示例#25
0
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var idColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = IdColumnName,
                    coltyp = JET_coltyp.Long,
                    grbit = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL
                };

                var nameColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = NameColumnName,
                    coltyp = JET_coltyp.LongText,
                    cp = JET_CP.Unicode,
                    grbit = ColumndefGrbit.ColumnNotNULL
                };

                var columns = new JET_COLUMNCREATE[] { idColumnCreate, nameColumnCreate };

                var idIndexKey = "+" + IdColumnName + "\0\0";
                var nameIndexKey = "+" + NameColumnName + "\0\0";

                var indexes = new JET_INDEXCREATE[]
                {
                    new JET_INDEXCREATE
                    {
                        szIndexName = IdIndexName,
                        szKey = idIndexKey,
                        cbKey = idIndexKey.Length,
                        grbit = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull,
                        ulDensity = 80
                    },
                    new JET_INDEXCREATE
                    {
                        szIndexName = NameIndexName,
                        szKey = nameIndexKey,
                        cbKey = nameIndexKey.Length,
                        grbit = CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull | VistaGrbits.IndexDisallowTruncation,
                        ulDensity = 80,
                        cbKeyMost = SystemParameters.KeyMost
                    }
                };

                var tableCreate = new JET_TABLECREATE()
                {
                    szTableName = TableName,
                    ulPages = 16,
                    ulDensity = 80,
                    rgcolumncreate = columns,
                    cColumns = columns.Length,
                    rgindexcreate = indexes,
                    cIndexes = indexes.Length
                };

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _idColumnId = idColumnCreate.columnid;
                _nameColumnId = nameColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
示例#26
0
        public void JetCreateTemplateTableColumnIndex()
        {
            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);
            Api.JetCreateTableColumnIndex3(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,
            };

            Api.JetCreateTableColumnIndex3(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);
        }
示例#27
0
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var idColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = IdColumnName,
                    coltyp       = JET_coltyp.Long,
                    grbit        = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL
                };

                var nameColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = NameColumnName,
                    coltyp       = JET_coltyp.LongText,
                    cp           = JET_CP.Unicode,
                    grbit        = ColumndefGrbit.ColumnNotNULL
                };

                var columns = new JET_COLUMNCREATE[] { idColumnCreate, nameColumnCreate };

                var idIndexKey   = "+" + IdColumnName + "\0\0";
                var nameIndexKey = "+" + NameColumnName + "\0\0";

                var indexes = new JET_INDEXCREATE[]
                {
                    new JET_INDEXCREATE
                    {
                        szIndexName = IdIndexName,
                        szKey       = idIndexKey,
                        cbKey       = idIndexKey.Length,
                        grbit       = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull,
                        ulDensity   = 80
                    },
                    new JET_INDEXCREATE
                    {
                        szIndexName = NameIndexName,
                        szKey       = nameIndexKey,
                        cbKey       = nameIndexKey.Length,
                        grbit       = CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull | VistaGrbits.IndexDisallowTruncation,
                        ulDensity   = 80,
                        // this should be 2000 bytes Max after vista
                        cbKeyMost = SystemParameters.KeyMost
                    }
                };

                var tableCreate = new JET_TABLECREATE()
                {
                    szTableName    = TableName,
                    ulPages        = 16,
                    ulDensity      = 80,
                    rgcolumncreate = columns,
                    cColumns       = columns.Length,
                    rgindexcreate  = indexes,
                    cIndexes       = indexes.Length
                };

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _idColumnId   = idColumnCreate.columnid;
                _nameColumnId = nameColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
示例#28
0
        public void JetCreateTableColumnIndexWithInvalidIndexName()
        {
            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
            {
                Api.JetCreateTableColumnIndex3(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);
        }
 protected JET_TABLECREATE CreateTable(string tableName, JET_COLUMNCREATE[] columns, JET_INDEXCREATE[] indexes)
 {
     return new JET_TABLECREATE()
     {
         szTableName = tableName,
         ulPages = 16,
         ulDensity = 80,
         rgcolumncreate = columns,
         cColumns = columns.Length,
         rgindexcreate = indexes,
         cIndexes = indexes.Length
     };
 }
示例#30
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)
                        {
                        }
                    }
                }
            }
        }
示例#31
0
        public void JetCreateTemplateTableColumnIndex()
        {
            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);
            Api.JetCreateTableColumnIndex3(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,
            };

            Api.JetCreateTableColumnIndex3(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);
        }
示例#32
0
        private void JetCreateTableColumnIndex()
        {
            Console.WriteLine("\tJetCreateTableColumnIndex()");
            var columncreates = new JET_COLUMNCREATE[13];

            for (int i = 0; i < columncreates.Length; ++i)
            {
                columncreates[i] = new JET_COLUMNCREATE();
            }

            columncreates[0] = new JET_COLUMNCREATE {
                szColumnName = "recordID", coltyp = JET_coltyp.Long
            };

            columncreates[1].szColumnName = "tagged";
            columncreates[1].coltyp       = VistaColtyp.LongLong;
            columncreates[1].grbit        = ColumndefGrbit.ColumnTagged;

            columncreates[2].szColumnName = "separated_lv";
            columncreates[2].coltyp       = JET_coltyp.LongBinary;

            columncreates[3].szColumnName = "compressed_unicode";
            columncreates[3].coltyp       = JET_coltyp.LongText;
            columncreates[3].cp           = JET_CP.Unicode;
            columncreates[3].grbit        = Windows7Grbits.ColumnCompressed;

            columncreates[4].szColumnName = "compressed_ascii";
            columncreates[4].coltyp       = JET_coltyp.LongText;
            columncreates[4].cp           = JET_CP.ASCII;
            columncreates[4].grbit        = Windows7Grbits.ColumnCompressed;

            columncreates[5].szColumnName = "compressed_binary";
            columncreates[5].coltyp       = JET_coltyp.LongBinary;
            columncreates[5].grbit        = Windows7Grbits.ColumnCompressed;

            columncreates[6].szColumnName = "columntodelete";
            columncreates[6].coltyp       = JET_coltyp.Long;

            columncreates[7].szColumnName = "autoinc";
            columncreates[7].coltyp       = JET_coltyp.Long;
            columncreates[7].grbit        = ColumndefGrbit.ColumnAutoincrement;

            columncreates[8].szColumnName = "version";
            columncreates[8].coltyp       = JET_coltyp.Long;
            columncreates[8].grbit        = ColumndefGrbit.ColumnVersion;

            columncreates[9].szColumnName = "unicode";
            columncreates[9].coltyp       = JET_coltyp.LongText;
            columncreates[9].cp           = JET_CP.Unicode;
            columncreates[9].pvDefault    = Encoding.Unicode.GetBytes(
                "This is the default value for the unicode column");
            columncreates[9].cbDefault = columncreates[9].pvDefault.Length;

            columncreates[10].szColumnName = "ascii";
            columncreates[10].coltyp       = JET_coltyp.LongText;
            columncreates[10].cp           = JET_CP.ASCII;
            columncreates[10].pvDefault    = Encoding.ASCII.GetBytes("This is the default value for the ASCII column");
            columncreates[10].cbDefault    = columncreates[10].pvDefault.Length;

            columncreates[11].szColumnName = "columntodelete2";
            columncreates[11].coltyp       = JET_coltyp.Long;

            columncreates[12].szColumnName = "fixed";
            columncreates[12].coltyp       = VistaColtyp.LongLong;
            columncreates[12].grbit        = ColumndefGrbit.ColumnFixed;

            var primarySpaceHints = new JET_SPACEHINTS();

            primarySpaceHints.ulInitialDensity = 100;
            primarySpaceHints.cbInitial        = 512 * 1024;

            var secondarySpaceHints = new JET_SPACEHINTS();

            secondarySpaceHints.ulInitialDensity = 80;
            secondarySpaceHints.cbInitial        = 96 * 1024;
            secondarySpaceHints.ulGrowth         = 150;
            secondarySpaceHints.cbMinExtent      = 64 * 1024;
            secondarySpaceHints.cbMaxExtent      = 256 * 1024;

            var indexcreates = new JET_INDEXCREATE[14];

            for (int i = 0; i < indexcreates.Length; ++i)
            {
                indexcreates[i] = new JET_INDEXCREATE();
            }

            indexcreates[0].szIndexName = "index_recordID";
            indexcreates[0].szKey       = "+recordID\0\0";
            indexcreates[0].cbKey       = indexcreates[0].szKey.Length;
            indexcreates[0].grbit       = CreateIndexGrbit.IndexPrimary;
            indexcreates[0].pSpaceHints = primarySpaceHints;

            indexcreates[1]  = this.MakeIndexcreate("tagged");
            indexcreates[2]  = this.MakeIndexcreate("separated_lv");
            indexcreates[3]  = this.MakeIndexcreate("compressed_unicode");
            indexcreates[4]  = this.MakeIndexcreate("compressed_ascii");
            indexcreates[5]  = this.MakeIndexcreate("compressed_binary");
            indexcreates[6]  = this.MakeIndexcreate("autoinc");
            indexcreates[7]  = this.MakeIndexcreate("version");
            indexcreates[8]  = this.MakeIndexcreate("unicode");
            indexcreates[9]  = this.MakeIndexcreate("ascii");
            indexcreates[10] = this.MakeIndexcreate("fixed");

            indexcreates[11].szIndexName = "secondary";
            indexcreates[11].szKey       = "+autoinc\0+compressed_unicode\0+recordID\0\0";
            indexcreates[11].cbKey       = indexcreates[11].szKey.Length;
            indexcreates[11].grbit       = CreateIndexGrbit.IndexUnique;
            indexcreates[11].pSpaceHints = secondarySpaceHints;

            indexcreates[12].szIndexName = "indextodelete";
            indexcreates[12].szKey       = "+autoinc\0+recordID\0\0";
            indexcreates[12].cbKey       = indexcreates[12].szKey.Length;

            indexcreates[13] = this.MakeIndexcreate("columntodelete2");

            var tablecreate = new JET_TABLECREATE();

            tablecreate.szTableName    = this.table;
            tablecreate.ulPages        = 1;
            tablecreate.ulDensity      = 100;
            tablecreate.rgcolumncreate = columncreates;
            tablecreate.cColumns       = tablecreate.rgcolumncreate.Length;
            tablecreate.rgindexcreate  = indexcreates;
            tablecreate.cIndexes       = tablecreate.rgindexcreate.Length;

            Api.JetBeginTransaction(this.sesid);
            Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreate);
            Api.JetCloseTable(this.sesid, tablecreate.tableid);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
        }
示例#33
0
        private void JetCreateTableColumnIndex()
        {
            Console.WriteLine("\tJetCreateTableColumnIndex()");
            var columncreates = new JET_COLUMNCREATE[13];
            for (int i = 0; i < columncreates.Length; ++i)
            {
                columncreates[i] = new JET_COLUMNCREATE();
            }

            columncreates[0] = new JET_COLUMNCREATE { szColumnName = "recordID", coltyp = JET_coltyp.Long };

            columncreates[1].szColumnName = "tagged";
            columncreates[1].coltyp = VistaColtyp.LongLong;
            columncreates[1].grbit = ColumndefGrbit.ColumnTagged;

            columncreates[2].szColumnName = "separated_lv";
            columncreates[2].coltyp = JET_coltyp.LongBinary;

            columncreates[3].szColumnName = "compressed_unicode";
            columncreates[3].coltyp = JET_coltyp.LongText;
            columncreates[3].cp = JET_CP.Unicode;
            columncreates[3].grbit = Windows7Grbits.ColumnCompressed;

            columncreates[4].szColumnName = "compressed_ascii";
            columncreates[4].coltyp = JET_coltyp.LongText;
            columncreates[4].cp = JET_CP.ASCII;
            columncreates[4].grbit = Windows7Grbits.ColumnCompressed;

            columncreates[5].szColumnName = "compressed_binary";
            columncreates[5].coltyp = JET_coltyp.LongBinary;
            columncreates[5].grbit = Windows7Grbits.ColumnCompressed;

            columncreates[6].szColumnName = "columntodelete";
            columncreates[6].coltyp = JET_coltyp.Long;

            columncreates[7].szColumnName = "autoinc";
            columncreates[7].coltyp = JET_coltyp.Long;
            columncreates[7].grbit = ColumndefGrbit.ColumnAutoincrement;

            columncreates[8].szColumnName = "version";
            columncreates[8].coltyp = JET_coltyp.Long;
            columncreates[8].grbit = ColumndefGrbit.ColumnVersion;

            columncreates[9].szColumnName = "unicode";
            columncreates[9].coltyp = JET_coltyp.LongText;
            columncreates[9].cp = JET_CP.Unicode;
            columncreates[9].pvDefault = Encoding.Unicode.GetBytes(
                "This is the default value for the unicode column");
            columncreates[9].cbDefault = columncreates[9].pvDefault.Length;

            columncreates[10].szColumnName = "ascii";
            columncreates[10].coltyp = JET_coltyp.LongText;
            columncreates[10].cp = JET_CP.ASCII;
            columncreates[10].pvDefault = Encoding.ASCII.GetBytes("This is the default value for the ASCII column");
            columncreates[10].cbDefault = columncreates[10].pvDefault.Length;

            columncreates[11].szColumnName = "columntodelete2";
            columncreates[11].coltyp = JET_coltyp.Long;

            columncreates[12].szColumnName = "fixed";
            columncreates[12].coltyp = VistaColtyp.LongLong;
            columncreates[12].grbit = ColumndefGrbit.ColumnFixed;

            var primarySpaceHints = new JET_SPACEHINTS();
            primarySpaceHints.ulInitialDensity = 100;
            primarySpaceHints.cbInitial = 512 * 1024;

            var secondarySpaceHints = new JET_SPACEHINTS();
            secondarySpaceHints.ulInitialDensity = 80;
            secondarySpaceHints.cbInitial = 96 * 1024;
            secondarySpaceHints.ulGrowth = 150;
            secondarySpaceHints.cbMinExtent = 64 * 1024;
            secondarySpaceHints.cbMaxExtent = 256 * 1024;

            var indexcreates = new JET_INDEXCREATE[14];
            for (int i = 0; i < indexcreates.Length; ++i)
            {
                indexcreates[i] = new JET_INDEXCREATE();
            }

            indexcreates[0].szIndexName = "index_recordID";
            indexcreates[0].szKey = "+recordID\0\0";
            indexcreates[0].cbKey = indexcreates[0].szKey.Length;
            indexcreates[0].grbit = CreateIndexGrbit.IndexPrimary;
            indexcreates[0].pSpaceHints = primarySpaceHints;

            indexcreates[1] = this.MakeIndexcreate("tagged");
            indexcreates[2] = this.MakeIndexcreate("separated_lv");
            indexcreates[3] = this.MakeIndexcreate("compressed_unicode");
            indexcreates[4] = this.MakeIndexcreate("compressed_ascii");
            indexcreates[5] = this.MakeIndexcreate("compressed_binary");
            indexcreates[6] = this.MakeIndexcreate("autoinc");
            indexcreates[7] = this.MakeIndexcreate("version");
            indexcreates[8] = this.MakeIndexcreate("unicode");
            indexcreates[9] = this.MakeIndexcreate("ascii");
            indexcreates[10] = this.MakeIndexcreate("fixed");

            indexcreates[11].szIndexName = "secondary";
            indexcreates[11].szKey = "+autoinc\0+compressed_unicode\0+recordID\0\0";
            indexcreates[11].cbKey = indexcreates[11].szKey.Length;
            indexcreates[11].grbit = CreateIndexGrbit.IndexUnique;
            indexcreates[11].pSpaceHints = secondarySpaceHints;

            indexcreates[12].szIndexName = "indextodelete";
            indexcreates[12].szKey = "+autoinc\0+recordID\0\0";
            indexcreates[12].cbKey = indexcreates[12].szKey.Length;

            indexcreates[13] = this.MakeIndexcreate("columntodelete2");

            var tablecreate = new JET_TABLECREATE();
            tablecreate.szTableName = this.table;
            tablecreate.ulPages = 1;
            tablecreate.ulDensity = 100;
            tablecreate.rgcolumncreate = columncreates;
            tablecreate.cColumns = tablecreate.rgcolumncreate.Length;
            tablecreate.rgindexcreate = indexcreates;
            tablecreate.cIndexes = tablecreate.rgindexcreate.Length;

            Api.JetBeginTransaction(this.sesid);
            Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreate);
            Api.JetCloseTable(this.sesid, tablecreate.tableid);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
        }
示例#34
0
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var projectColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = ProjectColumnName,
                    coltyp       = JET_coltyp.Long,
                    grbit        = ColumndefGrbit.ColumnNotNULL
                };

                var documentColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = DocumentColumnName,
                    coltyp       = JET_coltyp.Long,
                    grbit        = ColumndefGrbit.ColumnNotNULL
                };

                var identifierColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = IdentifierColumnName,
                    coltyp       = JET_coltyp.Long,
                    grbit        = ColumndefGrbit.ColumnNotNULL
                };

                var locationsColumnCreate = new JET_COLUMNCREATE()
                {
                    szColumnName = LocationsColumnName,
                    coltyp       = JET_coltyp.LongBinary,
                    grbit        = ColumndefGrbit.None
                };

                var columns = new JET_COLUMNCREATE[] { projectColumnCreate, documentColumnCreate, identifierColumnCreate, locationsColumnCreate };

                var projectAndDocumentAndIdentifierIndexKey = "+" + ProjectColumnName + "\0+" + DocumentColumnName + "\0+" + IdentifierColumnName + "\0\0";
                var projectAndDocumentIndexKey = "+" + ProjectColumnName + "\0+" + DocumentColumnName + "\0\0";
                var documentIndexKey           = "+" + DocumentColumnName + "\0\0";

                var indexes = new JET_INDEXCREATE[]
                {
                    new JET_INDEXCREATE
                    {
                        szIndexName = ProjectAndDocumentAndIdentifierIndexName,
                        szKey       = projectAndDocumentAndIdentifierIndexKey,
                        cbKey       = projectAndDocumentAndIdentifierIndexKey.Length,
                        grbit       = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull,
                        ulDensity   = 80
                    },
                    new JET_INDEXCREATE
                    {
                        szIndexName = ProjectAndDocumentIndexName,
                        szKey       = projectAndDocumentIndexKey,
                        cbKey       = projectAndDocumentIndexKey.Length,
                        grbit       = CreateIndexGrbit.IndexDisallowNull,
                        ulDensity   = 80
                    },
                    new JET_INDEXCREATE
                    {
                        szIndexName = DocumentIndexName,
                        szKey       = documentIndexKey,
                        cbKey       = documentIndexKey.Length,
                        grbit       = CreateIndexGrbit.IndexDisallowNull,
                        ulDensity   = 80
                    }
                };

                var tableCreate = new JET_TABLECREATE()
                {
                    szTableName    = TableName,
                    ulPages        = 16,
                    ulDensity      = 80,
                    rgcolumncreate = columns,
                    cColumns       = columns.Length,
                    rgindexcreate  = indexes,
                    cIndexes       = indexes.Length
                };

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _projectColumnId    = projectColumnCreate.columnid;
                _documentColumnId   = documentColumnCreate.columnid;
                _identifierColumnId = identifierColumnCreate.columnid;
                _locationsColumnId  = locationsColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
示例#35
0
        public void CreateTableColumnIndex3OnXp()
        {
            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("XpCreateTableColumnIndex3"))
            {
                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))
                    {
                        Api.JetCreateTableColumnIndex3(session, dbid, tablecreate);
                        Assert.AreNotEqual(JET_TABLEID.Nil, tablecreate.tableid);

                        // 1 table, 2 columns, 2 indices = 5 objects.
                        Assert.AreEqual(tablecreate.cCreated, 5);
                        Assert.AreNotEqual(tablecreate.rgcolumncreate[0].columnid, JET_COLUMNID.Nil);
                        Assert.AreNotEqual(tablecreate.rgcolumncreate[1].columnid, JET_COLUMNID.Nil);

                        Api.JetCloseTable(session, tablecreate.tableid);
                        transaction.Commit(CommitTransactionGrbit.LazyFlush);
                    }
                }
            }
        }
        public void JetCreateTableColumnIndex4UnicodeIndex2()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            const string LocaleName = "en-US";

            var unicode = new JET_UNICODEINDEX()
            {
                szLocaleName = LocaleName,
                dwMapFlags   = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.None),
            };

            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,
                    pidxUnicode = unicode,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 99,
                },
                new JET_INDEXCREATE
                {
                    szIndexName = Index2Name,
                    szKey       = Index2Description,
                    cbKey       = Index2Description.Length + 1,
                    pidxUnicode = unicode,
                    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,
            };

            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);

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

            Api.JetCloseTable(this.sesid, tableCreated);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
        }
示例#37
0
 public void JetColumnCreateToString()
 {
     var columncreate = new JET_COLUMNCREATE
     {
         szColumnName = "ImaginativeColumnName",
         coltyp = JET_coltyp.Text,
         grbit = ColumndefGrbit.ColumnFixed
     };
     Assert.AreEqual("JET_COLUMNCREATE(ImaginativeColumnName,Text,ColumnFixed)", columncreate.ToString());
 }