Is | a reserved character?

This is kicking me as this s/b really simple:



set a to {"caiv2|2010BBDGRC|President, Board of Directors"}
--if "|" is in a then
if (ASCII character 124) is in a then
	beep 3 --> false
end if


This is a string from sqlite3. I should be able to do set my text item delimiters to “|” and find text items I would think. But it’s not finding the pipe character.

As an aside, since this is output from sqlite3, I read up on how to use the .separator command to change the delimiter. I can do it through terminal but setting up as a single command is failing. The Apple tech note says to use a semicolon but the below is failing. Perhaps because the instance of sqlite3 is an interactive program?

set sql_statement to (“.separator "%";” & "SELECT * FROM " & table_name & " ; " & “.separator "|";” as string) yields and shell command error. Perhaps the period is throwing it?

I searched the forum to try to find out what others have done with this output, but I must be using the wrong keywords. How should I parse out this output if I’m right? I hope it’s a simple thing, thanx, sam

Model: imac 27
Browser: Safari 525.27.1
Operating System: Mac OS X (10.6)

It’s actually a list {} containing a string (or text). You need to look for “|” in the text rather than in the list.



set a to {"caiv2|2010BBDGRC|President, Board of Directors"}
--if "|" is in item 1 of a then
if (character id 124) is in item 1 of a then
	beep 3 --> false
end if


Here is something to solve your troubles:



set a to "caiv2|2010BBDGRC|President, Board of Directors"
--if "|" is in a then
if a contains (ASCII character 124) then
	beep 3 --> false
end if


The bit about the pipe character has been covered by others. If you still want to use a different delimiters in the output of SQLite, read on.

I am not sure which tech note you mean, but TN2065 is about shell scripting and has no bearing on application specific commands issued to sqlite3. It is related in that often shell commands are used to “build up” application specific commands, but they have no direct syntactic relationship (e.g. you can use osascript to execute AppleScript from a shell, but that does not make AppleScript understand semicolons as statement separators).

The .separator command is a special “meta-command”, and cannot be combined with other SQL statements by joining them with semicolons. Instead, such meta-commands are terminated by newlines (and for .separator, its argument need not be quoted unless you want to use a quote character as a separator (it can be a multi-character string, too)). It is easier to supply multiple meta-commands via stdin.

set dbPath to "/tmp/s"

set sqliteCommands to "
.separator <-->
SELECT * FROM foo;
.separator |
SELECT * FROM bar;
"

do shell script "printf %s " & quoted form of sqliteCommands & " | sqlite3 " & quoted form of dbPath

Or, if you want to use the same separator for a whole session, then you can just use the -separator option on the command line of the sqlite3 program. As long as the other commands are actual SQL commands, they can be supplied as an argument to sqlite3 instead of having to supply them via stdin.

set dbPath to "/tmp/s"

set sep to "]>!sep!<["
set sqlCommands to "
SELECT * FROM foo;
SELECT * FROM bar;
"

do shell script "sqlite3 -separator " & quoted form of sep & " " & quoted form of dbPath & " " & quoted form of sqlCommands