[Lazarus] RE : Right click, paste as string?
Sven Barth
pascaldragon at googlemail.com
Sat Apr 21 18:04:03 CEST 2012
On 21.04.2012 17:58, Marcos Douglas wrote:
> On Sat, Apr 21, 2012 at 7:04 AM, Ludo Brands<ludo.brands at free.fr> wrote:
>>> When working with e.g. multiline SQL statements, sometimes I
>>> want to copy them to a string in Lazarus, e.g from something
>>> like: const
>>> SQL =
>>> with this on the clipboard:
>>> SELECT
>>> c.colid as recno,
>>> o.name as TableName,
>>> c.name as FieldName,
>>> c.colorder as FieldPosition,
>>> t.name as FieldType,
>>> c.scale as FieldScale,
>>> c.prec as FieldPrecision,
>>> c.isnullable as FieldNull
>>> FROM sys.syscolumns c
>>> INNER JOIN sys.sysobjects o ON c.id = o.id
>>> INNER JOIN sys.systypes t ON c.xtype = t.xtype and
>>> c.usertype=t.usertype WHERE (o.type='V' or o.type='U') and
>>> o.name='MEDEWERKERS' ORDER BY o.name, c.colorder
>>>
>>> to something like:
>>> Const
>>> SQL =
>>> 'SELECT'+
>>> 'c.colid as recno,'+
>>> 'o.name as TableName,'+
>>> 'c.name as FieldName,'+
>>> 'c.colorder as FieldPosition,'+
>>> 't.name as FieldType,'+
>>> 'c.scale as FieldScale,'+
>>> 'c.prec as FieldPrecision,'+
>>> 'c.isnullable as FieldNull'+
>>> 'FROM sys.syscolumns c'+
>>> 'INNER JOIN sys.sysobjects o ON c.id = o.id'+
>>> 'INNER JOIN sys.systypes t ON c.xtype = t.xtype and
>>> c.usertype=t.usertype'+
>>> 'WHERE (o.type='V' or o.type='U') and o.name=''MEDEWERKERS'''+
>>> 'ORDER BY o.name, c.colorder';
>>>
>>>
>>> I.e. indenting, appending quotes and + sign, and escaping
>>> existing quotes. (In this case, it's SQL and having an extra
>>> space at the end of the line before the closing quote would
>>> be even nicer but that's something of a special case)
>>>
>>> Is that possible in Lazarus?
>>>
>>
>> That is roughly what the 'Editing SQL' window already does with right click/
>> Create String constant. Your sample string is transformed in:
>>
>> SQL = 'SELECT'+sLineBreak+
>> 'c.colid as recno,'+sLineBreak+
>> 'o.name as TableName,'+sLineBreak+
>> 'c.name as FieldName,'+sLineBreak+
>> 'c.colorder as FieldPosition,'+sLineBreak+
>> 't.name as FieldType,'+sLineBreak+
>> 'c.scale as FieldScale,'+sLineBreak+
>> 'c.prec as FieldPrecision,'+sLineBreak+
>> 'c.isnullable as FieldNull'+sLineBreak+
>> 'FROM sys.syscolumns c'+sLineBreak+
>> 'INNER JOIN sys.sysobjects o ON c.id = o.id'+sLineBreak+
>> 'INNER JOIN sys.systypes t ON c.xtype = t.xtype and c.usertype=t.usertype
>> WHERE (o.type=''V'' or o.type=''U'') and o.name=''MEDEWERKERS'' ORDER BY
>> o.name, c.colorder';
>>
>> Only the indenting is missing.
>
> IMHO, I think this is a little better:
>
> SQL = 'SELECT '#13
> + 'c.colid as recno, '#13
> + 'o.name as TableName, '#13
> + 'c.name as FieldName, '#13
> + 'c.colorder as FieldPosition, '#13
> + 't.name as FieldType, '#13
> + 'c.scale as FieldScale, '#13
> + 'c.prec as FieldPrecision, '#13
> + 'c.isnullable as FieldNull '#13
> + 'FROM sys.syscolumns c '#13
> + 'INNER JOIN sys.sysobjects o ON c.id = o.id '#13
> + 'INNER JOIN sys.systypes t ON c.xtype = t.xtype and
> c.usertype=t.usertype '#13
> + WHERE (o.type=''V'' or o.type=''U'') and o.name=''MEDEWERKERS''
> ORDER BY '#13
> + o.name, c.colorder';
Here we are at the point again that everyone has a different
preference... I myself wouldn't like literal "#13" in the string, but
more preferably the "LineEnding" constant... (also I like to have the
"+" at the end of the line like in the example from Ludo (but with
spaces between operators and values).
Regards,
Sven
More information about the Lazarus
mailing list