Can Awk directly interact with some RDBMS engine (that is, within
'BEGIN{}')?
It depends on the interface the RDBMS provides.I suppose it's the only solution, unless you extend Awk's syntax to
What you can do with GNU awk is, for example, to create a co-process
and send requests to that co-process and intercept its replies to
process them.
On 2/3/2024 1:25 am, Janis Papanagnou wrote:
I suppose it's the only solution, unless you extend Awk's syntax to SQLconnect some RDBMS. :)
It depends on the interface the RDBMS provides.
What you can do with GNU awk is, for example, to create a co-process
and send requests to that co-process and intercept its replies to
process them.
Can Awk directly interact with some RDBMS engine (that is, within 'BEGIN{}')?
I haven't done a Google Search yet. Is looking for a direct answer. :)
Well, in the past there was xgawk that supported database handling.
This feature is now available in GNU Awk as part of its extension
library. You can handle PostgreSQL with it. But since I have never
used it myself you have to look up the details yourself. (Or maybe
there's someone around here who has experiences with the extension
or can answer any specific questions.)
On 3/1/24 9:29 AM, Mr. Man-wai Chang wrote:
Can Awk directly interact with some RDBMS engine (that is, within
'BEGIN{}')?
I haven't done a Google Search yet. Is looking for a direct answer. :)
I *think* most SQL type DBs have CLI interaction capabilities.
A SQLite3 example; 'csv' used for DB output mode since it's easy to run split() on and several awks now have native CSV support:
....
BEGIN {
DBfile = "./site.db"
CMD = "sqlite3 -csv " DBfile " \"" ARGV[1] "\""
while (CMD | getline == 1) arr[++cnt] = $0
close(CMD)
for (i=1; i<=cnt; i++) printf "arr[%d] = %s\n", i, arr[i]
print ""
}
On 3/3/24 16:20, Arti F. Idiot wrote:
BEGIN {
DBfile = "./site.db"
CMD = "sqlite3 -csv " DBfile " \"" ARGV[1] "\""
while (CMD | getline == 1) arr[++cnt] = $0
close(CMD)
for (i=1; i<=cnt; i++) printf "arr[%d] = %s\n", i, arr[i]
print ""
}
Would someone please help me understand why you'd want to have the
sqlite3 (et al.) inside of awk (in the BEGIN{...}) verses having sqlite3 outside of awk and piping the output from sqlite3's STDOUT into awk's STDIN?
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (1 / 9) |
Uptime: | 76:04:52 |
Calls: | 12,949 |
Calls today: | 3 |
Files: | 186,574 |
Messages: | 3,264,538 |