Reputation: 2614
I was looking at some documentation here:
http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki#db_exec
And found this code snippet:
sql=[=[
CREATE TABLE numbers(num1,num2,str);
INSERT INTO numbers VALUES(1,11,"ABC");
INSERT INTO numbers VALUES(2,22,"DEF");
INSERT INTO numbers VALUES(3,33,"UVW");
INSERT INTO numbers VALUES(4,44,"XYZ");
SELECT * FROM numbers;
]=]
function showrow(udata,cols,values,names)
assert(udata=='test_udata')
print('exec:')
for i=1,cols do print('',names[i],values[i]) end
return 0
end
db:exec(sql,showrow,'test_udata')
Here they use a multi-line string but add the nesting operator =
even though no nesting is taking place.
Why would might someone do this?
Upvotes: 0
Views: 33
Reputation: 5847
The =
sign is not a nesting operator. It's just a symbol used to make double brackets marker unique. It doesn't matter if nesting is taking place or not, all that matters is that closing double brackets has the same amount of =
signs, and that the string literal does not contain that ending marker.
It is possible to have ]]
in sql request string, but not ]=]
. So using ]=]
is just a precaution, a part of coding style that eliminates the need of choosing the exact double brackets marker to match the sql request.
Upvotes: 2