zsv 1.3.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +41 -3
  4. data/ext/zsv/extconf.rb +1 -1
  5. data/lib/zsv/version.rb +1 -1
  6. metadata +6 -226
  7. data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +0 -756
  8. data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +0 -381
  9. data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +0 -228
  10. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +0 -123
  11. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +0 -39
  12. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +0 -104
  13. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +0 -41
  14. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +0 -1
  15. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +0 -14
  16. data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +0 -19
  17. data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +0 -116
  18. data/ext/zsv/vendor/zsv-1.3.0/app/check.c +0 -194
  19. data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +0 -796
  20. data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +0 -41
  21. data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +0 -16
  22. data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +0 -280
  23. data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +0 -36
  24. data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +0 -913
  25. data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +0 -23
  26. data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +0 -20
  27. data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +0 -140
  28. data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +0 -91
  29. data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +0 -81
  30. data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +0 -82
  31. data/ext/zsv/vendor/zsv-1.3.0/app/count.c +0 -404
  32. data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +0 -569
  33. data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +0 -365
  34. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +0 -366
  35. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +0 -341
  36. data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +0 -263
  37. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +0 -298
  38. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +0 -157
  39. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +0 -177
  40. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +0 -444
  41. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +0 -145
  42. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +0 -110
  43. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +0 -15
  44. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +0 -64
  45. data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +0 -1955
  46. data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +0 -6802
  47. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +0 -230517
  48. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +0 -12174
  49. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +0 -2
  50. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +0 -142
  51. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +0 -49
  52. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +0 -485
  53. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +0 -1015
  54. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +0 -663
  55. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +0 -85
  56. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +0 -75
  57. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +0 -167
  58. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +0 -228
  59. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +0 -186
  60. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +0 -23
  61. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +0 -76
  62. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +0 -167
  63. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +0 -238
  64. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +0 -186
  65. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +0 -184
  66. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +0 -52
  67. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +0 -34
  68. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +0 -103
  69. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +0 -57
  70. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +0 -69
  71. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +0 -220
  72. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +0 -34
  73. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +0 -362
  74. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +0 -764
  75. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +0 -117
  76. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +0 -508
  77. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +0 -78
  78. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +0 -505
  79. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +0 -7
  80. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +0 -59
  81. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +0 -208
  82. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +0 -795
  83. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +0 -28
  84. data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +0 -851
  85. data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +0 -106
  86. data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +0 -6
  87. data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +0 -113
  88. data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +0 -90
  89. data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +0 -295
  90. data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +0 -175
  91. data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +0 -693
  92. data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +0 -980
  93. data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +0 -131
  94. data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +0 -130
  95. data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +0 -118
  96. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +0 -45
  97. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +0 -41
  98. data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +0 -107
  99. data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +0 -20
  100. data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +0 -61
  101. data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +0 -14
  102. data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +0 -192
  103. data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +0 -72
  104. data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +0 -812
  105. data/ext/zsv/vendor/zsv-1.3.0/app/select.c +0 -753
  106. data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +0 -372
  107. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +0 -15
  108. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +0 -119
  109. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +0 -45
  110. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +0 -63
  111. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +0 -12
  112. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +0 -166
  113. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +0 -214
  114. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +0 -128
  115. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +0 -43
  116. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +0 -81
  117. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +0 -25
  118. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +0 -325
  119. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +0 -73
  120. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +0 -203
  121. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +0 -7
  122. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +0 -318
  123. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +0 -134
  124. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +0 -119
  125. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +0 -322
  126. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +0 -203
  127. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +0 -36
  128. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +0 -167
  129. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +0 -36
  130. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +0 -153
  131. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +0 -32
  132. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +0 -312
  133. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +0 -29
  134. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +0 -266
  135. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +0 -9
  136. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +0 -60
  137. data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +0 -1007
  138. data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +0 -453
  139. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +0 -101
  140. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +0 -49
  141. data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +0 -393
  142. data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +0 -322
  143. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +0 -228
  144. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +0 -91
  145. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +0 -240
  146. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +0 -63
  147. data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +0 -57
  148. data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +0 -148
  149. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +0 -2
  150. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +0 -427
  151. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +0 -253
  152. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +0 -121
  153. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +0 -20
  154. data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +0 -159
  155. data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +0 -24
  156. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +0 -180
  157. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +0 -256
  158. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +0 -197
  159. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +0 -49
  160. data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +0 -400
  161. data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +0 -120
  162. data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +0 -18
  163. data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +0 -132
  164. data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +0 -178
  165. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +0 -258
  166. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +0 -246
  167. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +0 -123
  168. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +0 -153
  169. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +0 -54
  170. data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +0 -267
  171. data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +0 -53
  172. data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +0 -357
  173. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +0 -83
  174. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +0 -33
  175. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +0 -184
  176. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +0 -292
  177. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +0 -259
  178. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +0 -13
  179. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +0 -255
  180. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +0 -96
  181. data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +0 -361
  182. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +0 -40
  183. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +0 -16
  184. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +0 -44
  185. data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +0 -3
  186. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +0 -100
  187. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +0 -143
  188. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +0 -89
  189. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +0 -123
  190. data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +0 -16
  191. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/api.h +0 -336
  192. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/common.h +0 -361
  193. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation.h +0 -62
  194. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation_private.h +0 -113
  195. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/sheet.h +0 -73
  196. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext.h +0 -329
  197. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/arg.h +0 -90
  198. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/cache.h +0 -49
  199. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/clock.h +0 -36
  200. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/compiler.h +0 -58
  201. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/db.h +0 -19
  202. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dirs.h +0 -147
  203. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dl.h +0 -22
  204. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/emcc/fs_api.h +0 -28
  205. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/err.h +0 -22
  206. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file-mem.h +0 -17
  207. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file.h +0 -99
  208. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/jq.h +0 -65
  209. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/json.h +0 -19
  210. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/mem.h +0 -19
  211. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/memmem.h +0 -13
  212. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +0 -54
  213. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite.h +0 -71
  214. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite_writer.h +0 -53
  215. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/prop.h +0 -107
  216. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/signal.h +0 -18
  217. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +0 -11
  218. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/string.h +0 -148
  219. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/utf8.h +0 -41
  220. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/win/dl.h +0 -25
  221. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/writer.h +0 -101
  222. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/zsv_export.h +0 -33
  223. data/ext/zsv/vendor/zsv-1.3.0/include/zsv.h +0 -20
  224. data/ext/zsv/vendor/zsv-1.3.0/src/vector_delim.c +0 -60
  225. data/ext/zsv/vendor/zsv-1.3.0/src/zsv.c +0 -484
  226. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_internal.c +0 -731
  227. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_delim.c +0 -285
  228. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_fixed.c +0 -88
  229. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +0 -51
@@ -1,453 +0,0 @@
1
- /*
2
- * Copyright (C) 2021 Liquidaty and zsv contributors. All rights reserved.
3
- *
4
- * This file is part of zsv/lib, distributed under the MIT license as defined at
5
- * https://opensource.org/licenses/MIT
6
- */
7
-
8
- #include <stdlib.h>
9
- #include <stdio.h>
10
- #include <string.h>
11
- #include <sys/stat.h>
12
- // #include <sqlite3.h>
13
- #include "external/sqlite3/sqlite3.h"
14
- #include "external/sqlite3/sqlite3_csv_vtab-mem.h"
15
-
16
- #define ZSV_COMMAND sql
17
- #include "zsv_command.h"
18
-
19
- #include <zsv/utils/writer.h>
20
- #include <zsv/utils/file.h>
21
- #include <zsv/utils/string.h>
22
- #include <zsv/utils/sql.h>
23
- #include "sql_internal.h"
24
-
25
- #include <unistd.h> // unlink
26
-
27
- #ifndef STRING_LIST
28
- #define STRING_LIST
29
- struct string_list {
30
- struct string_list *next;
31
- char *value;
32
- };
33
- #endif
34
-
35
- const char *zsv_sql_usage_msg[] = {
36
- APPNAME ": run ad hoc sql on a CSV file",
37
- " or join multiple CSV files on one or more common column(s)",
38
- "",
39
- #ifdef NO_STDIN
40
- "Usage: " APPNAME " <filename> [filename ...] <sql | @file.sql>",
41
- #else
42
- "Usage: " APPNAME " [filename, or - for stdin] [filename ...] <sql | @file.sql | --join-indexes <N,...>>",
43
- #endif
44
- " e.g. " APPNAME " file.csv \"select * from data\"",
45
- " e.g. " APPNAME " file1.csv file2.csv \"select * from data inner join data2\"",
46
- " e.g. " APPNAME " file1.csv file2.csv --join-indexes 1,2",
47
- "",
48
- "Loads your CSV file into a table named 'data', then runs your sql, which must start with 'select '.",
49
- "If multiple files are specified, tables will be named data, data2, data3, ...",
50
- "",
51
- "Options:",
52
- " --join-indexes <n1...>: specify one or more column names to join multiple files by",
53
- " each n is treated as an index in the first input file that determines a column",
54
- " of the join. For example, if joining two files that, respectively, have columns",
55
- " A,B,C,D and X,B,C,A,Y then `--join-indexes 1,3` will join on columns A and C.",
56
- " When using this option, do not include an sql statement",
57
- " -b : output with BOM",
58
- " -C,--max-cols <n> : change the maximum allowable columns. must be > 0 and < 2000",
59
- " -o <filename> : filename to save output to",
60
- " --memory : use in-memory instead of temporary db (see https://www.sqlite.org/inmemorydb.html)",
61
- NULL,
62
- };
63
-
64
- static int zsv_sql_usage(FILE *f) {
65
- for (size_t i = 0; zsv_sql_usage_msg[i]; i++)
66
- fprintf(f, "%s\n", zsv_sql_usage_msg[i]);
67
- return f == stderr ? 1 : 0;
68
- }
69
-
70
- struct zsv_sql_data {
71
- FILE *in;
72
- const char *input_filename;
73
- struct string_list *more_input_filenames;
74
- char *sql_dynamic; // will hold contents of sql file, if any
75
- char *join_indexes; // will hold contents of join_indexes arg, prefixed and suffixed with a comma
76
- struct string_list *join_column_names;
77
- unsigned char in_memory : 1;
78
- unsigned char _ : 7;
79
- };
80
-
81
- static void zsv_sql_finalize(struct zsv_sql_data *data) {
82
- (void)data;
83
- }
84
-
85
- static void zsv_sql_cleanup(struct zsv_sql_data *data) {
86
- if (data->in && data->in != stdin)
87
- fclose(data->in);
88
- free(data->sql_dynamic);
89
- free(data->join_indexes);
90
- if (data->join_column_names) {
91
- struct string_list *next;
92
- for (struct string_list *tmp = data->join_column_names; tmp; tmp = next) {
93
- next = tmp->next;
94
- free(tmp->value);
95
- free(tmp);
96
- }
97
- }
98
-
99
- if (data->more_input_filenames) {
100
- struct string_list *next;
101
- for (struct string_list *tmp = data->more_input_filenames; tmp; tmp = next) {
102
- next = tmp->next;
103
- free(tmp);
104
- }
105
- }
106
- (void)data;
107
- }
108
-
109
- static char is_select_sql(const char *s) {
110
- return strlen(s) > strlen("select ") && !zsv_strincmp((const unsigned char *)"select ", strlen("select "),
111
- (const unsigned char *)s, strlen("select "));
112
- }
113
-
114
- int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *opts,
115
- struct zsv_prop_handler *custom_prop_handler) {
116
- /**
117
- * We need to pass the following data to the sqlite3 virtual table code:
118
- * a. zsv parser options indicated in the cmd line
119
- * b. input file path
120
- * c. cmd-line options used in (a), so that we can print warnings in case of
121
- * conflict between (a) and properties of (b)
122
- */
123
- int err = 0;
124
- if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
125
- err = zsv_sql_usage(argc < 2 ? stderr : stdout);
126
- else {
127
- struct zsv_sql_data data = {0};
128
- const char *my_sql = NULL;
129
- struct string_list **next_input_filename = &data.more_input_filenames;
130
-
131
- struct zsv_csv_writer_options writer_opts = zsv_writer_get_default_opts();
132
- for (int arg_i = 1; !err && arg_i < argc; arg_i++) {
133
- const char *arg = argv[arg_i];
134
- if (!strcmp(arg, "--join-indexes")) {
135
- if (data.join_indexes) {
136
- fprintf(stderr, "%s specified more than once\n", arg);
137
- err = 1;
138
- } else if (!(++arg_i < argc)) {
139
- fprintf(stderr, "%s option requires a value\n", arg);
140
- err = 1;
141
- } else {
142
- arg = argv[arg_i];
143
- int have = 0;
144
- for (const char *s = arg; *s; s++) {
145
- if (*s == ',')
146
- ;
147
- else if ((*s >= '0' && *s <= '9'))
148
- have = 1;
149
- else
150
- err = 1;
151
- }
152
- if (!have || err)
153
- fprintf(stderr,
154
- "Invalid --join-indexes value (%s): must be a comma-separated"
155
- " list of indexes with no spaces or other characters\n",
156
- arg),
157
- err = 1;
158
- else {
159
- asprintf(&data.join_indexes, ",%s,", arg);
160
- if (data.join_indexes && strstr(data.join_indexes, ",0,"))
161
- fprintf(stderr, "--join-indexes index values must be greater than zero\n"), err = 1;
162
- }
163
- }
164
- } else if (!my_sql && ((*arg == '@' && arg[1]) || is_select_sql(arg))) {
165
- if (is_select_sql(arg))
166
- my_sql = arg;
167
- else {
168
- struct stat st;
169
- if (stat(arg + 1, &st) == 0 && st.st_size > 0) {
170
- FILE *f = fopen(arg + 1, "rb");
171
- if (f) {
172
- data.sql_dynamic = malloc(st.st_size + 1);
173
- if (data.sql_dynamic) {
174
- fread(data.sql_dynamic, 1, st.st_size, f);
175
- data.sql_dynamic[st.st_size] = '\0';
176
- if (is_select_sql(data.sql_dynamic))
177
- my_sql = (const char *)data.sql_dynamic;
178
- else {
179
- fprintf(stderr, "File %s contents must be a sql SELECT statement\n", arg + 1);
180
- err = 1;
181
- }
182
- }
183
- fclose(f);
184
- }
185
- }
186
- if (!data.sql_dynamic && !err) {
187
- fprintf(stderr, "File %s empty or not readable\n", arg + 1);
188
- err = 1;
189
- }
190
- }
191
- } else if (!strcmp(arg, "-o") || !strcmp(arg, "--output"))
192
- writer_opts.output_path = zsv_next_arg(++arg_i, argc, argv, &err);
193
- else if (!strcmp(arg, "--memory"))
194
- data.in_memory = 1;
195
- else if (!strcmp(arg, "-b"))
196
- writer_opts.with_bom = 1;
197
- else if (*arg != '-') {
198
- if (!data.input_filename) {
199
- data.input_filename = arg;
200
- if (!(data.in = fopen(arg, "rb"))) {
201
- fprintf(stderr, "Unable to open for reading: %s\n", arg);
202
- err = 1;
203
- }
204
- } else { // another input file
205
- FILE *tmp_f;
206
- if (!(tmp_f = fopen(arg, "rb"))) {
207
- fprintf(stderr, "Unable to open %s for reading\n", arg);
208
- err = 1;
209
- } else {
210
- fclose(tmp_f);
211
- struct string_list *tmp = calloc(1, sizeof(**next_input_filename));
212
- if (!tmp)
213
- fprintf(stderr, "Out of memory!\n");
214
- else {
215
- tmp->value = (char *)arg;
216
- *next_input_filename = tmp;
217
- next_input_filename = &tmp->next;
218
- }
219
- }
220
- }
221
- } else {
222
- err = 1;
223
- fprintf(stderr, "Unrecognized option: %s\n", arg);
224
- }
225
- }
226
-
227
- if (!data.in || !data.input_filename) {
228
- #ifdef NO_STDIN
229
- fprintf(stderr, "Please specify an input file\n");
230
- err = 1;
231
- #else
232
- data.in = stdin;
233
- #endif
234
- }
235
-
236
- if (!my_sql && !data.join_indexes) {
237
- fprintf(stderr, "No sql command specified\n");
238
- err = 1;
239
- }
240
-
241
- if (err) {
242
- zsv_sql_cleanup(&data);
243
- return 1;
244
- }
245
-
246
- if (data.in != stdin) {
247
- fclose(data.in);
248
- data.in = NULL;
249
- }
250
-
251
- FILE *f = NULL;
252
- char *tmpfn = NULL;
253
- if (data.input_filename) {
254
- f = fopen(data.input_filename, "rb");
255
- if (!f)
256
- fprintf(stderr, "Unable to open %s for reading\n", data.input_filename);
257
- } else
258
- f = stdin;
259
-
260
- if (f == stdin) {
261
- tmpfn = zsv_get_temp_filename("zsv_sql_XXXXXXXX");
262
- if (!tmpfn) {
263
- fprintf(stderr, "Unable to create temp file name\n");
264
- } else {
265
- FILE *tmpf = fopen(tmpfn, "wb");
266
- if (!tmpf)
267
- fprintf(stderr, "Unable to open temp file %s\n", tmpfn);
268
- else {
269
- char rbuff[1024];
270
- size_t bytes_read;
271
- while ((bytes_read = fread(rbuff, 1, sizeof(rbuff), stdin)))
272
- fwrite(rbuff, 1, bytes_read, tmpf);
273
- f = tmpf;
274
- }
275
- }
276
- }
277
-
278
- zsv_csv_writer cw = zsv_writer_new(&writer_opts);
279
- if (f && cw) {
280
- fclose(f); // to do: don't open in the first place
281
- f = NULL;
282
-
283
- unsigned char cw_buff[1024];
284
- zsv_writer_set_temp_buff(cw, cw_buff, sizeof(cw_buff));
285
-
286
- struct zsv_sqlite3_dbopts dbopts = {
287
- .in_memory = data.in_memory,
288
- };
289
- struct zsv_sqlite3_db *zdb = zsv_sqlite3_db_new(&dbopts);
290
- if (zdb && zdb->rc == SQLITE_OK) {
291
- const char *csv_filename = tmpfn ? (const char *)tmpfn : data.input_filename;
292
-
293
- // for simplicity, we assume the same opts and custom_prop_handler for every input
294
- // it may be desirable later to make this customizable for each input
295
- if (zsv_sqlite3_add_csv(zdb, csv_filename, opts, custom_prop_handler) == SQLITE_OK) {
296
- for (struct string_list *sl = data.more_input_filenames; sl; sl = sl->next)
297
- if (zsv_sqlite3_add_csv(zdb, sl->value, opts, custom_prop_handler) != SQLITE_OK)
298
- break;
299
- }
300
-
301
- if (zdb->rc == SQLITE_OK && data.join_indexes) { // get column names, and construct the sql
302
- // sql template:
303
- // select t1.*, t2.*, t3.* from t1 left join (select * from t2 group by a) t2 left join (select * from t3
304
- // group by a) t3 using(a);
305
- sqlite3_stmt *stmt = NULL;
306
- const char *prefix_search = NULL;
307
- const char *prefix_end = NULL;
308
- if (my_sql) {
309
- prefix_search = " from data ";
310
- prefix_end = strstr(my_sql, prefix_search);
311
- if (!prefix_end) {
312
- prefix_search = " from data";
313
- prefix_end = strstr(my_sql, prefix_search);
314
- if (prefix_end && (prefix_end + strlen(prefix_search) != my_sql + strlen(my_sql)))
315
- prefix_end = NULL;
316
- }
317
- if (!prefix_end || !prefix_search) {
318
- err = 1;
319
- fprintf(stderr, "Invalid sql: must contain 'from data'");
320
- }
321
- }
322
-
323
- if (!err) {
324
- zdb->rc = sqlite3_prepare_v2(zdb->db, "select * from data", -1, &stmt, NULL);
325
- if (zdb->rc != SQLITE_OK) {
326
- fprintf(stderr, "%s:\n %s\n (or bad CSV/utf8 input)\n\n", sqlite3_errstr(err), "select * from data");
327
- err = 1;
328
- }
329
- }
330
- if (!err && stmt) {
331
- struct string_list **next_joined_column_name = &data.join_column_names;
332
- int col_count = sqlite3_column_count(stmt);
333
- for (char *ix_str = data.join_indexes; !err && ix_str && *ix_str && *(++ix_str);
334
- ix_str = strchr(ix_str + 1, ',')) {
335
- unsigned int next_ix;
336
- if (sscanf(ix_str, "%u,", &next_ix) == 1) {
337
- if (next_ix == 0)
338
- fprintf(stderr, "--join-indexes index must be greater than zero\n");
339
- else if (next_ix > (unsigned)col_count)
340
- fprintf(stderr, "Column %u out of range; input has only %i columns\n", next_ix, col_count), err = 1;
341
- else if (!sqlite3_column_name(stmt, next_ix - 1))
342
- fprintf(stderr, "Column %u unexpectedly missing name\n", next_ix);
343
- else {
344
- struct string_list *tmp = calloc(1, sizeof(**next_joined_column_name));
345
- if (!tmp)
346
- fprintf(stderr, "Out of memory!\n"), err = 1;
347
- else {
348
- tmp->value = strdup(sqlite3_column_name(stmt, next_ix - 1));
349
- *next_joined_column_name = tmp;
350
- next_joined_column_name = &tmp->next;
351
- }
352
- }
353
- }
354
- }
355
-
356
- if (!data.more_input_filenames)
357
- fprintf(stderr, "--join-indexes requires more than one input\n"), err = 1;
358
- else if (!err) { // now build the join select
359
- sqlite3_str *select_clause = sqlite3_str_new(zdb->db);
360
- sqlite3_str *from_clause = sqlite3_str_new(zdb->db);
361
- sqlite3_str *group_by_clause = sqlite3_str_new(zdb->db);
362
-
363
- sqlite3_str_appendf(select_clause, "data.*");
364
- sqlite3_str_appendf(from_clause, "data");
365
-
366
- for (struct string_list *sl = data.join_column_names; sl; sl = sl->next) {
367
- if (sl != data.join_column_names)
368
- sqlite3_str_appendf(group_by_clause, ",");
369
- sqlite3_str_appendf(group_by_clause, "\"%w\"", sl->value);
370
- }
371
-
372
- int i = 2;
373
- for (struct string_list *sl = data.more_input_filenames; sl; sl = sl->next, i++) {
374
- sqlite3_str_appendf(select_clause, ", data%i.*", i);
375
- // left join (select * from t2 group by a) t2 using(x,...)
376
- sqlite3_str_appendf(from_clause, " left join (select * from data%i group by %s) data%i", i,
377
- sqlite3_str_value(group_by_clause), i);
378
- sqlite3_str_appendf(from_clause, " using (%s)", sqlite3_str_value(group_by_clause));
379
- }
380
-
381
- if (!prefix_end || !prefix_search)
382
- asprintf(&data.sql_dynamic, "select %s from %s", sqlite3_str_value(select_clause),
383
- sqlite3_str_value(from_clause));
384
- else {
385
- asprintf(&data.sql_dynamic, "%.*s from %s%s%s", (int)(prefix_end - my_sql), my_sql,
386
- sqlite3_str_value(from_clause), strlen(prefix_end + strlen(prefix_search)) ? " " : "",
387
- strlen(prefix_end + strlen(prefix_search)) ? prefix_end + strlen(prefix_search) : "");
388
- }
389
-
390
- my_sql = data.sql_dynamic;
391
- if (opts->verbose)
392
- fprintf(stderr, "Join sql:\n%s\n", my_sql);
393
- sqlite3_free(sqlite3_str_finish(select_clause));
394
- sqlite3_free(sqlite3_str_finish(from_clause));
395
- sqlite3_free(sqlite3_str_finish(group_by_clause));
396
- }
397
- }
398
- if (stmt)
399
- sqlite3_finalize(stmt);
400
- }
401
-
402
- if (zdb->rc == SQLITE_OK && !err && my_sql) {
403
- sqlite3_stmt *stmt;
404
- err = sqlite3_prepare_v2(zdb->db, my_sql, -1, &stmt, NULL);
405
- if (err != SQLITE_OK)
406
- fprintf(stderr, "%s:\n %s\n (or bad CSV/utf8 input)\n\n", sqlite3_errstr(err), my_sql);
407
- else {
408
-
409
- int col_count = sqlite3_column_count(stmt);
410
-
411
- // write header row
412
- for (int i = 0; i < col_count; i++) {
413
- const char *colname = sqlite3_column_name(stmt, i);
414
- zsv_writer_cell(cw, !i, (const unsigned char *)colname, colname ? strlen(colname) : 0, 1);
415
- }
416
-
417
- // write sql results
418
- while (sqlite3_step(stmt) == SQLITE_ROW) {
419
- for (int i = 0; i < col_count; i++) {
420
- const unsigned char *text = sqlite3_column_text(stmt, i);
421
- int len = text ? sqlite3_column_bytes(stmt, i) : 0;
422
- zsv_writer_cell(cw, !i, text, len, 1);
423
- }
424
- }
425
- sqlite3_finalize(stmt);
426
- }
427
- }
428
- err = 1;
429
- if (zdb->err_msg)
430
- fprintf(stderr, "Error: %s\n", zdb->err_msg);
431
- else if (!zdb->db)
432
- fprintf(stderr, "Error (unable to open db, code %i): %s\n", zdb->rc, sqlite3_errstr(zdb->rc));
433
- else if (zdb->rc != SQLITE_OK)
434
- fprintf(stderr, "Error (code %i): %s\n", zdb->rc, sqlite3_errstr(zdb->rc));
435
- else
436
- err = 0;
437
-
438
- zsv_sqlite3_db_delete(zdb);
439
- }
440
- }
441
- if (f)
442
- fclose(f);
443
- zsv_sql_finalize(&data);
444
- zsv_sql_cleanup(&data);
445
- zsv_writer_delete(cw);
446
-
447
- if (tmpfn) {
448
- unlink(tmpfn);
449
- free(tmpfn);
450
- }
451
- }
452
- return err;
453
- }
@@ -1,101 +0,0 @@
1
- #include "sql_internal.h"
2
-
3
- struct zsv_sqlite3_db *zsv_sqlite3_db_new(struct zsv_sqlite3_dbopts *dbopts) {
4
- struct zsv_sqlite3_db *zdb = calloc(1, sizeof(*zdb));
5
- if (!zdb) {
6
- perror(NULL);
7
- return NULL;
8
- }
9
- const char *db_url = dbopts && dbopts->in_memory ? "file::memory:" : "";
10
- int flags = SQLITE_OPEN_URI | SQLITE_OPEN_READWRITE;
11
- zdb->rc = sqlite3_open_v2(db_url, &zdb->db, flags, NULL);
12
- if (zdb->rc == SQLITE_OK && zdb->db)
13
- zdb->rc = sqlite3_create_module(zdb->db, "csv", &CsvModule, 0);
14
- if (zdb->rc != SQLITE_OK && !zdb->err_msg)
15
- zdb->err_msg = strdup(sqlite3_errstr(zdb->rc));
16
- return zdb;
17
- }
18
-
19
- void zsv_sqlite3_db_delete(struct zsv_sqlite3_db *zdb) {
20
- if (zdb) {
21
- for (struct zsv_sqlite3_csv_file *next, *zcf = zdb->csv_files; zcf; zcf = next) {
22
- next = zcf->next;
23
- if (zcf->added)
24
- sqlite3_zsv_list_remove(zcf->path);
25
- free(zcf->path);
26
- free(zcf);
27
- }
28
- if (zdb->db)
29
- sqlite3_close(zdb->db);
30
- free(zdb);
31
- }
32
- }
33
-
34
- static int create_virtual_csv_table(const char *fname, sqlite3 *db, // int max_columns,
35
- char **err_msgp, int table_ix) {
36
- // TO DO: set customizable maximum number of columns to prevent
37
- // runaway in case no line ends found
38
- char *sql = NULL;
39
- char table_name_suffix[64];
40
-
41
- if (table_ix == 0)
42
- *table_name_suffix = '\0';
43
- else if (table_ix < 0 || table_ix > 1000)
44
- return -1;
45
- else
46
- snprintf(table_name_suffix, sizeof(table_name_suffix), "%i", table_ix + 1);
47
-
48
- sql = sqlite3_mprintf("CREATE VIRTUAL TABLE data%s USING csv(filename=%Q)", table_name_suffix, fname);
49
-
50
- char *err_msg_tmp;
51
- int rc = sqlite3_exec(db, sql, NULL, NULL, &err_msg_tmp);
52
- if (err_msg_tmp) {
53
- *err_msgp = strdup(err_msg_tmp);
54
- sqlite3_free(err_msg_tmp);
55
- }
56
- sqlite3_free(sql);
57
- return rc;
58
- }
59
-
60
- int zsv_sqlite3_add_csv(struct zsv_sqlite3_db *zdb, const char *csv_filename, struct zsv_opts *opts,
61
- struct zsv_prop_handler *custom_prop_handler) {
62
- struct zsv_sqlite3_csv_file *zcf = calloc(1, sizeof(*zcf));
63
- if (!zcf || !(zcf->path = strdup(csv_filename)))
64
- zdb->rc = SQLITE_ERROR;
65
- else {
66
- int err = 0;
67
- if (opts) {
68
- err = sqlite3_zsv_list_add(csv_filename, opts, custom_prop_handler);
69
- if (!err)
70
- zcf->added = 1;
71
- }
72
- if (err)
73
- zdb->rc = SQLITE_ERROR;
74
- else {
75
- zcf->next = zdb->csv_files;
76
- zdb->csv_files = zcf;
77
- zdb->rc = create_virtual_csv_table(csv_filename, zdb->db, &zdb->err_msg, zdb->table_count);
78
- if (zdb->rc == SQLITE_OK) {
79
- zdb->table_count++;
80
- return SQLITE_OK;
81
- }
82
- }
83
- }
84
- if (zcf) {
85
- free(zcf->path);
86
- free(zcf);
87
- }
88
- return zdb->rc;
89
- }
90
-
91
- /**
92
- * zsv_sqlite3_add_csv_no_dq is the same as zsv_sqlite3_add_csv() but also executes
93
- * sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, (void*)0);
94
- */
95
- int zsv_sqlite3_add_csv_no_dq(struct zsv_sqlite3_db *zdb, const char *csv_filename, struct zsv_opts *opts,
96
- struct zsv_prop_handler *custom_prop_handler) {
97
- int rc = zsv_sqlite3_add_csv(zdb, csv_filename, opts, custom_prop_handler);
98
- if (rc == SQLITE_OK)
99
- sqlite3_db_config(zdb->db, SQLITE_DBCONFIG_DQS_DDL, 0, (void *)0);
100
- return rc;
101
- }
@@ -1,49 +0,0 @@
1
- #ifndef SQL_INTERNAL_H
2
- #define SQL_INTERNAL_H
3
-
4
- #include <stdlib.h>
5
- #include <string.h>
6
- #include "external/sqlite3/sqlite3.h"
7
- #include "external/sqlite3/sqlite3_csv_vtab-mem.h"
8
- #include <zsv/utils/prop.h>
9
- #include <zsv/utils/string.h>
10
-
11
- extern sqlite3_module CsvModule;
12
-
13
- struct zsv_sqlite3_csv_file {
14
- struct zsv_sqlite3_csv_file *next;
15
- char *path;
16
- unsigned char added : 1;
17
- unsigned char _ : 7;
18
- };
19
-
20
- struct zsv_sqlite3_db {
21
- sqlite3 *db;
22
- int table_count;
23
- char *err_msg;
24
- struct zsv_sqlite3_csv_file *csv_files;
25
- int rc;
26
- };
27
-
28
- #include "../include/zsv/utils/sql.h"
29
-
30
- struct zsv_sqlite3_db *zsv_sqlite3_db_new(struct zsv_sqlite3_dbopts *dbopts);
31
- void zsv_sqlite3_db_delete(struct zsv_sqlite3_db *zdb);
32
-
33
- /**
34
- * @param opts: if non-null, opts and custom_prop_handler will be saved for use by the sqlite3 csvModule
35
- * and the saved entry will be removed by zsv_sqlite3_db_delete()
36
- * if NULL, csvModule will rely on any previously saved opts/custom_prop_handler
37
- */
38
- int zsv_sqlite3_add_csv(struct zsv_sqlite3_db *zdb, const char *csv_filename, struct zsv_opts *opts,
39
- struct zsv_prop_handler *custom_prop_handler);
40
-
41
- /**
42
- * zsv_sqlite3_add_csv_no_dq is the same as zsv_sqlite3_add_csv() but also disables double-quoted
43
- * values from being interpreted as literals by executing the below:
44
- * sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, (void*)0);
45
- */
46
- int zsv_sqlite3_add_csv_no_dq(struct zsv_sqlite3_db *zdb, const char *csv_filename, struct zsv_opts *opts,
47
- struct zsv_prop_handler *custom_prop_handler);
48
-
49
- #endif