1
0

nde_c.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #pragma once
  2. /* C style API.
  3. We'll eventually deprecate the C++ API as it presents a lot of linking challenges
  4. */
  5. #include "../nde_defines.h"
  6. #include "../NDEString.h"
  7. #include <foundation/types.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef struct nde_database_struct_t { } *nde_database_t;
  12. typedef struct nde_table_struct_t { } *nde_table_t;
  13. typedef struct nde_scanner_t_struct_t { } *nde_scanner_t;
  14. typedef struct nde_field_t_struct_t { } *nde_field_t;
  15. typedef struct nde_filter_struct_t { } *nde_filter_t;
  16. /* Database functions */
  17. NDE_API void NDE_Init();
  18. NDE_API void NDE_Quit();
  19. NDE_API nde_database_t NDE_CreateDatabase();
  20. NDE_API void NDE_DestroyDatabase(nde_database_t db);
  21. NDE_API nde_table_t NDE_Database_OpenTable(nde_database_t db, const char *filename, const char *filename_index, int create, int cache);
  22. NDE_API void NDE_Database_CloseTable(nde_database_t db, nde_table_t table);
  23. /* Table functions */
  24. NDE_API nde_field_t NDE_Table_NewColumn(nde_table_t table, unsigned char id, const char *name, unsigned char type);
  25. NDE_API void NDE_Table_PostColumns(nde_table_t table);
  26. NDE_API void NDE_Table_AddIndexByID(nde_table_t table, unsigned char id, const char *name);
  27. NDE_API nde_scanner_t NDE_Table_CreateScanner(nde_table_t table);
  28. NDE_API void NDE_Table_DestroyScanner(nde_table_t table, nde_scanner_t scanner);
  29. NDE_API void NDE_Table_Sync(nde_table_t table);
  30. #ifdef __cplusplus
  31. NDE_API void NDE_Table_Compact(nde_table_t table, int *progress=0);
  32. #else
  33. NDE_API void NDE_Table_Compact(nde_table_t table, int *progress);
  34. #endif
  35. NDE_API int NDE_Table_GetRecordsCount(nde_table_t table);
  36. NDE_API nde_field_t NDE_Table_GetColumnByID(nde_table_t table, unsigned char id);
  37. NDE_API nde_field_t NDE_Table_GetColumnByName(nde_table_t table, const char *name);
  38. NDE_API void NDE_Table_SetColumnSearchableByID(nde_table_t table, unsigned char id, int searchable);
  39. /* Scanner functions */
  40. NDE_API int NDE_Scanner_Query(nde_scanner_t scanner, const char *query);
  41. NDE_API void NDE_Scanner_Search(nde_scanner_t scanner, const char *search_term);
  42. NDE_API const char *NDE_Scanner_GetLastQuery(nde_scanner_t scanner);
  43. NDE_API int NDE_Scanner_GetRecordsCount(nde_scanner_t scanner);
  44. NDE_API void NDE_Scanner_New(nde_scanner_t scanner);
  45. NDE_API void NDE_Scanner_Post(nde_scanner_t scanner);
  46. #ifdef __cplusplus
  47. NDE_API void NDE_Scanner_First(nde_scanner_t scanner, int *killswitch=0);
  48. NDE_API int NDE_Scanner_Next(nde_scanner_t scanner, int *killswitch=0);
  49. #else
  50. NDE_API void NDE_Scanner_First(nde_scanner_t scanner, int *killswitch);
  51. NDE_API int NDE_Scanner_Next(nde_scanner_t scanner, int *killswitch);
  52. #endif
  53. NDE_API void NDE_Scanner_Delete(nde_scanner_t scanner);
  54. NDE_API void NDE_Scanner_Edit(nde_scanner_t scanner);
  55. NDE_API int NDE_Scanner_EOF(nde_scanner_t scanner);
  56. NDE_API int NDE_Scanner_BOF(nde_scanner_t scanner);
  57. NDE_API nde_field_t NDE_Scanner_NewFieldByID(nde_scanner_t scanner, unsigned char id);
  58. NDE_API nde_field_t NDE_Scanner_NewFieldByName(nde_scanner_t scanner, const char *name);
  59. NDE_API nde_field_t NDE_Scanner_GetFieldByID(nde_scanner_t scanner, unsigned char id);
  60. NDE_API nde_field_t NDE_Scanner_GetFieldByName(nde_scanner_t scanner, const char *name);
  61. NDE_API void NDE_Scanner_AddFilterByID(nde_scanner_t scanner, unsigned char id, nde_field_t field, unsigned char filter_operation);
  62. #ifdef __cplusplus
  63. NDE_API int NDE_Scanner_LocateInteger(nde_scanner_t scanner, unsigned char id, int from, int value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  64. NDE_API int NDE_Scanner_LocateString(nde_scanner_t scanner, unsigned char id, int from, const char *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  65. NDE_API int NDE_Scanner_LocateNDEString(nde_scanner_t scanner, unsigned char id, int from, char *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  66. NDE_API int NDE_Scanner_LocateFilename(nde_scanner_t scanner, unsigned char id, int from, const char *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  67. NDE_API int NDE_Scanner_LocateNDEFilename(nde_scanner_t scanner, unsigned char id, int from, char *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  68. NDE_API int NDE_Scanner_LocateField(nde_scanner_t scanner, unsigned char id, int from, nde_field_t field, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  69. #else
  70. NDE_API int NDE_Scanner_LocateInteger(nde_scanner_t scanner, unsigned char id, int from, int value, int *nskip, int compare_mode);
  71. NDE_API int NDE_Scanner_LocateString(nde_scanner_t scanner, unsigned char id, int from, const char *value, int *nskip, int compare_mode);
  72. NDE_API int NDE_Scanner_LocateNDEString(nde_scanner_t scanner, unsigned char id, int from, char *value, int *nskip, int compare_mode);
  73. NDE_API int NDE_Scanner_LocateFilename(nde_scanner_t scanner, unsigned char id, int from, const char *value, int *nskip, int compare_mode);
  74. NDE_API int NDE_Scanner_LocateNDEFilename(nde_scanner_t scanner, unsigned char id, int from, char *value, int *nskip, int compare_mode);
  75. NDE_API int NDE_Scanner_LocateField(nde_scanner_t scanner, unsigned char id, int from, nde_field_t field, int *nskip, int compare_mode);
  76. #endif
  77. NDE_API void NDE_Scanner_DeleteField(nde_scanner_t scanner, nde_field_t field);
  78. NDE_API void NDE_Scanner_RemoveFilters(nde_scanner_t scanner);
  79. /* Filter functions */
  80. NDE_API unsigned char NDE_Filter_GetID(nde_filter_t filter);
  81. NDE_API unsigned char NDE_Filter_GetOp(nde_filter_t filter);
  82. NDE_API nde_field_t NDE_Filter_GetData(nde_filter_t filter);
  83. /* Field functions */
  84. NDE_API unsigned char NDE_Field_GetType(nde_field_t field);
  85. NDE_API unsigned char NDE_Field_GetID(nde_field_t field);
  86. /* String Field functions */
  87. NDE_API char *NDE_StringField_GetString(nde_field_t field); /* returns non-const because it's an NDE string (reference counted, see ndestring.h) */
  88. NDE_API void NDE_StringField_SetNDEString(nde_field_t field, char *nde_string);
  89. NDE_API void NDE_StringField_SetString(nde_field_t field, const char *str);
  90. /* IntegerField functions */
  91. NDE_API void NDE_IntegerField_SetValue(nde_field_t field, int value);
  92. NDE_API int NDE_IntegerField_GetValue(nde_field_t field);
  93. NDE_API nde_field_t NDE_IntegerField_Create(int value); /* mainly used for NDE_Scanner_AddFilterByID */
  94. /* BinaryField functions */
  95. // on windows, the data pointer is optionally reference counted via ndestring (ndestring_retain if you plan on keeping it)
  96. NDE_API void *NDE_BinaryField_GetData(nde_field_t field, size_t *length);
  97. NDE_API void NDE_BinaryField_SetData(nde_field_t field, const void *data, size_t length);
  98. /* Int128Field functions */
  99. NDE_API void NDE_Int128Field_SetValue(nde_field_t field, const void *value);
  100. /* ColumnField functions */
  101. NDE_API const char *NDE_ColumnField_GetFieldName(nde_field_t field);
  102. NDE_API unsigned char NDE_ColumnField_GetDataType(nde_field_t field);
  103. #ifdef __cplusplus
  104. }
  105. #endif