Special Copy/Paste

Previous  Top  Next

The Special Copy and Special Paste feature is accessible from the main menu via Edit | Special Copy or Edit | Special Paste. You can use the default, one of the pre-defined options or the Custom menu option. The default option and pre-defined ones can be customized in the Preferences.

 

Special Copy

This functionality can be used if you want to copy text from Database Workbench to your programming environment, so that it can be pasted directly into your source code.

 

Here's an example:

 

select *

from CUSTOMERS

where CONTACT_FIRSTNAME = 'O''Hara'

 

Let's "special copy" this to several programming languages, with default settings:

 

'select *' + #10#13 +

'from CUSTOMERS' + #10#13 +

'where CONTACT_FIRSTNAME = ''O''''Hara''';

 

Delphi

All single quotes are replaced by two single quotes, text surrounded by single quotes and each line ended with #10#13 ASCII codes to signal "new line" and "carriage return".

"select *"

"from CUSTOMERS"

"where CONTACT_FIRSTNAME = ''O''''Hara''";

 

C or C++

All single quotes are replaced by two single quotes, double quotes escaped with \", text surrounded by double quotes.

"select *" & _

"from CUSTOMERS" & _

"where CONTACT_FIRSTNAME = ''O""Hara''";

ASP

All single quotes are replaced by two single quotes, text surrounded by double quotes and each line ended with & _ to signal string concatenation.

 

If you select Edit | Copy Special | Copy Special Custom, a dialog will be shown allowing you to modify the current way of copying things.

 

(click image to expand)

 

In this dialog, you can customize the current copy action.

 

Special Paste

To paste from your favorite programming language into Database Workbench, you can use the Special Paste functionality, it's default settings can be found in the Preferences.

 

The idea is to strip the SQL from any programming language specific things and get a plain SQL statement, this is done by only grabbing the text between "string markers", eg the single quote character, and replacing programming language specific escape sequences by SQL specific escape sequences.

 

For example, when copying from Delphi, the text between single quotes is taken and double single quotes are replaced by single quotes.

 

Delphi

 

'select *' + #10#13 +

'from CUSTOMERS' + #10#13 +

'where CONTACT_FIRSTNAME = ''O''''Hara''';

Database Workbench

 

select *

from CUSTOMERS

where CONTACT_FIRSTNAME = 'O''Hara'

 

If you select Edit | Paste Special | Paste Special Custom, a dialog will be shown allowing you to modify the current way of pasting.

 

 

In this dialog you can customize the current paste action.