From Clomosy Docs
(Created page with "<div class="alert alert-light" role="alert" data-bs-theme="light"> function QuotedStr(const S: string): string; </div> <br> It encloses a string in single quotes (') and escapes any existing single quotes within the string by doubling them. This is particularly useful when a string is to be used as a constant in an SQL query or another language, ensuring that the string is safely quoted.<br> Usage:<br> * QuotedStr takes a string and surrounds it with single quotes. * I...") |
No edit summary |
||
| Line 30: | Line 30: | ||
ShowMessage(quotedStr); // Output: 'O''Reilly' | ShowMessage(quotedStr); // Output: 'O''Reilly' | ||
end; | end; | ||
</pre> | |||
<h2> Usage in SQL Structure </h2> | |||
It is also used in cases where string expressions need to be added while writing sql code blocks in Clomosy application. An example code snippet is shown below.<br> | |||
<b>Example</b><br> | |||
<b>TRObject Syntax</b><br> | |||
<pre> | |||
LocalQ = Clomosy.DBSQLServerQueryWith(' SELECT '+ QuotedStr('Product Name: ') +'+productName AS MAINVIEW_TEXT ,'+ QuotedStr('Product Price: ') +'+ CAST(CAST(productPrice AS int)AS varchar(10)) AS MAINVİEW_CENTERTEXT FROM Products '); | |||
</pre> | |||
<b>Base Syntax</b><br> | |||
<pre> | |||
LocalQ := Clomosy.DBSQLServerQueryWith(' SELECT '+ QuotedStr('Product Name: ') +'+productName AS MAINVIEW_TEXT ,'+ QuotedStr('Product Price: ') +'+ CAST(CAST(productPrice AS int)AS varchar(10)) AS MAINVİEW_CENTERTEXT FROM Products '); | |||
</pre> | </pre> | ||
Revision as of 13:25, 4 October 2024
function QuotedStr(const S: string): string;
It encloses a string in single quotes (') and escapes any existing single quotes within the string by doubling them. This is particularly useful when a string is to be used as a constant in an SQL query or another language, ensuring that the string is safely quoted.
Usage:
- QuotedStr takes a string and surrounds it with single quotes.
- If the string already contains single quotes, they are doubled, making it a valid constant in languages like SQL.
Example
TRObject Syntax
var
originalStr, quotedStr: string;
{
originalStr = 'O''Reilly'; // O'Reilly is a common example with an apostrophe
quotedStr = QuotedStr(originalStr);
ShowMessage(quotedStr); // Output: 'O''Reilly'
}
Base Syntax
var originalStr, quotedStr: string; begin originalStr := 'O''Reilly'; // O'Reilly is a common example with an apostrophe quotedStr := QuotedStr(originalStr); ShowMessage(quotedStr); // Output: 'O''Reilly' end;
Usage in SQL Structure
It is also used in cases where string expressions need to be added while writing sql code blocks in Clomosy application. An example code snippet is shown below.
Example
TRObject Syntax
LocalQ = Clomosy.DBSQLServerQueryWith(' SELECT '+ QuotedStr('Product Name: ') +'+productName AS MAINVIEW_TEXT ,'+ QuotedStr('Product Price: ') +'+ CAST(CAST(productPrice AS int)AS varchar(10)) AS MAINVİEW_CENTERTEXT FROM Products ');
Base Syntax
LocalQ := Clomosy.DBSQLServerQueryWith(' SELECT '+ QuotedStr('Product Name: ') +'+productName AS MAINVIEW_TEXT ,'+ QuotedStr('Product Price: ') +'+ CAST(CAST(productPrice AS int)AS varchar(10)) AS MAINVİEW_CENTERTEXT FROM Products ');