[英]Ruby Code Comment Within Quotes
I have a multi-line SQL command string in my Ruby script. 我的Ruby脚本中有一个多行SQL命令字符串。 I am adding some extra lines to the SQL command string, and want to supplement it with some in-line comments. 我在SQL命令字符串中添加了一些额外的行,并希望在其中添加一些行内注释。
mysql.query("CREATE TABLE If NOT EXISTS #{table}(
application varchar(255),
eventType varchar(255),
eventTs datetime,
eventDayWeek int,
newColumnHere int, #Hello, I would like to be a comment
eventHourDay int,
....)")
How does one add code comments within a set of quotes? 如何在一组引号内添加代码注释?
MySQL does support comment syntax so your code should work as is. MySQL确实支持注释语法,因此您的代码应按原样工作。 However, I would prefer to use a "heredoc": 但是,我宁愿使用“ heredoc”:
mysql.query <<END
CREATE TABLE If NOT EXISTS #{table}(
application varchar(255),
eventType varchar(255),
eventTs datetime,
eventDayWeek int,
newColumnHere int, #Hello, I would like to be a comment
eventHourDay int,
....)
END
You could just break the string in two, or alternatively include an SQL comment. 您可以将字符串分成两部分,或者包含一个SQL注释。
For the first option: 对于第一种选择:
"CREATE TABLE ...
newColumnHere int, " +
# comment in ruby here
"eventHourDay int, ...
Or the second option: 或第二种选择:
newColumnHere int, -- SQL comments from double dash to end of line
eventHourDay int,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.