1
0

nde_c.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. #include "nde_c.h"
  2. #include "../nde.h"
  3. /* Database */
  4. nde_database_t NDE_CreateDatabase()
  5. {
  6. return (nde_database_t)new Database();
  7. }
  8. void NDE_DestroyDatabase(nde_database_t db)
  9. {
  10. delete (Database *)db;
  11. }
  12. nde_table_t NDE_Database_OpenTable(nde_database_t db, const char *filename, const char *indexname, int create, int cache)
  13. {
  14. Database *database = (Database *)db;
  15. if (database && filename)
  16. return (nde_table_t)database->OpenTable(filename, indexname, (BOOL)create, (BOOL)cache);
  17. else
  18. return 0;
  19. }
  20. void NDE_Database_CloseTable(nde_database_t db, nde_table_t t)
  21. {
  22. Database *database = (Database *)db;
  23. Table *table = (Table *)t;
  24. if (database && table)
  25. {
  26. database->CloseTable(table);
  27. }
  28. }
  29. /* Table */
  30. nde_field_t NDE_Table_NewColumn(nde_table_t t, unsigned char id, const char *name, unsigned char type)
  31. {
  32. Table *table = (Table *)t;
  33. if (table)
  34. return (nde_field_t)table->NewColumn(id, name, type, FALSE);
  35. else
  36. return 0;
  37. }
  38. void NDE_Table_PostColumns(nde_table_t t)
  39. {
  40. Table *table = (Table *)t;
  41. if (table)
  42. table->PostColumns();
  43. }
  44. void NDE_Table_AddIndexByID(nde_table_t t, unsigned char id, const char *name)
  45. {
  46. Table *table = (Table *)t;
  47. if (table)
  48. table->AddIndexById(id, name);
  49. }
  50. nde_scanner_t NDE_Table_CreateScanner(nde_table_t t)
  51. {
  52. Table *table = (Table *)t;
  53. if (table)
  54. return (nde_scanner_t)table->NewScanner();
  55. else
  56. return 0;
  57. }
  58. void NDE_Table_DestroyScanner(nde_table_t t, nde_scanner_t s)
  59. {
  60. Table *table = (Table *)t;
  61. Scanner *scanner = (Scanner *)s;
  62. if (table && scanner)
  63. table->DeleteScanner(scanner);
  64. }
  65. void NDE_Table_Sync(nde_table_t t)
  66. {
  67. Table *table = (Table *)t;
  68. if (table)
  69. table->Sync();
  70. }
  71. int NDE_Table_GetRecordsCount(nde_table_t t)
  72. {
  73. Table *table = (Table *)t;
  74. if (table)
  75. return table->GetRecordsCount();
  76. else
  77. return 0;
  78. }
  79. nde_field_t NDE_Table_GetColumnByID(nde_table_t t, unsigned char id)
  80. {
  81. Table *table = (Table *)t;
  82. if (table)
  83. return (nde_field_t)table->GetColumnById(id);
  84. else
  85. return 0;
  86. }
  87. nde_field_t NDE_Table_GetColumnByName(nde_table_t t, const char *name)
  88. {
  89. Table *table = (Table *)t;
  90. if (table && name)
  91. return (nde_field_t)table->GetColumnByName(name);
  92. else
  93. return 0;
  94. }
  95. void NDE_Table_SetColumnSearchableByID(nde_table_t t, unsigned char id, int searchable)
  96. {
  97. Table *table = (Table *)t;
  98. if (table)
  99. table->SetFieldSearchableById(id, !!searchable);
  100. }
  101. /* Scanner */
  102. int NDE_Scanner_Query(nde_scanner_t s, const char *query)
  103. {
  104. Scanner *scanner = (Scanner *)s;
  105. if (scanner)
  106. return scanner->Query(query);
  107. else
  108. return 0;
  109. }
  110. void NDE_Scanner_Search(nde_scanner_t s, const char *search_term)
  111. {
  112. Scanner *scanner = (Scanner *)s;
  113. if (scanner)
  114. scanner->Search(search_term);
  115. }
  116. const char *NDE_Scanner_GetLastQuery(nde_scanner_t s)
  117. {
  118. Scanner *scanner = (Scanner *)s;
  119. if (scanner)
  120. return scanner->GetLastQuery();
  121. else
  122. return 0;
  123. }
  124. int NDE_Scanner_GetRecordsCount(nde_scanner_t s)
  125. {
  126. Scanner *scanner = (Scanner *)s;
  127. if (scanner)
  128. return scanner->GetRecordsCount();
  129. else
  130. return 0;
  131. }
  132. void NDE_Scanner_New(nde_scanner_t s)
  133. {
  134. Scanner *scanner = (Scanner *)s;
  135. if (scanner)
  136. scanner->New();
  137. }
  138. void NDE_Scanner_Post(nde_scanner_t s)
  139. {
  140. Scanner *scanner = (Scanner *)s;
  141. if (scanner)
  142. scanner->Post();
  143. }
  144. void NDE_Scanner_First(nde_scanner_t s, int *killswitch)
  145. {
  146. Scanner *scanner = (Scanner *)s;
  147. if (scanner)
  148. scanner->First(killswitch);
  149. }
  150. void NDE_Scanner_Delete(nde_scanner_t s)
  151. {
  152. Scanner *scanner = (Scanner *)s;
  153. if (scanner)
  154. scanner->Delete();
  155. }
  156. void NDE_Scanner_Edit(nde_scanner_t s)
  157. {
  158. Scanner *scanner = (Scanner *)s;
  159. if (scanner)
  160. scanner->Edit();
  161. }
  162. int NDE_Scanner_EOF(nde_scanner_t s)
  163. {
  164. Scanner *scanner = (Scanner *)s;
  165. if (scanner)
  166. return scanner->Eof();
  167. else
  168. return 1;
  169. }
  170. int NDE_Scanner_BOF(nde_scanner_t s)
  171. {
  172. Scanner *scanner = (Scanner *)s;
  173. if (scanner)
  174. return scanner->Bof();
  175. else
  176. return 1;
  177. }
  178. nde_field_t NDE_Scanner_NewFieldByID(nde_scanner_t s, unsigned char id)
  179. {
  180. Scanner *scanner = (Scanner *)s;
  181. if (scanner)
  182. return (nde_field_t)scanner->NewFieldById(id, PERM_READWRITE);
  183. else
  184. return 0;
  185. }
  186. nde_field_t NDE_Scanner_NewFieldByName(nde_scanner_t s, const char *name)
  187. {
  188. Scanner *scanner = (Scanner *)s;
  189. if (scanner)
  190. return (nde_field_t)scanner->NewFieldByName(name, PERM_READWRITE);
  191. else
  192. return 0;
  193. }
  194. nde_field_t NDE_Scanner_GetFieldByID(nde_scanner_t s, unsigned char id)
  195. {
  196. Scanner *scanner = (Scanner *)s;
  197. if (scanner)
  198. return (nde_field_t)scanner->GetFieldById(id);
  199. else
  200. return 0;
  201. }
  202. nde_field_t NDE_Scanner_GetFieldByName(nde_scanner_t s, const char *name)
  203. {
  204. Scanner *scanner = (Scanner *)s;
  205. if (scanner && name)
  206. return (nde_field_t)scanner->GetFieldByName(name);
  207. else
  208. return 0;
  209. }
  210. void NDE_Scanner_AddFilterByID(nde_scanner_t s, unsigned char id, nde_field_t f, unsigned char filter_operation)
  211. {
  212. Scanner *scanner = (Scanner *)s;
  213. Field *field = (Field *)f;
  214. if (scanner && field)
  215. scanner->AddFilterById(id, field, filter_operation);
  216. }
  217. int NDE_Scanner_LocateInteger(nde_scanner_t s, unsigned char id, int from, int value, int *nskip, int compare_mode)
  218. {
  219. Scanner *scanner = (Scanner *)s;
  220. if (scanner)
  221. {
  222. IntegerField field(value);
  223. return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
  224. }
  225. else
  226. return 0;
  227. }
  228. int NDE_Scanner_LocateString(nde_scanner_t s, unsigned char id, int from, const char *value, int *nskip, int compare_mode)
  229. {
  230. Scanner *scanner = (Scanner *)s;
  231. if (scanner)
  232. {
  233. StringField field(value);
  234. return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
  235. }
  236. else
  237. return 0;
  238. }
  239. int NDE_Scanner_LocateNDEString(nde_scanner_t s, unsigned char id, int from, char *value, int *nskip, int compare_mode)
  240. {
  241. Scanner *scanner = (Scanner *)s;
  242. if (scanner)
  243. {
  244. StringField field(value, STRING_IS_NDESTRING);
  245. return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
  246. }
  247. else
  248. return 0;
  249. }
  250. int NDE_Scanner_LocateFilename(nde_scanner_t s, unsigned char id, int from, const char *value, int *nskip, int compare_mode)
  251. {
  252. Scanner *scanner = (Scanner *)s;
  253. if (scanner)
  254. {
  255. FilenameField field(value);
  256. return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
  257. }
  258. else
  259. return 0;
  260. }
  261. int NDE_Scanner_LocateNDEFilename(nde_scanner_t s, unsigned char id, int from, char *value, int *nskip, int compare_mode)
  262. {
  263. Scanner *scanner = (Scanner *)s;
  264. if (scanner)
  265. {
  266. FilenameField field(value, STRING_IS_NDESTRING);
  267. return scanner->LocateByIdEx(id, from, &field, nskip, compare_mode);
  268. }
  269. else
  270. return 0;
  271. }
  272. int NDE_Scanner_LocateField(nde_scanner_t s, unsigned char id, int from, nde_field_t f, int *nskip, int compare_mode)
  273. {
  274. Scanner *scanner = (Scanner *)s;
  275. Field *field = (Field *)f;
  276. if (scanner && field)
  277. {
  278. return scanner->LocateByIdEx(id, from, field, nskip, compare_mode);
  279. }
  280. else
  281. return 0;
  282. }
  283. void NDE_Scanner_DeleteField(nde_scanner_t s, nde_field_t f)
  284. {
  285. Scanner *scanner = (Scanner *)s;
  286. Field *field = (Field *)f;
  287. if (scanner && field)
  288. {
  289. scanner->DeleteField(field);
  290. }
  291. }
  292. void NDE_Scanner_RemoveFilters(nde_scanner_t s)
  293. {
  294. Scanner *scanner = (Scanner *)s;
  295. if (scanner)
  296. scanner->RemoveFilters();
  297. }
  298. int NDE_Scanner_Next(nde_scanner_t s, int *killswitch)
  299. {
  300. Scanner *scanner = (Scanner *)s;
  301. if (scanner)
  302. return scanner->Next(killswitch);
  303. else
  304. return 0;
  305. }
  306. /* Filter functions */
  307. unsigned char NDE_Filter_GetID(nde_filter_t f)
  308. {
  309. Filter *filter = (Filter *)f;
  310. if (filter)
  311. return filter->GetId();
  312. else
  313. return FILTERS_INVALID; // right value but I'm not sure if it's the best constant name to use
  314. }
  315. NDE_API unsigned char NDE_Filter_GetOp(nde_filter_t f)
  316. {
  317. Filter *filter = (Filter *)f;
  318. if (filter)
  319. return filter->GetOp();
  320. else
  321. return FILTERS_INVALID; // right value but I'm not sure if it's the best constant name to use
  322. }
  323. NDE_API nde_field_t NDE_Filter_GetData(nde_filter_t f)
  324. {
  325. Filter *filter = (Filter *)f;
  326. if (filter)
  327. return (nde_field_t)filter->Data();
  328. else
  329. return 0;
  330. }
  331. /* Field functions */
  332. unsigned char NDE_Field_GetType(nde_field_t f)
  333. {
  334. Field *field = (Field *)f;
  335. if (field)
  336. return field->GetType();
  337. else
  338. return FIELD_UNKNOWN;
  339. }
  340. unsigned char NDE_Field_GetID(nde_field_t f)
  341. {
  342. Field *field = (Field *)f;
  343. if (field)
  344. return field->GetFieldId();
  345. else
  346. return FIELD_UNKNOWN;
  347. }
  348. /* StringField functions */
  349. void NDE_StringField_SetNDEString(nde_field_t f, char *nde_string)
  350. {
  351. StringField *field = (StringField *)(Field *)f;
  352. if (field)
  353. field->SetNDEString(nde_string);
  354. }
  355. char *NDE_StringField_GetString(nde_field_t f)
  356. {
  357. StringField *field = (StringField *)(Field *)f;
  358. if (field)
  359. return field->GetString();
  360. else
  361. return 0;
  362. }
  363. void NDE_StringField_SetString(nde_field_t f, const char *str)
  364. {
  365. StringField *field = (StringField *)(Field *)f;
  366. if (field)
  367. field->SetString(str);
  368. }
  369. /* IntegerField functions */
  370. void NDE_IntegerField_SetValue(nde_field_t f, int value)
  371. {
  372. IntegerField *field = (IntegerField *)(Field *)f;
  373. if (field)
  374. field->SetValue(value);
  375. }
  376. int NDE_IntegerField_GetValue(nde_field_t f)
  377. {
  378. IntegerField *field = (IntegerField *)(Field *)f;
  379. if (field)
  380. return field->GetValue();
  381. else
  382. return 0;
  383. }
  384. nde_field_t NDE_IntegerField_Create(int value)
  385. {
  386. return (nde_field_t)new IntegerField(value);
  387. }
  388. /* BinaryField */
  389. void *NDE_BinaryField_GetData(nde_field_t f, size_t *length)
  390. {
  391. BinaryField *field = (BinaryField *)(Field *)f;
  392. if (field)
  393. return (void *)field->GetData(length);
  394. else
  395. return 0;
  396. }
  397. void NDE_BinaryField_SetData(nde_field_t f, const void *data, size_t length)
  398. {
  399. BinaryField *field = (BinaryField *)(Field *)f;
  400. if (field)
  401. field->SetData((const uint8_t *)data, length);
  402. }
  403. /* Int128Field */
  404. void NDE_Int128Field_SetValue(nde_field_t f, const void *value)
  405. {
  406. Int128Field *field = (Int128Field *)(Field *)f;
  407. if (field && value)
  408. field->SetValue(value);
  409. }
  410. /* ColumnField */
  411. const char *NDE_ColumnField_GetFieldName(nde_field_t f)
  412. {
  413. ColumnField *field = (ColumnField *)(Field *)f;
  414. if (field)
  415. return field->GetFieldName();
  416. else
  417. return 0;
  418. }
  419. unsigned char NDE_ColumnField_GetDataType(nde_field_t f)
  420. {
  421. ColumnField *field = (ColumnField *)(Field *)f;
  422. if (field)
  423. return field->GetDataType();
  424. else
  425. return FIELD_UNKNOWN;
  426. }