From Clomosy Docs
No edit summary |
ClomosyAdmin (talk | contribs) No edit summary |
||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<div class="alert alert- | <div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert"> | ||
function QuotedStr(const S: string): string; | function QuotedStr(const S: string): string; | ||
</div> | </div> | ||
<br> | <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> | 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> | ||
| Line 10: | Line 11: | ||
* If the string already contains single quotes, they are doubled, making it a valid constant in languages like SQL. | * If the string already contains single quotes, they are doubled, making it a valid constant in languages like SQL. | ||
<b>Example</b><br> | |||
<pre> | <pre> | ||
var | var | ||
| Line 21: | Line 22: | ||
} | } | ||
</pre> | </pre> | ||
<b> | |||
< | <b>Output:</b><br> | ||
<div class="alert alert-success" role="alert" data-bs-theme="light"> | |||
<nowiki>'O''Reilly'</nowiki> | |||
</div> | |||
</ | |||
<h2> Usage in SQL Structure </h2> | <h2> Usage in SQL Structure </h2> | ||
| Line 36: | Line 32: | ||
<b>Example</b><br> | <b>Example</b><br> | ||
<pre> | <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 '); | 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> | ||
< | |||
<h2> See Also </h2> | |||
* [[System_Library#String_Functions | String Functions]] | |||
{{#seo:|title=QuotedStr Using in Clomosy - Clomosy Docs}} | |||
{{#seo:|description=Learn how to use the QuotedStr function in Clomosy to securely format strings for SQL queries and other applications.}} | |||
Latest revision as of 15:09, 24 December 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
var
originalStr, quotedStr: string;
{
originalStr = 'O''Reilly'; // O'Reilly is a common example with an apostrophe
quotedStr = QuotedStr(originalStr);
ShowMessage(quotedStr); // Output: 'O''Reilly'
}
Output:
'O''Reilly'
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
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 ');