123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- #include "nde_c.h"
- #include "nde.h"
- #ifdef _WIN32
- #include "../nu/AutoCharFn.h"
- #include "../nu/AutoWide.h"
- #endif
- /* Database */
- #ifdef _WIN32
- nde_database_t NDE_CreateDatabase(HINSTANCE hInstance)
- {
- return (nde_database_t)new Database(hInstance);
- }
- #else
- nde_database_t NDE_CreateDatabase()
- {
- return (nde_database_t)new Database();
- }
- #endif
- void NDE_DestroyDatabase(nde_database_t db)
- {
- delete (Database *)db;
- }
- #ifdef _WIN32
- nde_table_t NDE_Database_OpenTable(nde_database_t db, const wchar_t *filename, const wchar_t *indexname, int create, int cache)
- {
- Database *database = (Database *)db;
- if (database && filename)
- return (nde_table_t)database->OpenTable(filename, indexname, (BOOL)create, (BOOL)cache);
- else
- return 0;
- }
- #else
- nde_table_t NDE_Database_OpenTable(nde_database_t db, const char *filename, const char *indexname, int create, int cache)
- {
- Database *database = (Database *)db;
- if (database && filename)
- return (nde_table_t)database->OpenTable(filename, indexname, (BOOL)create, (BOOL)cache);
- else
- return 0;
- }
- #endif
- void NDE_Database_CloseTable(nde_database_t db, nde_table_t t)
- {
- Database *database = (Database *)db;
- Table *table = (Table *)t;
- if (database && table)
- {
- database->CloseTable(table);
- }
- }
- /* Table */
- #ifdef _WIN32
- nde_field_t NDE_Table_NewColumn(nde_table_t t, unsigned char id, const char *name, unsigned char type)
- {
- Table *table = (Table *)t;
- if (table)
- return (nde_field_t)table->NewColumn(id, AutoWide(name), type, FALSE);
- else
- return 0;
- }
- #else
- nde_field_t NDE_Table_NewColumn(nde_table_t t, unsigned char id, CFStringRef name, unsigned char type)
- {
- Table *table = (Table *)t;
- if (table)
- return (nde_field_t)table->NewColumn(id, name, type, FALSE);
- else
- return 0;
- }
- #endif
- void NDE_Table_PostColumns(nde_table_t t)
- {
- Table *table = (Table *)t;
- if (table)
- table->PostColumns();
- }
- #ifdef _WIN32
- void NDE_Table_AddIndexByID(nde_table_t t, unsigned char id, const char *name)
- {
- Table *table = (Table *)t;
- if (table)
- table->AddIndexById(id, AutoWide(name));
- }
- #else
- void NDE_Table_AddIndexByID(nde_table_t t, unsigned char id, CFStringRef name)
- {
- Table *table = (Table *)t;
- if (table)
- table->AddIndexById(id, name);
- }
- #endif
- nde_scanner_t NDE_Table_CreateScanner(nde_table_t t)
- {
- Table *table = (Table *)t;
- if (table)
- return (nde_scanner_t)table->NewScanner();
- else
- return 0;
- }
- void NDE_Table_DestroyScanner(nde_table_t t, nde_scanner_t s)
- {
- Table *table = (Table *)t;
- Scanner *scanner = (Scanner *)s;
- if (table && scanner)
- table->DeleteScanner(scanner);
- }
- void NDE_Table_Sync(nde_table_t t)
- {
- Table *table = (Table *)t;
- if (table)
- table->Sync();
- }
- #ifdef _WIN32
- void NDE_Table_Compact(nde_table_t t, int *progress)
- {
- Table *table = (Table *)t;
- if (table)
- table->Compact(progress);
- }
- #endif
- int NDE_Table_GetRecordsCount(nde_table_t t)
- {
- Table *table = (Table *)t;
- if (table)
- return table->GetRecordsCount();
- else
- return 0;
- }
- nde_field_t NDE_Table_GetColumnByID(nde_table_t t, unsigned char id)
- {
- Table *table = (Table *)t;
- if (table)
- return (nde_field_t)table->GetColumnById(id);
- else
- return 0;
- }
- #ifdef _WIN32
- nde_field_t NDE_Table_GetColumnByName(nde_table_t t, const char *name)
- {
- Table *table = (Table *)t;
- if (table && name)
- return (nde_field_t)table->GetColumnByName(AutoWide(name));
- else
- return 0;
- }
- #else
- nde_field_t NDE_Table_GetColumnByName(nde_table_t t, CFStringRef name)
- {
- Table *table = (Table *)t;
- if (table && name)
- return (nde_field_t)table->GetColumnByName(name);
- else
- return 0;
- }
- #endif
- void NDE_Table_SetColumnSearchableByID(nde_table_t t, unsigned char id, int searchable)
- {
- Table *table = (Table *)t;
- if (table)
- table->SetFieldSearchableById(id, !!searchable);
- }
- /* Scanner */
- #ifdef _WIN32
- int NDE_Scanner_Query(nde_scanner_t s, const wchar_t *query)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return scanner->Query(query);
- else
- return 0;
- }
- void NDE_Scanner_Search(nde_scanner_t s, const wchar_t *search_term)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- scanner->Search(search_term);
- }
- const wchar_t *NDE_Scanner_GetLastQuery(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return scanner->GetLastQuery();
- else
- return 0;
- }
- #elif defined(__APPLE__)
- int NDE_Scanner_Query(nde_scanner_t s, const char *query)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return scanner->Query(query);
- else
- return 0;
- }
- CFStringRef NDE_Scanner_GetLastQuery(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return scanner->GetLastQuery();
- else
- return 0;
- }
- #endif
- int NDE_Scanner_GetRecordsCount(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return scanner->GetRecordsCount();
- else
- return 0;
- }
- void NDE_Scanner_New(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- scanner->New();
- }
- void NDE_Scanner_Post(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- scanner->Post();
- }
- void NDE_Scanner_First(nde_scanner_t s, int *killswitch)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- scanner->First(killswitch);
- }
- void NDE_Scanner_Delete(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- scanner->Delete();
- }
- void NDE_Scanner_Edit(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- scanner->Edit();
- }
- int NDE_Scanner_EOF(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return scanner->Eof();
- else
- return 1;
- }
- int NDE_Scanner_BOF(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return scanner->Bof();
- else
- return 1;
- }
- nde_field_t NDE_Scanner_NewFieldByID(nde_scanner_t s, unsigned char id)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return (nde_field_t)scanner->NewFieldById(id, PERM_READWRITE);
- else
- return 0;
- }
- #ifdef _WIN32
- nde_field_t NDE_Scanner_NewFieldByName(nde_scanner_t s, const char *name)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return (nde_field_t)scanner->NewFieldByName(AutoWide(name), PERM_READWRITE);
- else
- return 0;
- }
- #else
- nde_field_t NDE_Scanner_NewFieldByName(nde_scanner_t s, CFStringRef name)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return (nde_field_t)scanner->NewFieldByName(name, PERM_READWRITE);
- else
- return 0;
- }
- #endif
- nde_field_t NDE_Scanner_GetFieldByID(nde_scanner_t s, unsigned char id)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return (nde_field_t)scanner->GetFieldById(id);
- else
- return 0;
- }
- #ifdef _WIN32
- nde_field_t NDE_Scanner_GetFieldByName(nde_scanner_t s, const char *name)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner && name)
- return (nde_field_t)scanner->GetFieldByName(AutoWide(name));
- else
- return 0;
- }
- #else
- nde_field_t NDE_Scanner_GetFieldByName(nde_scanner_t s, CFStringRef name)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner && name)
- return (nde_field_t)scanner->GetFieldByName(name);
- else
- return 0;
- }
- #endif
- void NDE_Scanner_AddFilterByID(nde_scanner_t s, unsigned char id, nde_field_t f, unsigned char filter_operation)
- {
- Scanner *scanner = (Scanner *)s;
- Field *field = (Field *)f;
- if (scanner && field)
- scanner->AddFilterById(id, field, filter_operation);
- }
- int NDE_Scanner_LocateInteger(nde_scanner_t s, unsigned char id, int from, int value, int *nskip, int compare_mode)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- {
- IntegerField field(value);
- return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
- }
- else
- return 0;
- }
- #ifdef _WIN32
- int NDE_Scanner_LocateString(nde_scanner_t s, unsigned char id, int from, const wchar_t *value, int *nskip, int compare_mode)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- {
- StringField field(value);
- return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
- }
- else
- return 0;
- }
- int NDE_Scanner_LocateNDEString(nde_scanner_t s, unsigned char id, int from, wchar_t *value, int *nskip, int compare_mode)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- {
- StringField field(value, STRING_IS_NDESTRING);
- return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
- }
- else
- return 0;
- }
- #endif
- #ifdef _WIN32
- int NDE_Scanner_LocateFilename(nde_scanner_t s, unsigned char id, int from, const wchar_t *value, int *nskip, int compare_mode)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- {
- FilenameField field(value);
- return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
- }
- else
- return 0;
- }
- int NDE_Scanner_LocateNDEFilename(nde_scanner_t s, unsigned char id, int from, wchar_t *value, int *nskip, int compare_mode)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- {
- FilenameField field(value, STRING_IS_NDESTRING);
- return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
- }
- else
- return 0;
- }
- #endif
- int NDE_Scanner_LocateField(nde_scanner_t s, unsigned char id, int from, nde_field_t f, int *nskip, int compare_mode)
- {
- Scanner *scanner = (Scanner *)s;
- Field *field = (Field *)f;
- if (scanner && field)
- {
- return scanner->LocateByIdEx(id, from, field, nskip, compare_mode);
- }
- else
- return 0;
- }
- void NDE_Scanner_DeleteField(nde_scanner_t s, nde_field_t f)
- {
- Scanner *scanner = (Scanner *)s;
- Field *field = (Field *)f;
- if (scanner && field)
- {
- scanner->DeleteField(field);
- }
- }
- void NDE_Scanner_RemoveFilters(nde_scanner_t s)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- scanner->RemoveFilters();
- }
- int NDE_Scanner_Next(nde_scanner_t s, int *killswitch)
- {
- Scanner *scanner = (Scanner *)s;
- if (scanner)
- return scanner->Next(killswitch);
- else
- return 0;
- }
- /* Filter functions */
- unsigned char NDE_Filter_GetID(nde_filter_t f)
- {
- Filter *filter = (Filter *)f;
- if (filter)
- return filter->GetId();
- else
- return FILTERS_INVALID; // right value but I'm not sure if it's the best constant name to use
- }
- NDE_API unsigned char NDE_Filter_GetOp(nde_filter_t f)
- {
- Filter *filter = (Filter *)f;
- if (filter)
- return filter->GetOp();
- else
- return FILTERS_INVALID; // right value but I'm not sure if it's the best constant name to use
- }
- NDE_API nde_field_t NDE_Filter_GetData(nde_filter_t f)
- {
- Filter *filter = (Filter *)f;
- if (filter)
- return (nde_field_t)filter->Data();
- else
- return 0;
- }
- /* Field functions */
- unsigned char NDE_Field_GetType(nde_field_t f)
- {
- Field *field = (Field *)f;
- if (field)
- return field->GetType();
- else
- return FIELD_UNKNOWN;
- }
- unsigned char NDE_Field_GetID(nde_field_t f)
- {
- Field *field = (Field *)f;
- if (field)
- return field->GetFieldId();
- else
- return FIELD_UNKNOWN;
- }
- /* StringField functions */
- #ifdef _WIN32
- void NDE_StringField_SetNDEString(nde_field_t f, wchar_t *nde_string)
- {
- StringField *field = (StringField *)(Field *)f;
- if (field)
- field->SetNDEString(nde_string);
- }
- wchar_t *NDE_StringField_GetString(nde_field_t f)
- {
- StringField *field = (StringField *)(Field *)f;
- if (field)
- return field->GetStringW();
- else
- return 0;
- }
- #ifdef _WIN32
- void NDE_StringField_SetString(nde_field_t f, const wchar_t *str)
- {
- StringField *field = (StringField *)(Field *)f;
- if (field)
- field->SetStringW(str);
- }
- #endif
- #elif defined(__APPLE__)
- void NDE_StringField_SetString(nde_field_t f, CFStringRef nde_string)
- {
- StringField *field = (StringField *)(Field *)f;
- if (field)
- field->SetNDEString(nde_string);
- }
- CFStringRef NDE_StringField_GetString(nde_field_t f)
- {
- StringField *field = (StringField *)(Field *)f;
- if (field)
- return field->GetString();
- else
- return 0;
- }
- #endif
- /* IntegerField functions */
- void NDE_IntegerField_SetValue(nde_field_t f, int value)
- {
- IntegerField *field = (IntegerField *)(Field *)f;
- if (field)
- field->SetValue(value);
- }
- int NDE_IntegerField_GetValue(nde_field_t f)
- {
- IntegerField *field = (IntegerField *)(Field *)f;
- if (field)
- return field->GetValue();
- else
- return 0;
- }
- nde_field_t NDE_IntegerField_Create(int value)
- {
- return (nde_field_t)new IntegerField(value);
- }
- /* BinaryField */
- void *NDE_BinaryField_GetData(nde_field_t f, size_t *length)
- {
- BinaryField *field = (BinaryField *)(Field *)f;
- if (field)
- return (void *)field->GetData(length);
- else
- return 0;
- }
- #ifdef __APPLE__
- CFDataRef NDE_BinaryField_GetCFData(nde_field_t f)
- {
- BinaryField *field = (BinaryField *)(Field *)f;
- if (field)
- return field->GetCFData();
- else
- return 0;
- }
- #endif
- void NDE_BinaryField_SetData(nde_field_t f, const void *data, size_t length)
- {
- BinaryField *field = (BinaryField *)(Field *)f;
- if (field)
- field->SetData((const uint8_t *)data, length);
- }
- /* Int128Field */
- void NDE_Int128Field_SetValue(nde_field_t f, const void *value)
- {
- Int128Field *field = (Int128Field *)(Field *)f;
- if (field && value)
- field->SetValue(value);
- }
- /* ColumnField */
- #ifdef _WIN32
- const wchar_t *NDE_ColumnField_GetFieldName(nde_field_t f)
- {
- ColumnField *field = (ColumnField *)(Field *)f;
- if (field)
- return field->GetFieldName();
- else
- return 0;
- }
- #else
- CFStringRef NDE_ColumnField_GetFieldName(nde_field_t f)
- {
- ColumnField *field = (ColumnField *)(Field *)f;
- if (field)
- return field->GetFieldName();
- else
- return 0;
- }
- #endif
- unsigned char NDE_ColumnField_GetDataType(nde_field_t f)
- {
- ColumnField *field = (ColumnField *)(Field *)f;
- if (field)
- return field->GetDataType();
- else
- return FIELD_UNKNOWN;
- }
- #ifdef _WIN32
- __time64_t NDE_Time_ApplyConversion(__time64_t value, const wchar_t *str, class TimeParse *tp)
- {
- IntegerField f(value);
- f.ApplyConversion(str, tp);
- return f.GetValue();
- }
- #endif
|