Oracle SQL Error: How to Debug this issue - sql

Using:
select name, id
from "TEST"
where id :2
AND name :1
order by id desc
I am getting ORA: 00904 "TEST"."NAME": invalid identifier error but the wierd part is that I have checked my test table and it does not have NAME field but it has name field, I have also checked all the references which is made from that table and all other constraints but still it gives me same error. I do not know why, is there a way where I can check all the columns of the database for NAME column name or any other debuggind approach recommended would be highly welcomed.
DESC TEST;
Name Null Type
id NOT NULL NUMBER(11)
name VARCHAR2(29)
2 rows selected
EDIT
DESC TEST
Name Null Type
------------------------------ -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID NOT NULL NUMBER(11)
NAME VARCHAR2(29)
2 rows selected
Java Code
public String searchExecute(HttpServletRequest req, javax.servlet.ServletContext ctx, String nextPage){
// ESCA-JAVA0266:
System.out.println("This is Awesome");
// ESCA-JAVA0266:
System.out.println("id:"+req.getParameter("s_1985"));
// ESCA-JAVA0266:
System.out.println("name:"+req.getParameter("s_1984"));
boolean bDisplayAll = StringUtils.stringToBoolean(req.getParameter("display_all"));
if(bDisplayAll)
// ESCA-JAVA0034:
req.setAttribute("c_display_all", "Y");
req.setAttribute("c_search_submitted", "Y");
return nextPage;
}
JSP Code
<%# page import="att.leadx.dbutils.AppUtils" %>
<%# page import="java.util.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1">
</head>
<link rel=stylesheet type=text/css href="leadx.css">
<body bgcolor="#FFFFFF"><BR>
<form NAME="forma" ACTION="dispatcher" METHOD="post">
<INPUT TYPE="hidden" name="action" value="">
<input type=hidden name="c_master" value="TEST_SEARCH">
<%
request.setAttribute("c_form", "TEST_SEARCH");
request.setAttribute("c_top_title","PROFILE > TEST_SEARCH");
request.setAttribute("c_top_link_image","images/setup_sm.gif");
request.setAttribute("c_top_link_action","user.search.setup");
request.setAttribute("c_top_link_app_func","search_setup");
request.setAttribute("c_top_link_alt_display","Setup search criteria");
%>
<jsp:include page="j_custom_search.jsp" flush="true" />
<table width="94%" border="0" cellspacing="1" cellpadding="3" align=center>
<tr>
<td colspan=4 align=center>
<INPUT TYPE="submit" value="Search" class=prismsbutton onclick="document.forma.action.value ='cep.project.search.execute'">
</td>
<td colspan=4 align=center>
<INPUT TYPE="button" value="Cancel" class=prismsbutton onclick="window.history.back()">
</td>
</tr>
</table>
</form>
<form NAME="formd" ACTION="dispatcher" METHOD="post">
<input type="hidden" name="c_jsp" value="j_test_dynamic_search.jsp">
<%
request.setAttribute("c_master", "TEST_SEARCH");
request.setAttribute("c_html_form","formd");
request.setAttribute("c_list_id","1984");
request.setAttribute("c_search_form","TEST_SEARCH");
Object args[] = att.utils.DataStore.arg(att.leadx.dbutils.AppUtils.getLoggedInUser(request), att.utils.DataStore.TYPE_NUMERIC);
request.setAttribute("c_args", args);
if (att.utils.StringUtils.stringToBoolean((String)request.getAttribute("c_search_submitted"))){
%>
<jsp:include page="j_master_detail_dlist.jsp" flush="true" />
<%
}
%>
</form>
<%!
private void o(String s){
if (att.leadx.dbutils.AppUtils.inDebug())
System.out.println("[J_USER_SEARCH.JSP] " + s);
}
%>
SQL Statement
select name, id from TEST where name = :1 AND id = :2 order by id desc
Error Message
Aug 16, 2010 5:22:21 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.sql.SQLException: ORA-00936: missing expression
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1451)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:651)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2110)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2324)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:627)
at att.utils.DataStore.retrieve(DataStore.java:724)
at org.apache.jsp.j_005fmaster_005fdetail_005fdlist_jsp._jspService(j_005fmaster_005fdetail_005fdlist_jsp.java:566)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:659)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:565)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:493)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:965)
at org.apache.jsp.j_005ftest_005fdynamic_005fsearch_jsp._jspService(j_005ftest_005fdynamic_005fsearch_jsp.java:102)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:659)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:457)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)
at att.leadx.nav.Dispatcher.service(Dispatcher.java:113)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
Thanks

SELECT *
FROM ALL_TAB_COLS
WHERE UPPER(COLUMN_NAME) = 'NAME';
will show you all columns called NAME
EDIT:
Based on your comment, aren't you missing the operators in your WHERE clause? ie =
select name, id
from "TEST"
where id :2 -- Surely you mean: id = :2
AND name :1 -- Surely you mean: name = :2
order by id desc
EDIT 2:
Based on the SQL*Plus output, it looks like you've created the table with lower-case column names. Whilst this is possible and valid it's usually just hard work. I'd recreate the columns with upper case names. (as Alex said)
EDIT 3:
I think...
SELECT "id", "name"
FROM TEST
WHERE "id" = :1
AND "name" = :2
ORDER BY "id" desc;
should work

It's a good idea not to surround column and table names with double-quotation marks unless you are know what you are doing and confident you need that.
In Oracle, database object names (including table and columns) are not case-sensitive and assumed upper-case unless you include them into double-quotes.
E.g, if a table created as TEST, it can be referred to as test, Test or TesT or "TEST".
But if it is created as "Test", you will only be able to refer to it as "Test" (in double quotation marks). All the other ways will result in "invalid identifier" error.

Related

Start Order by data from table that is found in another table

My question may be not easy to explain but I am going to do my best.
I have 3 tables :
medicine
patient
patient_medicine
the third table contains 3 columns :
auto increment (id)
medicine_id
patient_id
I make a query that display all data in medicine table and if there is a patient id found in patient_medicine table I check it and those that are not found are not checked.
A- controller
public function showPatientMedicine()
{
$data['patient_id']=$this->input->post('patient_id');
$data['medicine'] = $this->model_admin->medicine();
$this->load->view('admin/show-Patient-Medicine',$data);
}
B- VIEW
<table>
<thead>
<tr>
<th>List</th><th></th>
</tr>
</thead>
<tbody>
<?php
foreach($medicine as $row){
$patient_med=$this->db->select('medicine_id')
->where('patient_id',$patient_id)
->where('medicine_id',$row->id)
->get('patient_medicine')->row('medicine_id');
if($row->id==$patient_med){
$checked="checked";
} else {
$checked="";
}
?>
<tr>
<td>
</td>
<td>
<input type='checkbox' value="<?=$row->id?>" <?=$checked?> />
</td>
</tr>
<?php
}
?>
</tbody>
</table>
THIS QUERY SHOWS ME ALL MEDICINES AND CHECK THE MEDICINES THAT ARE FOUND IN PATIENT_MEDICINE TABLE
MY QUESTION IS :
HOW CAN I SHOW ALL MEDICINES THAT ARE CHECKED IN THE FIRST POSITION OR HOW TO ORDER BY CHECKED CHECKBOX ?
THANK YOU IN ADVANCE.
Try this,
SELECT * FROM `medicine` as a left join (select medicine_id,patient_id from patient_medicine where patient_id = 2) as b on a.id = b.medicine_id
Put the above query in your controller, it will automatically sort the result based on patient id, if patient details found. it will return null for all other details in rows except medicine details.
So you can just
<?php foreach($medicine as $row){ ?>
<input type='checkbox' value="<?=$row->id?>" <?php echo !is_null($row->patient_id)?'checked':''; ?> />
<?php } ?>

Filter assetset by id Webcenter Sites

I need filter a assetset by id, my asset type is a flex asset. I never do this by id before and I'm stucked with this.
This is my code:
<publication:load name="pub" field="name" value='<%= ics.GetVar("site") %>'/>
<publication:get name="pub" field="id" output="siteId"/>
<%-- Content:getasset data is a custom tag to obtain attributes form a concrete asset --%>
<content:getassetdata prefix="lov" id='<%= ics.GetVar("assetid") %>' type="LOV" attributes="LOVUser"/>
<listobject:create name="powerObject" columns="power"/>
<c:forEach items="${lov.LOVUser}" var="usu">
<listobject:addrow name="powerObject"><listobject:argument name="power" value="${usu.id}"/></listobject:addrow>
</c:forEach>
<listobject:tolist name="powerObject" listvarname="powerList"/>
<%-- A this time, I have a powerList with all the IDs that I need to get --%>
<searchstate:create name="ssLovElements"/>
<searchstate:addstandardconstraint name="ssLovElements" attribute="id" list="powerList" />
<assetset:setsearchedassets name="asElementLovs" constraint="ssLovElements" assettypes="elementLOV" site='<%= ics.GetVar("siteId") %>' fixedlist="false"/>
<%-- Correct number --%>
<br/> N.Filas powerList: <ics:listget listname="powerList" fieldname="#numRows"/>
<%-- Incorrect number (Because constraint haven't effect --%>
N.Filas aslist: <ics:listget listname="aslist" fieldname="#numRows"/>
First list have 60 elements, second list have 600. I need use this constraint to extrac only wanted elements and get their attributes with multiplevalues, but I dont get working this. Any help? Thanks
I think you should use the Asset API instead of jstl tag. See the doc :
Session ses = SessionFactory.getSession();
AssetDataManager mgr = (AssetDataManager) ses.getManager(AssetDataManager.class.getName());
Condition c = ConditionFactory.createCondition( "id", OpTypeEnum.GREATER_THAN, long);
Query query = new SimpleQuery( "elementLOV", null, c, Arrays.asList( "name", ) );
query.getProperties().setIsBasicSearch( true );

Dreamweaver ASP command INSERT INTO not passing value

Hi I am trying to create an INSERT INTO script in Dreamweaver Command and ASP.
If I use a static value it works fine, but when I try to declare a variable I get the following error message
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Sybase][ODBC Driver][Adaptive Server Anywhere]Primary key for table 'testing'
is not unique
/coding/Untitled-3.asp, line 30
Now the reason it is telling me the primary key is not unique is it is passing a null value, rather than the value of my field. Code below;
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim Command1__product
Command1__product = Request.Form("product")
%>
<!--#include file="Connections/Conn_PSCRM_Demo.asp" -->
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
Set Command1 = Server.CreateObject ("ADODB.Command")
Command1.ActiveConnection = MM_Conn_PSCRM_Demo_STRING
Command1.CommandText = "INSERT INTO testing (prodref) VALUES (?)"
Command1.Parameters.Append Command1.CreateParameter("product", 201, 1, 25, MM_IIF(Request.Form("Field1") , Request.Form("Field1") , Command1__product & ""))
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="form" id="form">
<label for="Field1"></label>
<input name="Field1" type="text" id="Field1" value="33399">
</form>
</body>
</html>
According to my comment - you'll have to check if your form has been posted or your site has just been initially loaded. In your question the code will be executed everytime the site has been loaded - that's why it works when you provide hardcoded values.
Anything like this code will do the trick
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
If Request.Form("SUBMITBUTTON") <> "" then
Dim Command1__product
Command1__product = Request.Form("product")
' all your code goes here!
%>
Bit of a rookie error, I wasn't declaring the form variable.
I have added a Bindings Request.Form and all is working.

ASP.NET Database error

I am trying to follow a tutorial online and I have followed the steps exactly however i keep getting an error when trying to write to a database.
Here Is the code for a simple form
#{
var name = string.Empty;
var email = string.Empty;
var subject = string.Empty;
var message = string.Empty;
if (IsPost){
name = Request["txtName"];
email = Request["txtEmail"];
subject = Request["txtSubject"];
message = Request["txtMessage"];
var db = Database.Open("FormAndDataDB");
db.Execute("INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent) " +
"VALUES (#0, #1, #2, #3, #4)", name, email, subject, message, DateTime.Now);
}
}
<doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="contact.cshtml" method="POST">
<p>
<label for="txtName">Name:</label><br />
<input type="text" name="txtName" id="txtName" value="#name"/>
</p>
<p>
<label for="txtEmail">Email:</label><br />
<input type="text" name="txtEmail" id="txtEmail" value="#email" />
</p>
<p>
<label for="txtSubject">Subject:</label><br />
<input type="text" name="txtSubject" id="txtSubject" value="#subject" />
</p>
<p>
<label for="txtMessage">Message:</label><br />
<textarea name="txtMessage" id="txtMessage" cols="40" rows="10" >#message</textarea>
</p>
<p>
<input type="submit" value="send" />
</p>
</form>
</body>
</html>
Here is the error i get in visual studio on attempt of execution of the SQL insert statement:
"An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll but was not handled in user code"
This is the error text returned from SQL and displayed on the webpage:
"The column cannot contain null values. [ Column name = ID,Table name = ContactLog ]"
I have filled out the form completely
Your errors in the question notwithstanding, the problem seems to be that you've got a table (contactLog) with a column (id) that has the NOT NULL attribute attached to it. You are trying to insert a row without a value in said column, and that is causing this error.
To fix this either insert a value into the [ID] column or set the identity attribute to TRUE instead of FALSE on said column and allow it to autogenerate / autoincrement.
My assumption is that even when you fixed the syntax of the insert statement you still couldn't process the insert properly.
You have five columns, but only 3 values.
Your statement is
INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent)
VALUES (#0, #1, #3)
What happened to #2 and #4?
Maybe you need
db.Execute("INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent) "+
"VALUES (#0, #1, #2, #3, #4)",
name, email, subject, message, DateTime.Now);

SQL select statement with AND and OR operators issue

I'm fetching records from the SQL Server 2000 database using Classic ASP. This is what the code I have used.
ASP Code:
<form name="search" method="post" onsubmit="return attention();">
<table width="60%" border="0" cellpadding="2" cellspacing="0" style="margin:0 auto">
<tr>
<td colspan="2"><h1 style="color:#003399;">Search for Certificate of Analysis</h1></td>
</tr>
<tr>
<td valign="bottom">Product number <sup style="color:#EE0000;font-size:1.3em">*</sup></td>
<td valign="bottom">Lot number</td>
</tr>
<tr>
<td width="30%" valign="top">
<input type="text" name="input1" size="20"/>
</td>
<td valign="top">
<input type="text" size="20" name="input2"/>
<input style="background-color:#ffffff;border:0px;cursor:pointer" size="10" type="submit" name="sub" value=">>" />
</td>
</tr>
</table>
<%
if request.Form("sub") <> "" then
Dim fname, lname
fname= request.Form("input1")
lname= request.Form("input2")
session("n") = fname & lname
sql = "Select * from search where cat_no_batch_no LIKE '"&request.Form("input1")&"%' OR cat_no_batch_no='"&session("n")&"'"
rs.open sql, con, 1, 2
if rs.eof then
response.write("Please provide a valid Cat No.")
else
do while not rs.eof
%>
<table border="1" cellpadding="5" cellspacing="0" width="60%" style="margin:0 auto; border-collapse:collapse;border-color:#999999">
<tr>
<td width="50%"><%=rs("cat_no_batch_no")%></td>
<td width="10%">Click to open <a target="_blank" href="http://localhost/search1/<%=rs("pdf_path")%>"><%=rs("cat_no_batch_no")%></a></td>
</tr>
</table>
<%
rs.movenext
loop
end if
rs.close
end if
%>
</form>
Above the LIKE statement works as expected and displays multiple records which contains similar Cat No..
Issue rises when I input a Cat No in first Input box and Lot Number in another. My desired output should have been just a single record to display as I have given Cat No. and Lot Number , but it shows multiple records.
I have provided the images to be more clear.
In this image below I have put 6106021 as the product number so it displays two entries.
In this image I have put 6106021 as the product number and 218111 as the Lot Number, it shows two entries instead of 1. This is what the issue, it should show one entry as Lot number are unique while cat number can be the same.
Read your question to yourself and think about what you are saying:
You state "My desired output should have been just a single record to display as I have given Cat No. and Lot Number"
But in your SQL you write where cat_no_batch_no LIKE '"&request.Form("input1")&"%' OR cat_no_batch_no='"&session("n")&"'
The key words are AND vs. OR
In your mind you are thinking both conditions must be true, but your query says otherwise. If you want both conditions to be true then you must use the AND operator.
Naoki is on to something - you are going to have to modify your SQL depending upon which criteria are specified.
I guess you can write two separate SQL queries, according as the "Lot number" is provided or not.
Your code may goes like below:
if lname = "" then
sql = "Select * from search where cat_no_batch_no LIKE '"&request.Form("input1")&"%'"
else
sql = "Select * from search where cat_no_batch_no LIKE '"&session("n")&"%'"
end if
I hope this could help