SQLite User Forum

Error 141 ??
Login

Error 141 ??

(1) By patrice on 2023-04-02 04:12:26 [link] [source]

Hi all

On a very simple query inside of a bash script, I am getting an error 141.

select headDomain from cnameMap where domain='media.apple-dns.net'

Running that same query straight from the command line works fine.

I can't find any details about what that error might be. Any pointers?

Thanks in advance..

(2) By Larry Brasfield (larrybr) on 2023-04-02 04:45:02 in reply to 1 [link] [source]

On a very simple query inside of a bash script, I am getting an error 141.

To get help with this, we need to see what that means. To my knowledge, bash does not understand SQL. I use bash and SQLite often, but I can only guess what you are doing that is summarized as "On a very simple query inside of a bash script". I can only guess what program you have (maybe) run or tried to run from bash, and I have no idea what inputs you provided. I do not know what you observed that causes you to write "I am getting an error 141." (I do know that the SQLite shell does not report "141" and the SQLite library has no such result code.)

Running that same query straight from the command line works fine.

How does "query inside of a bash script" differ from "straight from the command line"?

I can't find any details about what that error might be. Any pointers?

Some application using SQLite might document your mystery error. I would want to know more before starting a snipe hunt for it.

(3) By Warren Young (wyoung) on 2023-04-02 04:56:32 in reply to 2 [link] [source]

Something is getting SIGPIPE.

Why? Good question.

(5) By patrice on 2023-04-02 18:01:15 in reply to 2 [link] [source]

Hi Larry,

Thanks for the answer.. So the command invoked from the bash script is:

sqlite3 -cmd ".timeout ${SQLITE_TIMEOUT}" "${db}" "${__sqlArray[@]}" 
s=$?
if (( s )); then
	exitWithMessageAndCode $"SQLite Error $s with DB '${db}' executing '${__sqlArray[*]}'" "$s"
fi

and the exit command is hit, and s equals 141 there..

I am running that same sqlite3 invocation from the command line with the values directly and it works there. I don't see how an extra error code sneaks in there..

SIGPIPE sounds like a good lead right now..

(7) By Larry Brasfield (larrybr) on 2023-04-02 18:38:14 in reply to 5 [source]

Yes, SIGPIPE is a good lead. The SQLite CLI does not return such varied errors, and it invokes no subshells unless told to do so. That leads to:

What does this: echo "${__sqlArray[@]}" return from that bash session?

I would also be wondering about what is shown by: file $(which sqlite3) .

(8.2) By Adrian Ho (lexfiend) on 2023-04-03 14:15:09 edited from 8.1 in reply to 7 [link] [source]

What does this:

   echo "${__sqlArray[@]}"
return from that bash session?

Actually, the output of:

    declare -p __sqlArray
is more instructive...

$ __sqlArray=("create table a(x int)" "insert into a values (1), (2), (3)" "select * from a")

$ echo "${__sqlArray[@]}"
create table a(x int) insert into a values (1), (2), (3) select * from a

$ declare -p __sqlArray
declare -a __sqlArray=([0]="create table a(x int)" [1]="insert into a values (1), (2), (3)" [2]="select * from a")

$ sqlite3 -table :memory: "${__sqlArray[@]}"
+---+
| x |
+---+
| 1 |
| 2 |
| 3 |
+---+

(9) By patrice on 2023-04-04 01:08:39 in reply to 8.2 [link] [source]

So adding some debug statements seems to indicate everything is ok with the invocation:

sqlite3 -cmd ".timeout ${SQLITE_TIMEOUT}" "${db}" "${__sqlArray[@]}" 
s=$?
if (( s )); then
	echo "s=$s" >&2
	declare -p __sqlArray >&2
	declare -p sql >&2
	type sqlite3  >&2
	file $(which sqlite3)  >&2
	exitWithMessageAndCode $"SQLite Error $s with DB '${db}' executing '${__sqlArray[*]}'" "$s"
fi

yields

s=141
declare -n __sqlArray="sql"
declare -a sql=([0]="select headDomain from cnameMap where domain='ocsp.comodoca.com.cdn.cloudflare.net'")
sqlite3 is hashed (/usr/bin/sqlite3)
/usr/bin/sqlite3
/usr/bin/sqlite3: Mach-O universal binary with 3 architectures: [x86_64:Mach-O 64-bit executable x86_64] [x86_64h] [arm64e]
/usr/bin/sqlite3 (for architecture x86_64):	Mach-O 64-bit executable x86_64
/usr/bin/sqlite3 (for architecture x86_64h):	Mach-O 64-bit executable x86_64h
/usr/bin/sqlite3 (for architecture arm64e):	Mach-O 64-bit executable arm64e
***** SQLite Error 141 with DB '/Users/patrice/.cache/whoisPiHole-syn26000.sqlite' executing 'select headDomain from cnameMap where domain='ocsp.comodoca.com.cdn.cloudflare.net''

that exact code path is traveled many time before getting to that point, on the same DB with very similar queries, and this one fails every time and it's the only one doing that. The same thing happens on several machines I've tried this on too

(10) By patrice on 2023-04-04 01:15:05 in reply to 9 [link] [source]

Found a workaround I think following up on the SIGPIPE lead.. looking up the bash call stack I found this:

result=$(someFunctionWhichEndsupCallingTheSQLPathAbove | head -n1)

splitting this into

result=$(someFunctionWhichEndsupCallingTheSQLPathAbove)
result=$(echo "$result" | head -n1)

makes the problem go away. So sqlite3 is out of contention here, seems to be more of a bash quirk/bug now..

(4) By Simon Slavin (slavin) on 2023-04-02 09:13:36 in reply to 1 [link] [source]

Most errors involving scripting we see here are to do with quoting, or with escaping quote characters. The SELECT command you quote has apostrophes in it. Are you passing this command as part of a command line ? If so, my guess is that the apostrophes are being interpreted by BASH, not SQLite.

To fix the problem you may need to learn how to escape those characters. Or I may be barking up the wrong tree and your problem is nothing to do with that.

(6) By patrice on 2023-04-02 18:02:15 in reply to 4 [link] [source]

I am reasonably sure this particular one is not a quoting issue.. also wouldn't explain error 141 I don't think.