nde_c.cpp 12 KB

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