I am getting 'Variable 'per' not in scope error' error, when I tried to execute below code in Java.
String xq = "declare variable $per1 as document-node(element(*, xs:untyped)) := " +
"fn:parse-xml($per);" +
"declare variable $job1 as document-node(element(*, xs:untyped)) := fn:parse-xml($job);" +
"for $i in $per1//pimergednodes/Get__CompIntfc__CI_PERSONAL_DATAResponse,\n" +
" $j in $job1//jobmergednodes/Get__CompIntfc__CI_JOB_DATAResponse[PROP_EMPLID = $i/PROP_EMPLID]\n" +
"\n" +
" return\n" +
" <emp>\n" +
" {\n" +
" $i/PROP_EMPLID,\n" +
" $i/PROP_BIRTHDATE,\n" +
" <coll_names>\n" +
" {\n" +
" $i/COLL_NAME_TYPE_VW/COLL_NAMES\n" +
" }\n" +
" </coll_names>,\n" +
"\n" +
" $i/PROP_BIRTHDATE/COLL_NAME_TYPE_VW/PROP_FIRST_NAME,\n" +
" $j/COLL_JOB/PROP_DEPTID\n" +
"\n" +
" }\n" +
" </emp>";
XQDataSource xds = new oracle.xquery.xqj.OXQDataSource();
XQConnection conn = xds.getConnection();
XQPreparedExpression pEx = conn.prepareExpression(xq); ==> error raised in this call.
Can somebody help me in fixing this error.
Thanks In Advance,
Maviswa
You reference $per in fn:parse-xml($per), but your code doesn't define that variable anywhere. I see $per1, but no $per. I suspect you'll run into the same problem with $job.
For debugging, print out the xq string so you can see the XQuery by itself without all the Java string escaping, which just adds a lot of noise.
Related
I can't seem to find out what exactly I did wrong here. Seem to be getting a syntax error in my create command inside the createNewTable method.
Android SQLite Insert Error (Syntax error code 1)
I've added my database code:
private static final String KEY_DATE = "date";
private static final String KEY_TIME_IN = "timeCheckIn";
private static final String KEY_TIME_OUT = "timeCheckOut";
private static final String KEY_LATITUDE_IN = "latCheckIn";
private static final String KEY_LONGITUDE_IN = "longCheckIn";
private static final String KEY_LATITUDE_OUT = "latCheckOut";
private static final String KEY_LONGITUDE_OUT = "longCheckOut";
public void createNewTable(){
SQLiteDatabase db = this.getWritableDatabase(int _id);
Log.v("Database", "Adding Check in table: " + _id);
String CREATE_TABLE = " CREATE TABLE " + Integer.toString(_id) + "("
+ KEY_DATE + " TEXT," + KEY_TIME_IN + " TEXT," + KEY_TIME_OUT + " TEXT,"
+ KEY_LATITUDE_IN + " REAL," + KEY_LONGITUDE_IN + " REAL," + KEY_LATITUDE_OUT + " REAL,"
+ KEY_LONGITUDE_OUT + " REAL" + ")";
db.execSQL(CREATE_TABLE);}
My logcat error is as follows:
Caused by: android.database.sqlite.SQLiteException: near "1": syntax error (code 1): , while compiling: CREATE TABLE 1(date TEXT,timeCheckIn TEXT,timeCheckOut TEXT,latCheckIn REAL,longCheckIn REAL,latCheckOut REAL,longCheckOut REAL)
You have a table name that starts with a number. Not sure if SQLite allows it, but in MySQL, if your table name is a number, then for every query, you need to specify the table number with double quotes. Try giving the table name a prefix
SQLite is telling you unescaped table names are not allowed to start with a number, in this case the number 1. If you want to use numbers you must escape the table name with brackets, like so
String CREATE_TABLE = " CREATE TABLE [" + Integer.toString(_id) + "] ("
+ KEY_DATE + " TEXT," + KEY_TIME_IN + " TEXT," + KEY_TIME_OUT + " TEXT,"
+ KEY_LATITUDE_IN + " REAL," + KEY_LONGITUDE_IN + " REAL," + KEY_LATITUDE_OUT + " REAL,"
+ KEY_LONGITUDE_OUT + " REAL" + ")";
I'm having trouble with the log parser, punctually on the use of the function STRCAT parameter with CASE, using log parser the query works perfectly and using a simple STRCAT without CASE the query works even using c#, the problem starts when i use CASE. Am I missing something?
Here's the error:
CLogQueryClass: Error 8007064f: Execute: error parsing query: Syntax Error: : cannot find closing parenthesys for function STRCAT [ SQL query syntax invalid or unsupported. ]
string query = "SELECT " + " STRCAT('" + entry.Name +"'";
query += #", CASE INDEX_OF(SUBSTR(cs-uri-stem,1), '/')
WHEN 'NULL' THEN 'DEFAULTAPPPOOL'
ELSE EXTRACT_TOKEN(cs-uri-stem,1,'/')
END";
query += ") AS APPPOOL";
query += ", '" + Environment.MachineName + "' as server";
query += ", '" + entry.Name + "' as site";
query += ", cs-uri-stem as csUriStem";
query += ", c-ip as cIp, sc-status as scStatus";
query += ", sc-bytes as scBytes";
query += ", cs-bytes as csBytes";
query += ", time-taken as timeTaken";
query += " FROM " + logAddress + "\\" + yesterdayLogName;
// Initialize a LogQuery object
logQuery = new LogQueryClass();
logRecordSet = logQuery.Execute(query,new COMIISW3CInputContextClass());
//SHOWS RESULT
for (; !logRecordSet.atEnd(); logRecordSet.moveNext())
{
logrecord = logRecordSet.getRecord();
int i = 0;
while (i < 9)
{
Console.WriteLine(logrecord.getValue(i));
i++;
}
Thanks
First, it looks like you are mixing types. The CASE INDEX_OF(SUBSTR(cs-uri-stem,1), '/') WHEN 'NULL' compares an integer to string. This should be:
CASE INDEX_OF(SUBSTR(cs-uri-stem,1), '/')
WHEN NULL THEN 'DEFAULTAPPPOOL'
ELSE EXTRACT_TOKEN(cs-uri-stem,1,'/')
END
The error complains about finding the close parenthesis, but I've found that parsing errors can result in misleading error messages with LogParser.
Second, I've tested the following in C# targeted at .NET 3.5 (4.0 had an issue with embedded type. Similar to this...):
string logAddress = "C:\\Path\\to\\consolidatedFile";
string entryName = "blah";
string yesterdayLogName = "fileName.log";
string query = "SELECT " + " STRCAT('" + entryName + "'"
+ ", CASE INDEX_OF(SUBSTR(cs-uri-stem,1), '/') "
+ "WHEN NULL THEN 'DEFAULTAPPPOOL' "
+ "ELSE EXTRACT_TOKEN(cs-uri-stem,1,'/') "
+ "END"
+ ") AS APPPOOL"
+ ", '" + Environment.MachineName + "' as server"
+ ", '" + entryName + "' as site"
+ ", cs-uri-stem as csUriStem"
+ ", c-ip as cIp, sc-status as scStatus"
+ ", sc-bytes as scBytes"
+ ", cs-bytes as csBytes"
+ ", time-taken as timeTaken"
+ " FROM " + logAddress + "\\" + yesterdayLogName;
// Initialize a LogQuery object
COMW3CInputContextClassClass ctx = new COMW3CInputContextClassClass();
//LogQueryClass logQuery = new LogQueryClass();
LogQueryClass logQuery = new LogQueryClassClass();
//ILogRecordset logRecordSet = logQuery.Execute(query, new COMIISW3CInputContextClass());
ILogRecordset logRecordSet = logQuery.Execute(query, ctx);
//SHOWS RESULT
for (; !logRecordSet.atEnd(); logRecordSet.moveNext())
{
ILogRecord logrecord = logRecordSet.getRecord();
int i = 0;
while (i < 9)
{
Console.WriteLine(logrecord.getValue(i));
i++;
}
}
This ran successfully and return results. I commented out the lines initially presented since when I used them nothing returned on the console. That might be a difference of the code not presented. Finally, I substituted a string entryName for the entry.Name object assuming that it returns a string.
I hope this helps.
I have this 2 SQLite scripts:
both tested by direct input into SQLite.
def getOutgoingLinks(self, hostname):
t = (hostname,)
result = self.__cursor.execute("SELECT url.id, hostname.name, url.path, linking_to.keyword, siteId.id " +
"FROM url, hostname, linking_to, " +
"(SELECT url.id FROM url, hostname " +
"WHERE hostname.name = (?) " +
"AND hostname.id = url.hostname_id " +
") AS siteId " +
"WHERE linking_to.from_id = siteId.id " +
"AND linking_to.to_id = url.id " +
"AND url.hostname_id = hostname.id", t)
result = result.fetchall()
return result
def getIncommingLinks(self, hostname):
t = (hostname,)
result = self.__cursor.execute("SELECT url.id, hostname.name, url.path, linking_to.keyword, siteId.id " +
"FROM url, hostname, linking_to, " +
"(SELECT url.id FROM url, hostname " +
"WHERE hostname.name = (?) " +
"AND hostname.id = url.hostname_id " +
") AS siteId " +
"WHERE linking_to.to_id = siteId.id " +
"AND linking_to.from_id = url.id " +
"AND url.hostname_id = hostname.id", t)
result = result.fetchall()
return result
The getIncommingLinks() methond works very well, but getOutgoingLinks() causes an infinite Loop when python trys to execute the SQL statement. Any ideas what went wrong?
Rewrite your Select statements without select ...( Select ...) - thats very bad style. The result may solve your problem.
If by infinite loop you mean that the function doesnt ever get to return a value, I had the same problem.
Found the solution in Why python+sqlite3 is extremely slow?. With large tables it becomes a performance issue with the version shipped with python 2.7. I solved it by upgrading sqlite3 as specified here: https://stackoverflow.com/a/3341117/3894804
I am using the crystal report, in that i am using code like below to show the SQL data into the crystal report,
string req = "{View_EODPumpTest.ROId} IN " + str + " AND " + "({View_EODPumpTest.RecordCreatedDate}>=date(" + fromDate.Year + " , " + fromDate.Month + " , " + fromDate.Day + ")" + "AND" + "{View_EODPumpTest.RecordCreatedDate}<=date(" + toDate.Year + " , " + toDate.Month + " ," + toDate.Day + " ))";
ReportDocument rep = new ReportDocument();
rep.Load(Server.MapPath("PumpTestReport.rpt"));
DateTime fromDate = DateTime.Parse(Request.QueryString["fDate"].ToString());
DateTime toDate = DateTime.Parse(Request.QueryString["tDate"].ToString());
CrystalReportViewer_PumpTest.ReportSource = rep;
//CrystalReportViewer1.SelectionFormula = str;
rep.RecordSelectionFormula = str;
CrystalDecisions.CrystalReports.Engine.TextObject from = ((CrystalDecisions.CrystalReports.Engine.TextObject)rep.ReportDefinition.ReportObjects["txtFrom"]);
from.Text = fromDate.ToShortDateString();
CrystalDecisions.CrystalReports.Engine.TextObject to = ((CrystalDecisions.CrystalReports.Engine.TextObject)rep.ReportDefinition.ReportObjects["txtTO"]);
to.Text = toDate.ToShortDateString();
//Session["Repo"] = rep;
CrystalReportViewer_PumpTest.RefreshReport();
after running my application it executes fine with no exception but such error i am getting,
A number range is required here. Error in File C:\DOCUME~1\Delmon\LOCALS~1\Temp\PumpTestReport {14E557A7-51B3-4791-9C78-B6FBAFFBD87C}.rpt: Error in formula . '{View_EODPumpTest.ROId} IN ['15739410','13465410'] AND ({View_EODPumpTest.RecordCreatedDate}>=date(2010 , 12 , 1)AND{View_EODPumpTest.RecordCreatedDate}<=date(2010 , 12 ,25 ))' A number range is required here.
error.
what i will do for this?
Please help,
Thanks in advance
You've not included the definition of 'str' in your code sample, but I'd guess that it's a comma-separated set of values. For Crystal to interpret this you have to put the value range inside [ and ], not the standard ( and ) you might use in SQL. Eg,
{View_EODPumpTest.ROId} IN [1,2,3,4,5,6]
string updateIncomeData = #"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , ?, ?,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
This parametrized query gives me an exception that tells me that there is an error near "?". What is the error. Please correct it.
I am purely guessing but should it be year.selecteditem? not selectedindex?
I don't understand why you would want to mix up the parameter substitution.
Specify all five columns as parameters and set the values that way.
"INSERT INTO TEAM_FUNDS_DETAILS " +
"(COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR) " +
"VALUES(? , ?, ?,?, ?)"
You must set the parameterized values (the ones with the question mark). Here is a similar example in VB.NET:
' Make a Command for this connection
' and this transaction.
Dim cmd As New OleDb.OleDbCommand( _
"SELECT * FROM People WHERE FirstName=? AND " & _
"LastName=?", _
connUsers)
' Create parameters for the query.
cmd.Parameters.Add(New _
OleDb.OleDbParameter("FirstName", first_name))
cmd.Parameters.Add(New OleDb.OleDbParameter("LastName", _
last_name))
If you don't want to use parameterized queries, just substitute the question mark with the default value, or the variable with the value:
string updateIncomeData = #"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , '', 0,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
or
string updateIncomeData = #"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , '" + myComponentName + "', " + myComponentAmount,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
ddlMonth.SelectedItem.Value