Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-04

Right click, paste as string?

11 messages · 7 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Hi list,

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?

Thanks,
Reinier

Reply by email

Mattias Gaertner
to Reinier Olislagers
Show quoted text 35 lines
Hi list, 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'+

Maybe line breaks to spaces?

Show quoted text 13 lines
'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?

No.
But it is easy to write an IDE plugin that does that.

Mattias

Reply by email

Michael Van Canneyt
to Reinier Olislagers: When working with e.g. multiline SQL statements, sometimes I want to copy them to a…
Reinier Olislagers wrote
Hi list, When working with e.g. multiline SQL statements, sometimes I want to copy them to a string in Lazarus, e.g from something like:

The lazarus data dictionary SQL editor does this for you. Execute query.
Select 'generate code' button.
Select 'Generate Pascal string/constant'

That's it.

The same can be done in the Lazarus IDE.

1. Open TSQLQuery component's SQL property editor.
2. Type query.
3. Right click in SQL editor.
4. select 'Create string constant' from popup menu.

Michael.

Reply by email

Ludo Brands
to Reinier Olislagers: When working with e.g. multiline SQL statements, sometimes I want to copy them to a…
Show quoted text 47 lines
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.

Ludo

Reply by email

Reinier Olislagers
to Michael Van Canneyt: The lazarus data dictionary SQL editor does this for you. Execute query. Select 'generate…
Michael Van Canneyt wrote 15 lines
On Sat, 21 Apr 2012, Reinier Olislagers wrote: > Hi list, > > When working with e.g. multiline SQL statements, sometimes I want to > copy them to a string in Lazarus, e.g from something like: The lazarus data dictionary SQL editor does this for you. Execute query. Select 'generate code' button. Select 'Generate Pascal string/constant' That's it.

Thanks, that one I knew about...

Show quoted text 7 lines
The same can be done in the Lazarus IDE. 1. Open TSQLQuery component's SQL property editor. 2. Type query. 3. Right click in SQL editor. 4. select 'Create string constant' from popup menu.

Ok, thanks.

Perhaps the general case:
- convert ' to ''
- replace #13#10 and #10 with +LineEnding (thanks Mattias, yes, I forgot that one)
- indent
- paste
could still be handy.... but glad there's already some functionality for the SQL case!

Thanks,
Reinier

Reply by email

Michael Van Canneyt
to Reinier Olislagers
Reinier Olislagers wrote 25 lines
On 21-4-2012 12:01, Michael Van Canneyt wrote: > > > On Sat, 21 Apr 2012, Reinier Olislagers wrote: > >> Hi list, >> >> When working with e.g. multiline SQL statements, sometimes I want to >> copy them to a string in Lazarus, e.g from something like: > > The lazarus data dictionary SQL editor does this for you. > Execute query. > Select 'generate code' button. > Select 'Generate Pascal string/constant' > > That's it. Thanks, that one I knew about... > > The same can be done in the Lazarus IDE. > > 1. Open TSQLQuery component's SQL property editor. > 2. Type query. > 3. Right click in SQL editor. > 4. select 'Create string constant' from popup menu. Ok, thanks.

Note that the constant is put on the clipboard and is ready to be pasted in the code. (if you were wondering "why doesn't anything happen? " :) )

Michael.

Reply by email

Graeme Geldenhuys
to Reinier Olislagers: When working with e.g. multiline SQL statements, sometimes I want to copy them to a…
Reinier Olislagers wrote 7 lines
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?

It is not currently available in Lazarus, but as suggested it might be in 'Lazarus Data Desktop'.

Alternatively, I maintain a stand-alone tool called tiSQLEditor (mainly for use with tiOPF) which does exactly what you mentioned with indentation etc. It can also do the reverse so you can copy string SQL from your code and paste it back into tiSQLEditor as a query. The name tiSQLEditor is a bit deceiving, as it is much more than just a SQL editor, but the other functionality is more related to tiOPF. If you are interested, I can send you a pre-compiled executable. Just let me know what platform and what database server you connect too (I mainly use Firebird).

Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Reinier Olislagers
to Graeme Geldenhuys
Graeme Geldenhuys wrote 22 lines
On 21 April 2012 11:40, Reinier Olislagers wrote: > > 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? It is not currently available in Lazarus, but as suggested it might be in 'Lazarus Data Desktop'. Alternatively, I maintain a stand-alone tool called tiSQLEditor (mainly for use with tiOPF) which does exactly what you mentioned with indentation etc. It can also do the reverse so you can copy string SQL from your code and paste it back into tiSQLEditor as a query. The name tiSQLEditor is a bit deceiving, as it is much more than just a SQL editor, but the other functionality is more related to tiOPF. If you are interested, I can send you a pre-compiled executable. Just let me know what platform and what database server you connect too (I mainly use Firebird).

Sounds nice, Graeme, I'll shoot you an email...

Reply by email

Marcos Douglas
to Mattias Gaertner: On Sat, 21 Apr 2012 11:40:28 +0200 Maybe line breaks to spaces? No. But it is easy to…
Mattias Gaertner wrote 59 lines
On Sat, 21 Apr 2012 11:40:28 +0200 Reinier Olislagers wrote: > Hi list, > > 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'+ Maybe line breaks to spaces? > ? ? '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? No. But it is easy to write an IDE plugin that does that.

+1
But I do that using "macro record". First in Delphi but now we have in Lazarus too (thanks Mattias).

Marcos Douglas

Reply by email

Marcos Douglas
to Ludo Brands: That is roughly what the 'Editing SQL' window already does with right click/ Create…
Ludo Brands wrote 67 lines
> 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';

Marcos Dougla

Reply by email

Sven Barth
to Marcos Douglas
Marcos Douglas wrote 87 lines
On Sat, Apr 21, 2012 at 7:04 AM, Ludo Brands 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

Reply by email