Fix the index creation failure

This commit is contained in:
Namhyeon Go 2025-06-23 18:15:37 +09:00
parent ece369f8f0
commit 3e4b6a73b5
2 changed files with 18 additions and 7 deletions

View File

@ -105,22 +105,23 @@ namespace WelsonJS.Launcher
Api.JetAddColumn(_session, tableid, col.Name, coldef, null, 0, out _); Api.JetAddColumn(_session, tableid, col.Name, coldef, null, 0, out _);
} }
string indexKey = $"+{_primaryKey.Name}\0"; string indexName = "primary";
int keyLength = Encoding.ASCII.GetByteCount(indexKey + "\0"); // double null-terminated string key = $"+{_primaryKey.Name}\0";
string fullKeyDescription = indexKey + "\0"; string keyDescription = key + "\0"; // double null-terminated
int keyDescriptionLength = Encoding.ASCII.GetByteCount(keyDescription); // in characters
Api.JetCreateIndex( Api.JetCreateIndex(
_session, _session,
tableid, tableid,
"primary", indexName,
CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique, CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique,
fullKeyDescription, keyDescription,
keyLength, keyDescriptionLength,
100 100
); );
Api.JetCommitTransaction(_session, CommitTransactionGrbit.None);
Api.JetCloseTable(_session, tableid); Api.JetCloseTable(_session, tableid);
Api.JetCommitTransaction(_session, CommitTransactionGrbit.None);
} }
private void CacheColumns() private void CacheColumns()

View File

@ -17,6 +17,16 @@ namespace WelsonJS.Launcher.Storage
public JET_CP CodePage { get; set; } public JET_CP CodePage { get; set; }
public bool IsPrimaryKey { get; set; } = false; public bool IsPrimaryKey { get; set; } = false;
public override string ToString()
{
return Name;
}
public static explicit operator string(Column c)
{
return c.ToString();
}
public Column(string name, JET_coltyp type, int maxSize = 0, JET_CP codePage = JET_CP.None) public Column(string name, JET_coltyp type, int maxSize = 0, JET_CP codePage = JET_CP.None)
{ {
Name = name; Name = name;