You need to sign in to do that
Don't have an account?
d.tejdeep@nicomatic.in
System.Queryexceptionerror
Controller:
public with sharing class textInputsCon {
public String inputText1{get;set;} // input text1 value from vf
public String inputText2{get;set;} // input text2 value from vf
Public string operator{get;set;}
public list<Quote__c> quo{get;set;} //this is will hold data to be displayed on page
string query='select from1__c,Quote_number_new__c from quote__c';
public void showlist(){ //do not return anything
if(inputText1 != null){
query += 'WHERE Quote_number_new__c ' + operator + ' : inputText1';
}
quo = database.query(query);
}
}
error:
System.QueryException: unexpected token: =
Error is in expression '{!showlist}' in component <apex:commandButton> in page test
Class.textInputsCon.showlist: line 12, column 1
public with sharing class textInputsCon {
public String inputText1{get;set;} // input text1 value from vf
public String inputText2{get;set;} // input text2 value from vf
Public string operator{get;set;}
public list<Quote__c> quo{get;set;} //this is will hold data to be displayed on page
string query='select from1__c,Quote_number_new__c from quote__c';
public void showlist(){ //do not return anything
if(inputText1 != null){
query += 'WHERE Quote_number_new__c ' + operator + ' : inputText1';
}
quo = database.query(query);
}
}
error:
System.QueryException: unexpected token: =
Error is in expression '{!showlist}' in component <apex:commandButton> in page test
Class.textInputsCon.showlist: line 12, column 1
BTW, it's a bad idea to append operator to the query without validating it on the server side. Client could inject anything into that parameter (Search the web for "SQL injection"). You are somewhat protected by "with sharing" keyword, I would still do a whitelist validation of operator value to be on the safer side.
Seems you for got to give a space before the start of WHERE clause. check it
Regards,
- Harsha
i had one more problem .it would be more helpful if you correct that one ???
Controller:
public with sharing class textInputsCon {
public String inputText1{get;set;} // input text1 value from vf
public String inputText2{get;set;} // input text2 value from vf
public String inputText3{get;set;} // input text1 value from vf
public String inputText4{get;set;}
Public string operator{get;set;}
public list<Quote__c> quo{get;set;} //this is will hold data to be displayed on page
string query='select from1__c,Quote_number_new__c from quote__c ';
public void showlist(){ //do not return anything
if(inputText1 <> NULL ){
//&& inputText4 ==Null){
query += 'WHERE ' + inputText3 + ' ' + operator + ' : inputText1 ' ; }
if(inputText2 <> NULL ){
query +=' and '+ inputText4 + ' ' + operator + ' : inputText2'; }
quo = database.query(query);
}
}
vf code:
<apex:page showHeader="false" sidebar="False" controller="textInputsCon">
<apex:form >
Input Text1 <apex:inputText value="{!inputText1}"/>
<apex:selectList id="inputText3" value="{!inputText3}" size="1">
<apex:selectOption itemValue="Quote_number_new__c" itemLabel="Quote Number"/>
<apex:selectOption itemValue="From1__c" itemLabel="from"/>
<apex:selectOption itemValue="Null" itemLabel="None"/>
</apex:selectList>
Input Text2 <apex:inputText value="{!inputText2}"/>
<apex:selectList id="inputText4" value="{!inputText4}" size="1">
<apex:selectOption itemValue="Quote_number_new__c" itemLabel="Quote Number"/>
<apex:selectOption itemValue="From1__c" itemLabel="from"/>
<apex:selectOption itemValue="From1__c" itemLabel="None"/>
</apex:selectList>
<apex:selectList id="operator" value="{!operator}" size="1">
<apex:selectOption itemValue="=" itemLabel="Equal"/>
<apex:selectOption itemValue="!=" itemLabel="Not equal to"/>
<apex:selectOption itemValue="<=" itemLabel="Less than"/>
</apex:selectList>
<apex:commandButton value="list" action="{!showlist}"/>
<apex:pageBlock >
<apex:pageBlockTable value="{!quo}" var="q">
<apex:column value="{!q.Quote_Number_New__c}"/>
<apex:column value="{!q.From1__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
BY entering the text1 and text2 it is showing the results:
if(inputText1 <> NULL ){
//&& inputText4 ==Null){
query += 'WHERE ' + inputText3 + ' ' + operator + ' : inputText1 ' ; }
if(inputText2 <> NULL ){
query +=' and '+ inputText4 + ' ' + operator + ' : inputText2'; }
quo = database.query(query);
By entering the text1 it is filtering by not text two:
if(inputText1 <> NULL ){
//&& inputText4 ==Null){
query += 'WHERE ' + inputText3 + ' ' + operator + ' : inputText1 ' ; }
if(inputText2 <> NULL && inputtext1==NULL ){
query +=' and '+ inputText4 + ' ' + operator + ' : inputText2'; }
quo = database.query(query);
i need that in such a way that if i entered the text1 it has to show the results of text 1 and if i entered the data of text2 .it has to show the data of text2.if i entered the both .it has to filter by both can you correct my program?