Skip to content

Commit 31e89ba

Browse files
authored
Merge pull request #265 from noborus/README-multiple-queries
Added usage of multiple queries
2 parents df03fb0 + 5daa758 commit 31e89ba

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

README.md

+31-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ For usage as a library, please refer to the [godoc](https://pkg.go.dev/github.co
2222
* 1.3. [Homebrew](#homebrew)
2323
* 1.4. [MacPorts](#macports)
2424
* 1.5. [FreeBSD](#freebsd)
25-
* 1.6. [cgo free](#cgo-free)
25+
* 1.6. [Cgo free](#cgo-free)
2626
* 2. [Docker](#docker)
2727
* 2.1. [Docker pull](#docker-pull)
2828
* 2.2. [image build](#image-build)
@@ -34,6 +34,7 @@ For usage as a library, please refer to the [godoc](https://pkg.go.dev/github.co
3434
* 3.3. [Output formats](#output-formats)
3535
* 3.3.1. [Output options](#output-options)
3636
* 3.4. [Handling of NULL](#handling-of-null)
37+
* 3.5. [Multiple queries (v0.20.0 or later)](#multiple-queries-(v0.20.0-or-later))
3738
* 4. [Example](#example)
3839
* 4.1. [STDIN input](#stdin-input)
3940
* 4.2. [Multiple files](#multiple-files)
@@ -61,7 +62,7 @@ For usage as a library, please refer to the [godoc](https://pkg.go.dev/github.co
6162
* 5.3.2. [Join table and CSV file is possible](#join-table-and-csv-file-is-possible)
6263
* 5.4. [MySQL](#mysql)
6364
* 5.5. [Analyze](#analyze)
64-
* 5.6. [configuration](#configuration)
65+
* 5.6. [Configuration](#configuration)
6566
* 6. [Library](#library)
6667
* 7. [See also](#see-also)
6768
* 8. [License](#license)
@@ -112,7 +113,7 @@ sudo port install trdsql
112113
pkg install trdsql
113114
```
114115

115-
### 1.6. <a name='cgo-free'></a>cgo free
116+
### 1.6. <a name='cgo-free'></a>Cgo free
116117

117118
Typically, [go-sqlite3](https://github.com/mattn/go-sqlite3) is used for building.
118119
However, if you're building with `CGO_ENABLED=0`, consider using [sqlite](https://gitlab.com/cznic/sqlite) instead.
@@ -255,6 +256,32 @@ $ echo '[1,null,""]' | trdsql -inull "" -ojson -ijson "SELECT * FROM -"
255256
]
256257
```
257258

259+
### 3.5. <a name='multiple-queries-(v0.20.0-or-later)'></a>Multiple queries (v0.20.0 or later)
260+
261+
Multiple queries can be executed by separating them with a semicolon.
262+
Update queries must be followed by a SELECT statement.
263+
264+
```console
265+
$ trdsql "UPDATE SET c2='banana' WHERE c3='1';SELECT * FROM test.csv"
266+
1,Orange
267+
2,Melon
268+
3,banana
269+
```
270+
271+
You can perform multiple SELECTs, but the output will be in one format.
272+
273+
```console
274+
$ trdsql -oh "SELECT c1,c2 FROM test.csv;SELECT c2,c1 FROM test.csv"
275+
c1,c2
276+
1,Orange
277+
2,Melon
278+
3,Apple
279+
c2,c1
280+
Orange,1
281+
Melon,2
282+
Apple,3
283+
```
284+
258285
## 4. <a name='example'></a>Example
259286

260287
test.csv file.
@@ -1014,7 +1041,7 @@ trdsql -ih "SELECT id, count(id) FROM testdata/header.csv GROUP BY id"
10141041
trdsql -ih "SELECT id, \`name\` FROM testdata/header.csv ORDER BY id LIMIT 10"
10151042
```
10161043

1017-
### 5.6. <a name='configuration'></a>configuration
1044+
### 5.6. <a name='configuration'></a>Configuration
10181045

10191046
You can specify driver and dsn in the configuration file.
10201047

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ require (
1919
github.com/pierrec/lz4 v2.6.1+incompatible
2020
github.com/ulikunitz/xz v0.5.11
2121
golang.org/x/term v0.15.0
22-
modernc.org/sqlite v1.27.0
22+
modernc.org/sqlite v1.28.0
2323
)
2424

2525
require (
2626
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
2727
github.com/dustin/go-humanize v1.0.1 // indirect
2828
github.com/fatih/color v1.16.0 // indirect
2929
github.com/frankban/quicktest v1.7.2 // indirect
30-
github.com/google/uuid v1.4.0 // indirect
30+
github.com/google/uuid v1.5.0 // indirect
3131
github.com/itchyny/timefmt-go v0.1.5 // indirect
3232
github.com/jwalton/go-supportscolor v1.2.0 // indirect
3333
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
@@ -38,13 +38,13 @@ require (
3838
golang.org/x/crypto v0.16.0 // indirect
3939
golang.org/x/mod v0.14.0 // indirect
4040
golang.org/x/sys v0.15.0 // indirect
41-
golang.org/x/tools v0.16.0 // indirect
41+
golang.org/x/tools v0.16.1 // indirect
4242
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
4343
gonum.org/v1/gonum v0.14.0 // indirect
4444
lukechampine.com/uint128 v1.3.0 // indirect
4545
modernc.org/cc/v3 v3.41.0 // indirect
4646
modernc.org/ccgo/v3 v3.16.15 // indirect
47-
modernc.org/libc v1.37.0 // indirect
47+
modernc.org/libc v1.37.5 // indirect
4848
modernc.org/mathutil v1.6.0 // indirect
4949
modernc.org/memory v1.7.2 // indirect
5050
modernc.org/opt v0.1.3 // indirect

go.sum

+10-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ github.com/goccy/go-yaml v1.11.2/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHv
2121
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
2222
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
2323
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
24-
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
25-
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
24+
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
25+
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2626
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
2727
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
2828
github.com/itchyny/gojq v0.12.14 h1:6k8vVtsrhQSYgSGg827AD+PVVaB1NLXEdX+dda2oZCc=
@@ -110,8 +110,8 @@ golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
110110
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
111111
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
112112
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
113-
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
114-
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
113+
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
114+
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
115115
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
116116
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
117117
gonum.org/v1/gonum v0.14.0 h1:2NiG67LD1tEH0D7kM+ps2V+fXmsAnpUeec7n8tcr4S0=
@@ -127,8 +127,10 @@ modernc.org/ccgo/v3 v3.16.15 h1:KbDR3ZAVU+wiLyMESPtbtE/Add4elztFyfsWoNTgxS0=
127127
modernc.org/ccgo/v3 v3.16.15/go.mod h1:yT7B+/E2m43tmMOT51GMoM98/MtHIcQQSleGnddkUNI=
128128
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
129129
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
130-
modernc.org/libc v1.37.0 h1:WerjebcsP6A7Jy+f2lCnHAkiSTLf7IaSftBYUtoswak=
131-
modernc.org/libc v1.37.0/go.mod h1:YAXkAZ8ktnkCKaN9sw/UDeUVkGYJ/YquGO4FTi5nmHE=
130+
modernc.org/libc v1.37.1 h1:Wi3qhejztgB3hOYQGMc8NwePETHAWXmlU+GQnBNTrw8=
131+
modernc.org/libc v1.37.1/go.mod h1:YAXkAZ8ktnkCKaN9sw/UDeUVkGYJ/YquGO4FTi5nmHE=
132+
modernc.org/libc v1.37.5 h1:IDpTjKpyMYFenZ7DkOr6Jswhn79yxsXeWHi/4DaFDBA=
133+
modernc.org/libc v1.37.5/go.mod h1:YAXkAZ8ktnkCKaN9sw/UDeUVkGYJ/YquGO4FTi5nmHE=
132134
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
133135
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
134136
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
@@ -137,6 +139,8 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
137139
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
138140
modernc.org/sqlite v1.27.0 h1:MpKAHoyYB7xqcwnUwkuD+npwEa0fojF0B5QRbN+auJ8=
139141
modernc.org/sqlite v1.27.0/go.mod h1:Qxpazz0zH8Z1xCFyi5GSL3FzbtZ3fvbjmywNogldEW0=
142+
modernc.org/sqlite v1.28.0 h1:Zx+LyDDmXczNnEQdvPuEfcFVA2ZPyaD7UCZDjef3BHQ=
143+
modernc.org/sqlite v1.28.0/go.mod h1:Qxpazz0zH8Z1xCFyi5GSL3FzbtZ3fvbjmywNogldEW0=
140144
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
141145
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
142146
modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY=

0 commit comments

Comments
 (0)