I am attempting to run a sqlite3 command from within Go, to do a simple query (I completly understand there are other ways to access sqlite from go, but thats not the issue here)
func sqliteTest(){
cmd:=exec.Command("/usr/bin/sqlite3", " /home/chadg/Downloads/testDb.db 'select * from testTable;'")
fmt.Println("Command String:",cmd.String())
out,err:=cmd.CombinedOutput()
if err!=nil{
fmt.Println("Error Accessing Database:",err.Error(),string(out))
return
}
fmt.Println("Result Length:",len(out))
fmt.Println("Result:",string(out))
}
Running this gives me this output:
Command String: /usr/bin/sqlite3 /home/chadg/Downloads/testDb.db 'select * from testTable;'
Result Length: 0
Result:
Process finished with exit code 0
However if I run the same command by hand:
$ /usr/bin/sqlite3 /home/chadg/Downloads/testDb.db 'select * from testTable;'
testName|testValue
Have certainly run into many issues when running commands from within go, but there is always an error generated, but this time, there is no error, but the result from stdout and stderr seems to both be empty.
EDIT: Single quotes vs double quotes doesn't change anything
cmd:=exec.Command("/usr/bin/sqlite3", " /home/chadg/Downloads/testDb.db \"select * from testTable;\"")
still returns an empty output, but works as expected from the command line.
cmd:=exec.Command("/usr/bin/sqlite3", " /home/chadg/Downloads/testDb.db","'select * from testTable;'")though i am unsure about the single quotes around the sql" /home/chadg/Downloads/testDb.db 'select * from testTable;'"