Set Template Table

Jun 12, 2010 at 2:59 PM

Hi,

  I want to set template table for newly created table. How can i do this with Managed Esent?

 

Thanks,

Jude Aloysius

Jun 13, 2010 at 6:09 PM

Creating a table with a template table requires the JetCreateTableColumnIndex API, which isn't yet supported in ManagedEsent. It will be added in the next few months

 

Jun 16, 2010 at 1:09 PM
Edited Jun 16, 2010 at 1:10 PM
thanks for replying, Can u help me in callin JetCreateTableColumnIndex directly using pinvoke. I defined the structure as follows [StructLayout(LayoutKind.Sequential)] struct JET_TUPLELIMITS_ESE//tagJET_TUPLELIMITS { ulong chLengthMin; ulong chLengthMax; ulong chToIndexMax; ulong cchIncrement; ulong ichStart; } ; [StructLayout(LayoutKind.Sequential)] struct JET_UNICODEINDEX_ESE//tagJET_UNICODEINDEX { ulong lcid; ulong dwMapFlags; } ; [StructLayout(LayoutKind.Sequential)] struct JET_CONDITIONALCOLUMN_ESE//tagJET_CONDITIONALCOLUMN { ulong cbStruct; string szColumnName; ulong grbit; }; [StructLayout(LayoutKind.Sequential)] internal struct JET_INDEXCREATE_ESE//tagJET_INDEXCREATE { ulong cbStruct; string szIndexName; string szKey; ulong cbKey; ulong grbit; ulong ulDensity; [StructLayout(LayoutKind.Explicit)] public struct Union1 { [FieldOffset(0)]ulong lcid; [FieldOffset(0)] JET_UNICODEINDEX_ESE pidxunicode; }; [StructLayout(LayoutKind.Explicit)] public struct union2 { [FieldOffset(0)]ulong cbVarSegMac; [FieldOffset(0)] JET_TUPLELIMITS_ESE ptuplelimits; }; JET_CONDITIONALCOLUMN_ESE rgconditionalcolumn; ulong cConditionalColumn; long err; ulong cbKeyMost; } ; [StructLayout(LayoutKind.Sequential)] internal unsafe struct JET_COLUMNCREATE { public long cbStruct; public string szColumnName; public int coltyp; public ulong cbMax; public ulong grbit; public object pvDefault; public ulong cbDefault; public ulong cp; public ulong columnid; public long err; }; [StructLayout(LayoutKind.Sequential)] internal struct JET_TABLECREATE//tagJET_TABLECREATE { public ulong cbStruct; public string szTableName; public string szTemplateTableName; public ulong ulPages; public ulong ulDensity; public JET_COLUMNCREATE[] rgcolumncreate;/*JET_COLUMNCREATE[]*/ public ulong cColumns; public JET_INDEXCREATE_ESE[] rgindexcreate; /*JET_INDEXCREATE[]*/ public ulong cIndexes; public ulong grbit; public IntPtr tableid; public ulong cCreated; } then i did a dll import as follows :- [DllImport("esent.dll", SetLastError = true)] public static extern int JetCreateInstance(out IntPtr DbInstance, string Instancename); but i am getting error invalid parameter. prior to this i was able to create instance ,seesion and also create database using dllimport (imported directly from esent.dll) Its just that the parameters are not mapping. Can u please help me with this? Thanks, Jude Aloysius
Jun 16, 2010 at 3:44 PM

JetCreateTableColumnIndex is tricky to access via P/Invoke (which is why it isn't done yet). Getting all the memory pinned properly will be part of he problem.

In the example above JetCreateInstance takes an ASCII string, not a Unicode string so you would need to change the string marshalling. ManagedEsent uses P/Invoke to access the functions you list so I strongly suggest you use it. If you want, you can try adding support for JetCreateTableColumnIndex, but it will be a lot of work to recreate the project from scratch.

 

 

Jun 16, 2010 at 4:40 PM
Hi, I am trying to add support for JetCreateTableColumnIndex,, I accidently typed JetCreateInstance sry about that. Are the structures that i have defined, belowright or not? And also i am getting error -1003(invalid parameter) while calling [DllImport("esent.dll", SetLastError = true)] public static extern int JetCreateTableColumnIndex(IntPtr SessionID, ulong DatabaseID,ref JET_TABLECREATE ptablecreate); [StructLayout(LayoutKind.Sequential)] struct JET_TUPLELIMITS_ESE//tagJET_TUPLELIMITS { ulong chLengthMin; ulong chLengthMax; ulong chToIndexMax; ulong cchIncrement; ulong ichStart; } ; [StructLayout(LayoutKind.Sequential)] struct JET_UNICODEINDEX_ESE//tagJET_UNICODEINDEX { ulong lcid; ulong dwMapFlags; } ; [StructLayout(LayoutKind.Sequential)] struct JET_CONDITIONALCOLUMN_ESE//tagJET_CONDITIONALCOLUMN { ulong cbStruct; string szColumnName; ulong grbit; }; [StructLayout(LayoutKind.Sequential)] internal struct JET_INDEXCREATE_ESE//tagJET_INDEXCREATE { ulong cbStruct; string szIndexName; string szKey; ulong cbKey; ulong grbit; ulong ulDensity; [StructLayout(LayoutKind.Explicit)] public struct Union1 { [FieldOffset(0)]ulong lcid; [FieldOffset(0)] JET_UNICODEINDEX_ESE pidxunicode; }; [StructLayout(LayoutKind.Explicit)] public struct union2 { [FieldOffset(0)]ulong cbVarSegMac; [FieldOffset(0)] JET_TUPLELIMITS_ESE ptuplelimits; }; JET_CONDITIONALCOLUMN_ESE rgconditionalcolumn; ulong cConditionalColumn; long err; ulong cbKeyMost; } ; [StructLayout(LayoutKind.Sequential)] internal unsafe struct JET_COLUMNCREATE { public long cbStruct; public string szColumnName; public int coltyp; public ulong cbMax; public ulong grbit; public object pvDefault; public ulong cbDefault; public ulong cp; public ulong columnid; public long err; }; [StructLayout(LayoutKind.Sequential)] internal struct JET_TABLECREATE//tagJET_TABLECREATE { public ulong cbStruct; public string szTableName; public string szTemplateTableName; public ulong ulPages; public ulong ulDensity; public JET_COLUMNCREATE[] rgcolumncreate;/*JET_COLUMNCREATE[]*/ public ulong cColumns; public JET_INDEXCREATE_ESE[] rgindexcreate; /*JET_INDEXCREATE[]*/ public ulong cIndexes; public ulong grbit; public IntPtr tableid; public ulong cCreated; }
Jun 16, 2010 at 6:23 PM

I don't think P/Invoke can recursively pin/convert all the structures -- the JET_TABLECREATE structure contains arrays of other structures and the memory in those structures has to be pinned/converted as well (i.e. the strings should be in ASCII format, unless you use JetCreateTableColumnIndexW). I haven't seen examples of P/Invoke handling that.

A lot of the structues you describe above are already in ManagedEsent. Look at NATIVE_UNICODEINDEX, NATIVE_INDEXCREATE, NATIVE_CONDITIONALCOLUMN etc.

A -1003 error is often caused by having the wrong cbStruct size in one of the structures -- make sure you set those properly.