Insert string with quotes or apostrophies
Hi,
This seems like a simple problem, but I can't seem to find the answer.
If I want to insert a string into an oracle database that contains an apostrophy, for example:
"She's...."
How would I insert something like this when you normally surround your string with single quotes?
Thanks,
Annette
Use 2 single quotes to create one in your data.
select 'She''s' from dual;
returns She's
null
Similar Messages
-
Can I Index a String with Quotes. How is Men's indexed
HI!
I want to know that when i index a column which has a string with quotes how is it indexed ie., if there is a string "men's" then how is this indexed? because i am not able to search for men's,and when i search as "men_s" nothing is returned how to do that?
regards
JDUse the printjoins lexer attribute -
http://technet.oracle.com/doc/oracle8i_816/inter.816/a77063/cdatadi5.htm#35052 -
Insert value with quotes into the table
Hi,
How can I insert a value along with quotes into a table column of type varchar.
Meaning..I want to insert the value 'TEST' including the single quotes.
Regards,
Murali MohanIt only a matter of using the correct number of quotes. to insert 'TEST' you use 3 quotes on each end
example: '''TEST'''
Hi,
How can I insert a value along with quotes into a table column of type varchar.
Meaning..I want to insert the value 'TEST' including the single quotes.
Regards,
Murali Mohan -
Question about expressions that result in strings with quotes
Without jumping into too many of the details, I want to do something like this:
<h:outputLink onclick="someJSFunc('#{somebean.someVal}')" />
When the expression results in a string that contains apostrophes, the code naturally fails. Pre-JSF, I simply used a JSP scriptlet that took the value and passed it to a method that encoded it (quotes became an HTML code, etc). However, I don't know how I can achieve the same results with JSF...
Any ideas???Are you using the latest RI? I'm looking at the source code, and the default response writer seems to escape quotes as """ when writing attributes, as it should for HTML.
If you do have the latest RI, what sort of error are you getting?
Garret -
Generating a String with Quotes
Hi,
I have a table TABLEA
when i select :select code from tablea:
i want the output as:
create table tablea(code varchar2(1));
insert into tablea values('a');
insert into tablea values('b');
insert into tablea values('c');
insert into tablea values('d');
commit;
'a','b','c','d'
Any help will be needful for mehoek wrote:
2 from ( select rownum rnSince there is no particular order in relational tables, yoy are not guaranteed to get 'a','b','c','d':
SQL> select ltrim(sys_connect_by_path(''''||code||'''', ','), ',') str
2 from ( select rownum rn
3 , code
4 from tablea
5 )
6 where connect_by_isleaf=1
7 start with rn=1
8 connect by rn=prior rn+1;
STR
'd','b','a','c'You should use analytic row_number:
select ltrim(sys_connect_by_path(''''||code||'''', ','), ',') str
from ( select row_number() over(order by code) rn
, code
from tablea
where connect_by_isleaf=1
start with rn=1
connect by rn=prior rn+1
STR
'a','b','c','d'
SQL> SY. -
How to Search strings with and without quotes
Hello,
I need to search a string with quote and without quote the same way
Ex: Wendy's
If user enters wendys without ' also need to return all the Wendy's..!
I appreciate any help...!
Thanks
RGHi,
RG wrote:
Hello,
I need to search a string with quote and without quote the same way
Ex: Wendy's
If user enters wendys without ' also need to return all the Wendy's..!
I appreciate any help...!So you want to ignore single-quotes, is that it?
Here's one way:
INSTR ( REPLACE (big_string, '''')
, REPLACE (substring_sought, '''')
) > 0
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Inserting a string with apostrophe to SQL Server
Hi,
I develop a windows application using C#. I try to take a value from the textbox and put it in the table on SQL server. I create a connection string and the command string (ODBC). The value I want to insert surrounded with apostrophes. The problem occurs when user wants to insert apostrophe in the textbox. It is inserted to the string value and SQL server recognizes it as an end of string.
Does anybody know how to resolve this problem?
thank you.string someVal = TextBox1.Text;
someVal = someVal.Replace("'", "''");
This code should double up the value entered by some user in TextBox1
and then you can pass these values to sql command like this
var sb = new StringBuilder();
sb.AppendFormat("SELECT project_id,project_name" + " FROM dbo.TableName");
sb.Append(" WHERE " + someVal);
var select = new SqlCommand(sb.ToString(), conn))
Product Lifecycle Development |
Backlinks |
Get Twitter Followers -
String with embedded single quote
Hi, all. We're trying to pass a string from one procedure to another, which will then do an EXECUTE IMMEDIATE on it. However, there are single quotes withing the string, and they're driving us nuts! This is what the concatenated string should look like when passed to the pw_execDDL procedure:
insert into appimmunization.wsrprfs (inoc_id, proof, is_valid,proof_num) values ('MEAG', to_date('02-OCT-05','DD-MMM-YY'), 'Y',1);
Here's the concatenation process that doesn't work, and there are functions being called within the string:
chr_sql := 'insert into appimmunization.wsrprfs (inoc_id, proof, is_valid,proof_num) values (' || '''' || prm_inoc_id || '''' || ', ' || 'to_date(' || '''' || prm_proof1 || ''''||','||'''' ||'DD-MMM-YY'||''''||')' || ', ' || '''' || fw_is_proof_valid(prm_birth_date, prm_proof1) || '''' || ',1);';
pw_execDDL(chr_sql); /* call the procedure to do the EXECUTE IMMEDIATE */
Help! We've tried every combination -- using two single quotes together, three, and four, and still no luck. Thanks.insert into appimmunization.wsrprfs (inoc_id, proof,
is_valid,proof_num) values ('MEAG',
to_date('02-OCT-05','DD-MMM-YY'), 'Y',1);
This statement can be made in a string with the following affectation:
chr_sql := 'insert into appimmunization.wsrprfs (inoc_id, proof, is_valid,proof_num) values (''MEAG'', to_date(''02-OCT-05'',''DD-MMM-YY''), ''Y'',1)';
Note please that each single quote in your original string must be specified using two single quotes and that is all. It is more readable and more easy to do it this way.
Michel. -
How to concatenate a string with single quotes
Hi all,
how to concatenate a string with single quotes to a variable.
SathyaHi sathyabama,
1. simple
2. use TILDE character <b>(`)</b>
(just left to the '1' key)
<b> `'mystring'`</b>
3. just copy paste
report abc.
data : m(100) type c.
concatenate `'amit mittal'` 'hello' into m separated by space.
write m.
regards,
amit m. -
Replacing a special character in a string with another string
Hi
I need to replace a special character in a string with another string.
Say there is a string - "abc's def's are alphabets"
and i need to replace all the ' (apostrophe) with &apos& ..which should look like as below
"abc&apos&s def&apos&s are alphabets" .
Kindly let me know how this requirement can be met.
Regards
SukumariREPLACE
Syntax Forms
Pattern-based replacement
1. REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF]
pattern
IN [section_of] dobj WITH new
[IN {BYTE|CHARACTER} MODE]
[{RESPECTING|IGNORING} CASE]
[REPLACEMENT COUNT rcnt]
{ {[REPLACEMENT OFFSET roff]
[REPLACEMENT LENGTH rlen]}
| [RESULTS result_tab|result_wa] }.
Position-based replacement
2. REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
[IN {BYTE|CHARACTER} MODE].
Effect
This statement replaces characters or bytes of the variable dobj by characters or bytes of the data object new. Here, position-based and pattern-based replacement are possible.
When the replacement is executed, an interim result without a length limit is implicitly generated and the interim result is transferred to the data object dobj. If the length of the interim result is longer than the length of dobj, the data is cut off on the right in the case of data objects of fixed length. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or hexadecimal zeroes. Data objects of variable length are adjusted. If data is cut off to the right when the interim result is assigned, sy-subrc is set to 2.
In the case of character string processing, the closing spaces are taken into account for data objects dobj of fixed length; they are not taken into account in the case of new.
System fields
sy-subrc Meaning
0 The specified section or subsequence was replaced by the content of new and the result is available in full in dobj.
2 The specified section or subsequence was replaced in dobj by the contents of new and the result of the replacement was cut off to the right.
4 The subsequence in sub_string was not found in dobj in the pattern-based search.
8 The data objects sub_string and new contain double-byte characters that cannot be interpreted.
Note
These forms of the statement REPLACE replace the following obsolete form:
REPLACE sub_string WITH
Syntax
REPLACE sub_string WITH new INTO dobj
[IN {BYTE|CHARACTER} MODE]
[LENGTH len].
Extras:
1. ... IN {BYTE|CHARACTER} MODE
2. ... LENGTH len
Effect
This statement searches through a byte string or character string dobj for the subsequence specified in sub_string and replaces the first byte or character string in dobj that matches sub_string with the contents of the data object new.
The memory areas of sub_string and new must not overlap, otherwise the result is undefined. If sub_string is an empty string, the point before the first character or byte of the search area is found and the content of new is inserted before the first character.
During character string processing, the closing blank is considered for data objects dobj, sub_string and new of type c, d, n or t.
System Fields
sy-subrc Meaning
0 The subsequence in sub_string was replaced in the target field dobj with the content of new.
4 The subsequence in sub_string could not be replaced in the target field dobj with the contents of new.
Note
This variant of the statement REPLACE will be replaced, beginning with Release 6.10, with a new variant.
Addition 1
... IN {BYTE|CHARACTER} MODE
Effect
The optional addition IN {BYTE|CHARACTER} MODE determines whether byte or character string processing will be executed. If the addition is not specified, character string processing is executed. Depending on the processing type, the data objects sub_string, new, and dobj must be byte or character type.
Addition 2
... LENGTH len
Effect
If the addition LENGTH is not specified, all the data objects involved are evaluated in their entire length. If the addition LENGTH is specified, only the first len bytes or characters of sub_string are used for the search. For len, a data object of the type i is expected.
If the length of the interim result is longer than the length of dobj, data objects of fixed length will be cut off to the right. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or with hexadecimal 0. Data objects of variable length are adapted.
Example
After the replacements, text1 contains the complete content "I should know that you know", while text2 has the cut-off content "I should know that".
DATA: text1 TYPE string VALUE 'I know you know',
text2(18) TYPE c LENGTH 18 VALUE 'I know you know',
sub_string TYPE string VALUE 'know',
new TYPE string VALUE 'should know that'.
REPLACE sub_string WITH new INTO text1.
REPLACE sub_string WITH new INTO text2. -
Again same problem with quotes, but cant find a proper sol
I've gone thru so many posts, but cud'nt really find a solution. someone please help me here. I have a single insert function, which does all inserts for many tables, so cant use ppdstmt.setString(1, "value").
I am trying to insert some data into SQL server database(thru jdbc). The normal data works just fine, but if the user inserts some data which have quotation marks, then its throwing an error that is invalid character.
ex: received ->enters correctly into db
but
rec'd -> unable to
Insert into table(name) values('Oreilly'); //works fine
Insert into table(name) values('O'reilly'); //throws an error, sql exception
because the sql server is unable to find the matching quote. I would like to replace it with a ` or double quotes, but I am unable to replace it. I am not using a string to insert a value, I am using an Object. so I am unable to use any preparedStatement also(like ppdstmt.setString(1,"value"). Also I cant use replaceAll function, because, I am using jdk1.3. Is there any other way, I can replace ' with '' or `. The following is my code for inserting data.
private void insert(String pQualifierName, String pTableName, Map pValueMap)
m1Buffer.append("INSERT INTO ").append(QualifyTableName(pQualifierName, pTableName)).append(" (");
m2Buffer.append(" VALUES (");
// go over all values
boolean isNotFirst = false;
for (Iterator i = pValueMap.keySet().iterator(); i.hasNext();)
if (isNotFirst)
m1Buffer.append(", ");
m2Buffer.append(", ");
isNotFirst = true;
String aColumnName = (String) i.next();
// add the column name to the first part
m1Buffer.append(aColumnName);
// add a "?" to the second part, as well as adding the value to the parameter list
if(pValueMap.get(aColumnName)!= null) {
//aColumnName=aColumnName.replace( '\'', '`');
m2Buffer.append("'");
m2Buffer.append(pValueMap.get(aColumnName));
m2Buffer.append("'");
} else {
m2Buffer.append(pValueMap.get(aColumnName)); //appends the value we entered
m1Buffer.append(")");
m2Buffer.append(")");
protected void insert()
verifyUnbacked();
try
StatementBuilder aBuilder = StatementBuilder.insertStatement(accessQualifierName(), accessTableName(), mUnbackedMap);
Connection aConnection = ConnectionPool.getConnection();
try
PreparedStatement aPreparedStatement = aBuilder.generatePreparedStatement(aConnection);
try
aPreparedStatement.executeUpdate();
ThanksBarun_guha,
Thanks for your code, but the problem is pValueMap.get(aColumnName) is an Object and it cannot be initialized as a String .
scsi-boy,
I am attaching the 2 files related, StatementBuilder.java and AbstractEntity.java.
Basically, the statementBuilder.java builds the SQL stmt and AbstractEntity.java does the update, delete and inserts(it has the PreparedStament). So could someone suggest me a solution based on this code.
Thanks
import firstpro.util.AbstractType;
import java.sql.*;
import java.util.*;
public class StatementBuilder
private static final StatementType SELECT = new StatementType("SELECT");
private static final StatementType INSERT = new StatementType("INSERT");
private static final StatementType IDENTITY = new StatementType("IDENTITY");
private static final StatementType UPDATE = new StatementType("UPDATE");
private static final StatementType DELETE = new StatementType("DELETE");
* is true when the prepared statment can be set as "read-only" (i.e., a select of some kind).
private boolean mIsReadOnly = false;
* denotes what operation this statement represents.
private StatementType mStatementType;
* accumulates all the table names used in the statement.
private List mTableList = new ArrayList();
* holds the sequence of tables followed in join expressions.
private LinkedList mTableStack = new LinkedList();
* accumulates the table column names referenced in the statement.
private Set mReferenceSet = new HashSet();
* holds the column names used in the select result.
private List mResultColumnList = new ArrayList();
* is the first part of the generated SQL statement.
private StringBuffer m1Buffer = new StringBuffer();
* is the second part of the generated SQL statement.
private StringBuffer m2Buffer = new StringBuffer();
* holds the list of actual parameter values to substitute for the "?" symbols in the generated SQL.
private List mParameterList = new ArrayList();
* constructs an instance with the given type.
* @param pStatementType
private StatementBuilder(StatementType pStatementType)
mStatementType = pStatementType;
* creates a "select" statement.
* @param pQualifierName
* @param pTableName
* @param pCondition
* @param pResult
* @return
static StatementBuilder selectStatement(String pQualifierName, String pTableName, AbstractEntityCondition pCondition, AbstractEntityResult pResult)
StatementBuilder aBuilder = new StatementBuilder(SELECT);
aBuilder.select(pQualifierName, pTableName, pCondition, pResult);
return aBuilder;
* creates a "select distinct" statement.
* @param pQualifierName
* @param pTableName
* @param pCondition
* @param pResult
* @return
static StatementBuilder distinctStatement(String pQualifierName, String pTableName, AbstractEntityCondition pCondition, AbstractEntityResult pResult)
StatementBuilder aBuilder = new StatementBuilder(SELECT);
aBuilder.distinct(pQualifierName, pTableName, pCondition, pResult);
return aBuilder;
* creates a "select count(*)" statement.
* @param pQualifierName
* @param pTableName
* @param pCondition
* @return
static StatementBuilder countStatement(String pQualifierName, String pTableName, AbstractEntityCondition pCondition)
StatementBuilder aBuilder = new StatementBuilder(SELECT);
aBuilder.count(pQualifierName, pTableName, pCondition);
return aBuilder;
* creates in "insert" statement.
* @param pQualifierName
* @param pTableName
* @param pValueMap
* @return
static StatementBuilder insertStatement(String pQualifierName, String pTableName, Map pValueMap)
StatementBuilder aBuilder = new StatementBuilder(INSERT);
aBuilder.insert(pQualifierName, pTableName, pValueMap);
return aBuilder;
* creates an "identity" statement (for retrieving the generated primary key from the DB after an insert).
* @param pTypeName
* @return
static StatementBuilder identityStatement(String pTypeName)
StatementBuilder aBuilder = new StatementBuilder(IDENTITY);
aBuilder.identity(pTypeName);
return aBuilder;
* creates an "update" statement.
* @param pQualifierName
* @param pTableName
* @param pValueMap
* @param pCondition
* @return
static StatementBuilder updateStatement(String pQualifierName, String pTableName, Map pValueMap, AbstractEntityCondition pCondition)
StatementBuilder aBuilder = new StatementBuilder(UPDATE);
aBuilder.update(pQualifierName, pTableName, pValueMap, pCondition);
return aBuilder;
* creates a "delete" statement.
* @param pQualifierName
* @param pTableName
* @param pCondition
* @return
static StatementBuilder deleteStatement(String pQualifierName, String pTableName, AbstractEntityCondition pCondition)
StatementBuilder aBuilder = new StatementBuilder(DELETE);
aBuilder.delete(pQualifierName, pTableName, pCondition);
return aBuilder;
* emits a predicate of "true".
void trueAlways()
appendTrue();
* emits a predicate of "false".
void falseAlways()
appendFalse();
* emits a "join" predicate.
* @param pColumnName
* @param pQualifierName
* @param pJoinedTableName
* @param pJoinedColumnName
* @param pCondition
void join(String pColumnName, String pQualifierName, String pJoinedTableName, String pJoinedColumnName, AbstractEntityCondition pCondition)
if (!SELECT.equals(mStatementType))
throw new RuntimeException("Join only allowed in SELECT");
appendOpening();
appendColumn(pColumnName);
appendEqualTo();
pushTable(pQualifierName, pJoinedTableName);
appendColumn(pJoinedColumnName);
appendClosing();
appendAnd();
appendOpening();
appendCondition(pCondition);
appendClosing();
popTable();
* emits an "and" predicate.
* @param pCondition1
* @param pCondition2
void and(AbstractEntityCondition pCondition1, AbstractEntityCondition pCondition2)
appendOpening();
appendCondition(pCondition1);
appendClosing();
appendAnd();
appendOpening();
appendCondition(pCondition2);
appendClosing();
* emits an "and" predicate.
* @param pConditionArray
void and(AbstractEntityCondition[] pConditionArray)
if (0 == pConditionArray.length)
appendTrue();
else
for (int i = 0; i < pConditionArray.length; i++)
if (i != 0)
appendAnd();
appendOpening();
appendCondition(pConditionArray);
appendClosing();
* emits an "or" predicate.
* @param pCondition1
* @param pCondition2
void or(AbstractEntityCondition pCondition1, AbstractEntityCondition pCondition2)
appendOpening();
appendCondition(pCondition1);
appendClosing();
appendOr();
appendOpening();
appendCondition(pCondition2);
appendClosing();
* emits an "or" predicate.
* @param pConditionArray
void or(AbstractEntityCondition[] pConditionArray)
if (0 == pConditionArray.length)
appendFalse();
else
for (int i = 0; i < pConditionArray.length; i++)
if (i != 0)
appendOr();
appendOpening();
appendCondition(pConditionArray[i]);
appendClosing();
* emits a "not" predicate.
* @param pCondition
void not(AbstractEntityCondition pCondition)
appendNot();
appendOpening();
appendCondition(pCondition);
appendClosing();
* emits an "is null" predicate.
* @param pColumnName
void isNull(String pColumnName)
appendColumn(pColumnName);
appendIsNull();
* emits an "is not null" predicate.
* @param pColumnName
void isNotNull(String pColumnName)
appendColumn(pColumnName);
appendIsNotNull();
* emits a "between" predicate.
* @param pColumnName
* @param pValue1
* @param pValue2
void isBetween(String pColumnName, Object pValue1, Object pValue2)
appendColumn(pColumnName);
appendBetween();
appendValue(pValue1);
appendAnd();
appendValue(pValue2);
* emits a case-insensitive "between" predicate.
* @param pColumnName
* @param pValue1
* @param pValue2
void isBetweenIgnoringCase(String pColumnName, Object pValue1, Object pValue2)
appendColumnUpper(pColumnName);
appendBetween();
appendValueUpper(pValue1);
appendAnd();
appendValueUpper(pValue2);
* emits a "like" predicate.
* @param pColumnName
* @param pValue
void isLike(String pColumnName, Object pValue)
appendColumn(pColumnName);
appendLike();
appendValue(pValue);
* emits a case-insensitive "like" predicate.
* @param pColumnName
* @param pValue
void isLikeIgnoringCase(String pColumnName, Object pValue)
appendColumnUpper(pColumnName);
appendLike();
appendValueUpper(pValue);
* emits an "equals" predicate.
* @param pColumnName
* @param pValue
void isEqualTo(String pColumnName, Object pValue)
appendColumn(pColumnName);
appendEqualTo();
appendValue(pValue);
* emits a case-insensitive "equals" predicate.
* @param pColumnName
* @param pValue
void isEqualToIgnoringCase(String pColumnName, Object pValue)
appendColumnUpper(pColumnName);
appendEqualTo();
appendValueUpper(pValue);
* emits an "unequals" predicate.
* @param pColumnName
* @param pValue
void isNotEqualTo(String pColumnName, Object pValue)
appendColumn(pColumnName);
appendNotEqualTo();
appendValue(pValue);
* emits a case-insensitive "unequals" predicate.
* @param pColumnName
* @param pValue
void isNotEqualToIgnoringCase(String pColumnName, Object pValue)
appendColumnUpper(pColumnName);
appendNotEqualTo();
appendValueUpper(pValue);
* emits a "less than" predicate.
* @param pColumnName
* @param pValue
void isLessThan(String pColumnName, Object pValue)
appendColumn(pColumnName);
appendLessThan();
appendValue(pValue);
* emits a case-insensitive "less than" predicate.
* @param pColumnName
* @param pValue
void isLessThanIgnoringCase(String pColumnName, Object pValue)
appendColumnUpper(pColumnName);
appendLessThan();
appendValueUpper(pValue);
* emits a "less than or equals" predicate.
* @param pColumnName
* @param pValue
void isLessThanOrEqualTo(String pColumnName, Object pValue)
appendColumn(pColumnName);
appendLessThanOrEqualTo();
appendValue(pValue);
* emits a case-insensitive "less than or equals" predicate.
* @param pColumnName
* @param pValue
void isLessThanOrEqualToIgnoringCase(String pColumnName, Object pValue)
appendColumnUpper(pColumnName);
appendLessThanOrEqualTo();
appendValueUpper(pValue);
* emits a "greater than" predicate.
* @param pColumnName
* @param pValue
void isGreaterThan(String pColumnName, Object pValue)
appendColumn(pColumnName);
appendGreaterThan();
appendValue(pValue);
* emits a case-insensitive "greater than" predicate.
* @param pColumnName
* @param pValue
void isGreaterThanIgnoringCase(String pColumnName, Object pValue)
appendColumnUpper(pColumnName);
appendGreaterThan();
appendValueUpper(pValue);
* emits a "greater than or equals" predicate.
* @param pColumnName
* @param pValue
void isGreaterThanOrEqualTo(String pColumnName, Object pValue)
appendColumn(pColumnName);
appendGreaterThanOrEqualTo();
appendValue(pValue);
* emits a case-insensitive "greater than or equals" predicate.
* @param pColumnName
* @param pValue
void isGreaterThanOrEqualToIgnoringCase(String pColumnName, Object pValue)
appendColumnUpper(pColumnName);
appendGreaterThanOrEqualTo();
appendValueUpper(pValue);
* builds a "select" statment.
* @param pQualifierName
* @param pTableName
* @param pCondition
* @param pResult
private void select(String pQualifierName, String pTableName, AbstractEntityCondition pCondition, AbstractEntityResult pResult)
// this statment only reads from the DB
mIsReadOnly = true;
// initialize the table stack using the selected table
// the first push will write " FROM ..."
pushTable(pQualifierName, pTableName);
// build SELECT
StringBuffer sb = new StringBuffer();
// go over all columns
for (int i = 0; i < pResult.mColumnNameList.size(); i++)
// first one has command, others separate with commas
sb.append(i == 0 ? "SELECT DISTINCT TOP 100 " : ", ");
// get column name reference
String aQualifiedColumnName = QualifyColumnName((String) pResult.mColumnNameList.get(i));
// append to the statment
sb.append(aQualifiedColumnName);
// add to the result list
mResultColumnList.add(aQualifiedColumnName);
sb.append(" ");
// insert the "SELECT ..." before the " FROM ..." that was written on the push above
m1Buffer.insert(0, sb);
// do WHERE
if (pCondition != null)
m2Buffer.append(" WHERE ");
// will add to both "FROM..." in first buffer and to "WHERE ..." in second buffer
// this call does most of the hard work, and handles joins to other tables, etc.
appendCondition(pCondition);
// do ORDER BY
for (int i = 0; i < pResult.mOrderByList.size(); i++)
m2Buffer.append(i == 0 ? " ORDER BY " : ", ");
// column name
String aQualifiedColumnName = QualifyColumnName((String) pResult.mOrderByList.get(i));
// direction (ASC or DESC)
m2Buffer.append(aQualifiedColumnName).append(" ").append(pResult.mOrderByDirectionList.get(i));
popTable();
* is currently identical to "select"
* @param pQualifierName
* @param pTableName
* @param pCondition
* @param pResult
private void distinct(String pQualifierName, String pTableName, AbstractEntityCondition pCondition, AbstractEntityResult pResult)
select(pQualifierName, pTableName, pCondition, pResult);
* builds a "count(*)" statement.
* @param pQualifierName
* @param pTableName
* @param pCondition
private void count(String pQualifierName, String pTableName, AbstractEntityCondition pCondition)
// this statment only reads from the DB
mIsReadOnly = true;
// initialize the table stack using the selected table
// the first push will write " FROM ..."
pushTable(pQualifierName, pTableName);
// build and insert "SELECT ..." before the " FROM ..." that was written on the push above
m1Buffer.insert(0, "SELECT COUNT(*) ");
// do WHERE
if (pCondition != null)
m2Buffer.append(" WHERE ");
// will add to both "FROM..." in first buffer and to "WHERE ..." in second buffer
// this call does most of the hard work, and handles joins to other tables, etc.
appendCondition(pCondition);
// finished with this table
popTable();
private void insert(String pQualifierName, String pTableName, Map pValueMap)
// m1Buffer.append("set identity_insert " + pTableName + " off "+ " ").append("INSERT INTO ").append(QualifyTableName(pQualifierName, pTableName)).append(" (");
m1Buffer.append("INSERT INTO ").append(QualifyTableName(pQualifierName, pTableName)).append(" (");
m2Buffer.append(" VALUES (");
// go over all values
boolean isNotFirst = false;
for (Iterator i = pValueMap.keySet().iterator(); i.hasNext();)
if (isNotFirst)
m1Buffer.append(", ");
m2Buffer.append(", ");
isNotFirst = true;
String aColumnName = (String) i.next();
// add the column name to the first part
m1Buffer.append(aColumnName);
// add a "?" to the second part, as well as adding the value to the parameter list
if(pValueMap.get(aColumnName)!= null) {
//Object column= pValueMap.get(aColumnName);
aColumnName=aColumnName.replace( '\'', '`');
m2Buffer.append("'");
m2Buffer.append(pValueMap.get(aColumnName));
m2Buffer.append("'");
} else {
m2Buffer.append(pValueMap.get(aColumnName));
m1Buffer.append(")");
m2Buffer.append(")");
* builds a key-retrieval statement.
//* @param pTypeName
protected void identity(String pTypeName)
m2Buffer.append("SELECT CAST( @@IDENTITY AS "+ pTypeName + ")" );
private void update(String pQualifierName, String pTableName, Map pValueMap, AbstractEntityCondition pCondition)
m1Buffer.append("UPDATE ").append(QualifyTableName(pQualifierName, pTableName)).append(" SET ");
// go over all values
boolean isNotFirst = false;
for (Iterator i = pValueMap.keySet().iterator(); i.hasNext();)
if (isNotFirst)
m1Buffer.append(", ");
isNotFirst = true;
String aColumnName = (String) i.next();
// add the column name to the first part
m1Buffer.append(aColumnName);
m1Buffer.append(" = ");
// add a "?" to the second part, as well as adding the value to the parameter list
if((pValueMap.get(aColumnName)) == null) {
m1Buffer.append(pValueMap.get(aColumnName));
// System.out.println("NUll values are= " + pValueMap.get(aColumnName));
} else{
m1Buffer.append("'");
m1Buffer.append(pValueMap.get(aColumnName));
m1Buffer.append("'");
//System.out.println("Not Null values ARE*********" + pValueMap.get(aColumnName));
// do WHERE
if (pCondition != null)
m2Buffer.append(" WHERE ");
// this will normally be a key condition (one row updated at a time)
appendCondition(pCondition); // will add to "WHERE ..." clause
* builds a "delete" statement.
* @param pQualifierName
* @param pTableName
* @param pCondition
private void delete(String pQualifierName, String pTableName, AbstractEntityCondition pCondition)
m1Buffer.append("DELETE FROM ").append(QualifyTableName(pQualifierName, pTableName));
// do WHERE
if (pCondition != null)
m2Buffer.append(" WHERE ");
// this will normally be a key condition (one row deleted at a time)
appendCondition(pCondition); // will add to "WHERE ..." clause
* will get and save a unique (to this statment) correlation name of the given table
* to be used in the WHERE clause. This is in case the same table joined to
* more than once in the same query.
* @param pTableName
* @return
private String getCorrelationName(String pTableName)
String aCorrelationName = pTableName;
while (mReferenceSet.contains(aCorrelationName))
aCorrelationName = aCorrelationName + "_OTHER";
mReferenceSet.add(aCorrelationName);
return aCorrelationName;
* will prepend the qualifier (if any) to the table name.
* @param pQualifierName
* @param pTableName
* @return
private static String QualifyTableName(String pQualifierName, String pTableName)
return (pQualifierName == null ? "" : pQualifierName + ".") + pTableName;
* will make the given table the current table for parts of the expression below the current node.
* This is used anytime a join is needed.
* @param pQualifierName
* @param pTableName
private void pushTable(String pQualifierName, String pTableName)
String aCorrelationName = getCorrelationName(pTableName);
String aTableDeclaration = QualifyTableName(pQualifierName, pTableName) + " " + aCorrelationName;
m1Buffer.append(m1Buffer.length() == 0 ? " FROM " : ", ");
m1Buffer.append(aTableDeclaration);
mTableList.add(aTableDeclaration);
mTableStack.addFirst(aCorrelationName); // push
* will revert to the previous current table. This is used after a join is finished building.
private void popTable()
mTableStack.removeFirst(); // pop
* gets the table at the top of the stack.
* @return
private String getCurrentTable()
return (String) mTableStack.getFirst();
* will qualify the given column name with the name of the current table.
* @param pColumnName
* @return
private String QualifyColumnName(String pColumnName)
if (SELECT.equals(mStatementType))
return getCurrentTable() + "." + pColumnName;
return pColumnName;
* will qualify the column name and append it to the second buffer.
* @param pColumnName
private void appendColumn(String pColumnName)
m2Buffer.append(QualifyColumnName(pColumnName));
* will qualify the column name and append it to the second buffer, adding the "UPPER" function.
* @param pColumnName
private void appendColumnUpper(String pColumnName)
appendUpper();
appendOpening();
appendColumn(pColumnName);
appendClosing();
* will append "?" to the second buffer and add the value to the parameter list,
* or append "NULL" if the value is null.
* @param pValue
private void appendValue(Object pValue)
if (pValue == null)
m2Buffer.append("NULL");
else
m2Buffer.append("?");
mParameterList.add(pValue);
* will append "?" to the second buffer and add the upper-cased value to the parameter list,
* or append "NULL" if the value is null.
* @param pValue
private void appendValueUpper(Object pValue)
appendValue(null == pValue ? null : pValue.toString().toUpperCase());
* will append the condition to the statement. This initiates a series of calls that walks
* the expression tree and builds the SQL accordingly by calls back to methods of this class.
* @param pCondition
private void appendCondition(AbstractEntityCondition pCondition)
pCondition.buildPredicate(this);
* appends a true condition.
private void appendTrue()
m2Buffer.append("1=1");
* appends a false condition.
private void appendFalse()
m2Buffer.append("1=0");
* appends an opening parenthesis.
private void appendOpening()
m2Buffer.append("(");
* appends a closing parenthesis.
private void appendClosing()
m2Buffer.append(")");
* appends "is null".
private void appendIsNull()
m2Buffer.append(" IS NULL");
* appends "is not null".
private void appendIsNotNull()
m2Buffer.append(" IS NOT NULL");
private void appendAnd()
m2Buffer.append(" AND ");
private void appendOr()
m2Buffer.append(" OR ");
private void appendNot()
m2Buffer.append("NOT ");
private void appendLike()
m2Buffer.append(" LIKE ");
private void appendBetween()
m2Buffer.append(" BETWEEN ");
private void appendEqualTo()
m2Buffer.append(" = ");
private void appendNotEqualTo()
m2Buffer.append(" <> ");
private void appendLessThan()
m2Buffer.append(" < ");
private void appendLessThanOrEqualTo()
m2Buffer.append(" <= ");
private void appendGreaterThan()
m2Buffer.append(" > ");
private void appendGreaterThanOrEqualTo()
m2Buffer.append(" >= ");
* appends the upper-casing function.
private void appendUpper()
m2Buffer.append("UCASE");
* constructs the final SQL expression, builds a prepared statement with it,
* and fills the prepared statement with the parameter values.
* @param pConnection
* @return
* @throws SQLException
PreparedStatement generatePreparedStatement(Connection pConnection) throws SQLException
pConnection.setReadOnly(mIsReadOnly);
String sql = m1Buffer + " " + m2Buffer;
System.out.println("GENERATED SQL = ");
System.out.println(sql);
System.out.println("GENERATED SQL = ");
System.out.println(sql);
System.out.println("PARAMETER LIST = ");
System.out.println(mParameterList);
PreparedStatement aPreparedStatement = pConnection.prepareStatement(sql);
for (int i = 0; i < mParameterList.size(); i++)
aPreparedStatement.setObject(1 + i, mParameterList.get(i));
return aPreparedStatement;
* is an enumerated type.
private static final class StatementType extends AbstractType
private StatementType(String pType)
super(pType);
[i]package firstpro.persistence;
import multnomah.database.ConnectionPool;
import java.sql.*;
import java.util.Date;
import java.util.*;
* is the abstract base class for all generated entity classes.
* It encompasses all functionality not specifically tied to a given field.
public abstract class AbstractEntity
* contains all "open" entities in the system.
* This is to insure that two threads cannot update the same entity at the same time.
* It is a weak hash map, so that entries do not prevent garbage collection if something is left open.
static Map sOpenEntityMap = new WeakHashMap();
* is true when the entity represents a row in a table
boolean mIsBacked = false;
* is true when the entity is in a state that allows updating
boolean mIsMutable = false;
* contains the values that exist in the underlying row -
Creating a string with hiearchical data
This is being done in Crystal 8 will all updates applied.
I have a database with records that are linked to a series of "folders" that are hierarchical in nature as shown below:
Folder 1:
Folder 1.1
Folder 1.1.1
Folder 2
Folder 2.1
All of the folders can have data records attached to them.
The database represents the folder structure in a table with the following attributes:
Folder ID (integer)
Folder Name (String) (such as "Folder 1"
Folder Parent ID (integer)
(other non-related fields)
If the folder is at the root level, then the value in Folder Parent ID is 0, otherwise, it is the Folder ID of the parent folder.
I need to be able to create a string field that displays the path for any given folder that I can insert into a group header or footer, or into a report header if the report deals with records in a single folder. Desired format for the string is:
"Folder 1> Folder 1.1> Folder 1.1.1"
I need to be able to display at least 6 levels of folder indentation.
I have tried several ways to create a formula that will reliably produce the desired string, and can get close, but cannot completely address the problem. My most successful approach was to put multiple instance of the table into the report and link the Folder Parent ID of one level to the Folder ID of the next level down and then use the data to build the string with a formula like this:
Local StringVar Result := {portfolio_master.portfolio_name};
local stringvar ExitLoop := "1" ;
if ExitLoop = "1" then
Result := {portfolio_master_1.portfolio_name} + "> " + Result
else
ExitLoop := "0";
if {portfolio_master_1.parent_id} NE 0 AND ExitLoop = "1" then // NE replaces Crystal not equal symbol which will not show
Result := {portfolio_master_2.portfolio_name} + "> " + Result
else
ExitLoop := "0";
if {portfolio_master_2.parent_id} NE 0 and ExitLoop = "1" then
Result := {portfolio_master_3.portfolio_name} + "> " + Result
else
ExitLoop := "0";
if {portfolio_master_3.parent_id} NE 0 and ExitLoop = "1" then
Result := {portfolio_master_4.portfolio_name} + "> " + Result
else
ExitLoop := "0";
if {portfolio_master_4.parent_id} NE 0 and ExitLoop = "1" then
Result := {portfolio_master_5.portfolio_name} + "> " + Result
else
ExitLoop := "0";
Result;
This formula works so long as the folder in question is exactly 5 levels deep. Changing the nature of the links(inner join, left outer join etc.) between the instances of the table in the Database Expert changes the data that is visible, but I can't find a combination that will show ALL of the needed information for all of the folders.
I understand that this is a brute force approach, and that there must be a different way to skin the cat. My preference would be to "walk the tree" with a loop structure, but I don't see any way to do the needed data look up within the loop.
Any suggestions would be greatly appreciated!
Thanks,
L. Jasmann
Edited by: ljasmann1 on Jun 23, 2010 9:09 PM
Edited by: ljasmann1 on Jun 23, 2010 9:33 PMI have been working to adapt the code provided above to my application. Although I have worked with Crystal for quite a while, this is the first time that I have attempted to use SQL in Crystal... and it is just not working.. probably because I am no doing something very basic.
Here is the code as currently set up in the SQL Formula Editor. Only major difference from the code provided above is that the ID fields are integers instead of strings, and the field that I want to print out is a string field separate from the ID fields.... I have substituted the field names from the table I am referencing for the ones in the code above. The table that I am using has been selected using the Database Expert.
DECLARE @Value int, @pf int, @FolderPath VarChar(MAX)
SET @Value = "portfolio_master"."portfolio_id"
SELECT @pf = "portfolio_master"."parent_id" FROM portfolio_master WHERE "portfolio_master"."portfolio_id" = @Value
SET @FolderPath = "portfolio_master"."portfolio_name"
WHILE @pf <> 0
BEGIN
SET @Value = @pf
SELECT @pf = "portfolio_master"."parent_id" FROM portfolio_master WHERE "portfolio_master"."portfolio_id" = @Value
SET @FolderPath = "portfolio_master"."portfolio_name" + ' > ' + @FolderPath
END
SELECT @FolderPath AS FolderPath
When I test the SQL statement it errors out on the very first statement (the DECLARE statement). If I substitute a different statement in front of the DECLARE statement, it errors on that statement.
Here is the error that I get back. The database is using MS SQL Server.
Error in compiling SQL Expression:
Failed to retrieve data from the database.
Details: ADO Error Code: 0x80040e14
Source: Microsoft OLE db Provider for SQL Server
Description: Incorrect syntax near the keyword u2018DECLAREu2019,
SQL State: 42000
Native Error: 156 [Database Vendor Code: 156].
Any pointers would be greatly appreciated...
Thanks,
Larry Jasmann -
Pasting smart quotes and apostrophes in code view.
Sine upgrading to Dreamweaver CS5, I haven't been able to copy/paste smart quotes and apostrophes into code view without them automatically being converted to straight quotes.
For example, the following sentence (notice the curly quotes):
John’s new song is called “DW Blues”
would get pasted into Code View as:
John's new song is called "DW Blues"
Notice the smart quotes and apostrophe are replaced with single and double ticks, or "straight quotes." While this seems like a minor detail, it's extremely important to our writers and editors to have them appear on the website exactly as typed.
If I do the same copy/paste in Design View (doc type is XHTML Transitional), it appears as:
John's new song is called "DW Blues"
The characters are still replaced, and the straight quotes are then entity encoded (as expected).
This doesn't happen with other valid UTF-8 characters like ™, ®, —, etc., or with any other code editors I've used, including DW CS3.
Is there a hidden preference somewhere to disable this "feature," or is it just a bug?
Please help!It's now 4 years since jsparacio posted this, and I just wanted to let everyone know that I had -- and am still having -- the exact same problem with Dreamweaver CS5 (running first under Windows XP, then Windows 7, and now again with Windows 8.1). So it's not just Macs that are affected.
FWIW, I have set my DW CS5 Paste preferences to the 3rd of 4 options available
1 - Text Only
2 - Text With Structure
3 - Text With Structure Plus Basic Formatting
4 - Text With Structure Plus Full Formatting
in the EDIT > PREFERENCES > Copy/Paste Preferences dialog box.
But the Paste Special command ignores this setting, giving me only the first 2 options from which to choose, with option 2 the default selection for Paste Special operations (options 3 and 4 are grayed out, and can't be selected).
According to David Sawyer McFarland's _Dreamweaver CS5: The Missing Manual_ (O'Reilly Media, 2010), the reason these are grayed out is because I am pasting unformatted ASCII text which I generated in a program editor called "UltraEdit":
"... Choose EDIT > PASTE SPECIAL to open the Paste Special window. Here, you can choose which of the four techniques you wish to use ... sort of. You're limited to what Dreamweaver can paste. For non-Microsoft Office products, you can use only the first two options--the others are grayed out--whereas you can choose from any of the four with text copied from Word or Excel." (McFarland, p. 81)
Regardless of such restrictions, standard copy-and-paste (CTRL+C followed by CTRL+V) works just fine for me using Dreamweaver CS4 (i.e., I have never needed to use the Paste Special command), but with DW CS5, neither Paste command (CONTROL+V or CTRL+SHIFT+V) works properly with typographic/curly/smart quotes.
All typographic quotes -- ASCII-0146 and ASCII-0147 (double quote marks); plus ASCII-0145 and ASCII-0146 (single quote marks, for quotes within a quote) -- are converted to inch (" is entered in the code) and foot (' is entered in the code) marks when I copy-and-paste text with these characters into Dreamweaver's Design View.
When I copy this same plain ASCII text directly into the code (rather than using Design View), typographic double open & close quotes are converted to the inch (") mark, and typographic single open & close quotes are converted to the foot (') mark.
The beginning of this week, I installed Dreamweaver CS5, ver. 11.0, Build 4909 under Windows 8.1 OS on my new Ultrabook. I was hoping that under Windows 8.1, DW CS5's handling of typographic quotes might improve so that I can actually use this program that I purchased 4 years ago. Alas, no such luck: I continue to have the same problem I had when I first upgraded to Dreamweaver CS5 back in August 2010 (then running under Windows XP on my desktop computer).
Back in August 2020, when I first asked about fixes, I was told to change the Title/Encoding setting of Page Properties to "Western European" -- which I tried, but it didn't work then, and it doesn't work now ... and even if it did, it wouldn't be a proper fix for the problem as I have plenty of good reasons for wanting my HTML page Title/Encoding set to Unicode (UTF-8), not Western European ("charset=iso-8859-1").
The ability to copy-and-paste typographic quotes is such a big deal for me that I chose back in August 2010 to revert to Dreamweaver CS4, which I've been using ever since.
It is *very* frustrating that, 4 years later, I still can't use this program, and shall be reverting to DW CS4, yet again.
I continue to be completely flummoxed by this. Every other program with which I am familiar converts non-typographic quotes to typographic/curly/smart quotes ... never have I seen the process automated in reverse! -
What is happening with quote substitution in Mail since Mountain Lion?
What is happening with quote substitution in Mail since Mountain Lion? Now, whenever I type an apostrophe and it's replaced with a smart quote, it creates an unwanted space within my word and starts typing from there. It will also revert the font from my template style to helvetica. Annoying as heck! Any thoughts? Turning off smart quote substition in Mail elimates the error, but elimates the smart qoute, too. I'm stumped.
What is happening with quote substitution in Mail since Mountain Lion? Now, whenever I type an apostrophe and it's replaced with a smart quote, it creates an unwanted space within my word and starts typing from there. It will also revert the font from my template style to helvetica. Annoying as heck! Any thoughts? Turning off smart quote substition in Mail elimates the error, but elimates the smart qoute, too. I'm stumped.
-
How to insert a single quote ........
hi,
How do i insert a sngle quote in a table from sql prompt
suppose if i want to insert Luna's car.
how i do it...
i get error...on sql promptdear satyaki ,
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> desc tst
Name Null? Type
X VARCHAR2(50)
SQL> insert into tst
2 values (q'!luna's car!');
ERROR:
ORA-01756: quoted string not properly terminated
i still get this message
Maybe you are looking for
-
How to set up department ID printing on Canon IR Advanced C2020
We have a few Mac users (ranging from Leopard to Lion) that need to be able to print to our network printers. When I set them up to print to the Toshiba network printers I get the option of "Print Mode" in the printer options and then I can add their
-
HELP-Applications not opening.
Hi, I have an iMac 5,1 running the lastest Tiger OS. My problem seemed to start yesterday evening while installing the Safari 3 beta. As it was installing I deleted the package it was installing from causing it to be unsuccessful. Then I tried re-ins
-
Wish I didn't upgrade to iTunes 10... Having issues.
Ok so I have over 1200 songs on my iTunes and I saw it upgraded so I figure why not... that was a mistake as it is flawed at the moment. Some of my music is in MIDI format which was working fine on the previous version. Now ALL MIDI files read as Qui
-
Can not pick up sound through the Bluetooth headset microphone.
I use a Plantronics Bluetooth headset M55 connect new IPAD (IOS6.0), long press the voice dialing, SIRI from Bluetooth headset microphone can not pick up sound, still or IPAD comes with a microphone to pick up sound, SIRI does not recognize, but canf
-
IPhone 6 release dates Mexico?
Anyone have any idea when the iPhone 6 will be released in Mexico? Are they going to be available with fixed contracts or will we need to buy them separately?