ADO Execute not reading a line of SQL code? - ado.net

My code is below:
var statement = "test_oracle.sql";
F = aqFile.OpenTextFile(statement, aqFile.faRead, aqFile.ctANSI);
F.Cursor = 0;
while(! F.IsEndOfFile()){
s = F.ReadLine();
oResult = Project.Variables.oConnection.Execute_(s);
The first line that "s" reads is: set serverout on size 10000
An error is returned as "ORA-00922: missing or invalid option"
Can anyone provide guidance?

It seems to me that your problem is not with jscript or ado.net, but your sql in that sql file is invalid.
If you look at this page for example:
http://webcache.googleusercontent.com/search?q=cache:N0n7PtpJH4gJ:www.daniweb.com/forums/thread197500.html+ORA-00922:+missing+or+invalid+option&cd=3&hl=en&ct=clnk&gl=us&client=firefox-a
you will see that everyone who got that oracle error got it because of bad syntax.
does that sql execute in a sql client?

It turned out that I was sending a SQL+ statement to a pure SQL environment. This caused it to error on the Set Serverout statement

Related

Why do I get a "unterminated quoted string at or near" error using python postgresql, and not in pgadmin, whith the same request?

I have this query :
INSERT INTO lytnobjects.devices (id,idedge,uniqueref,constructeur,ipaddress,macaddress,
hostname,devicetype,isfirewall,isvisible,iscorporate,
ishub,osname,osversion,datecreation,lasttrafic,
hourtrafic,daytrafic,monthtrafic)
VALUES ('e1e455e98b6ed0037a58d0c1f5dc245a',3183,'TODO','TODO','192.168.143.49',
'b0:0c:d1:bb:36:1c','HPBB361C','Other',False,False,False,False,'','',
'2021-10-29T00:58:53.709','2021-01-01T00:00:00','0/0','0/0','0/0')
When I execute the query using python 3.9 and psycopg2_binary (PostgreSQL), I get an error :
unterminated quoted string at or near "'HPBB361C"
conn is the opened connection to the database (AWS RDS PostgreSQL)
sql is a string with the query above
def SQLExec(conn,sql):
try: cur = conn.cursor()
cur.execute(sql)
except (Exception, psycopg2.DatabaseError) as error:
print("***** ERROR:",error)
cur.close()
If I execute the same request from pgAdmin, I get no error !
There is no missing quote as you can see in the query, and no reason to point an error at this place!
So, I have a string (sql) with the query ("INSERT ...")
I call execute from psycopg2, and get an error: unterminated quoted string at or near "'HPBB361C"
I copy/paste the same string into pgAdmin, and the query is executed with no error
The same string (query)
Any idea why I get an error from my python app?
I am looking for an answer since many hours, but find no explanation, and I don't know how to fix the problem (which doesn't exist for me)
Your help is very appreciated
Thank you
I finaly found the answer!
I build the sql query (string) using some variables coming from various sources, like Amazon S3 for instance.
I assumed that the variable was really a string, with nothing "bizarre" in it... But in fact, sometimes, the "string" was ended with a "\x00" char, that is not displayed, so the string looks just normal :-/
When I execute my query (string) with psycopg2, it receives the extra \x00 char, which ends the string at this place! This is why it says there is a missing quote
I put a trace in the code to display the .encode() version of my string, and it revealed the \x00 at the end. So now I "clean" all string variables used in my queries, just with myvariable.replace("\x00","")
And it works now. There is probably a more conventional way to fix this...
I hope it may help somebody sometime! ;-)

How to correct use $X in jasper??. Problem with parameters and IN clause in JSS

I have a report made with Jaspersoft Studio and in the dataset query I need to use an IN clause, for that I am using the expression "$X{IN ..."
Question # 1: What is the correct type to use for the parameter?
I'm using the following format:
Question # 2: How do I test in the preview?
Parameters screen:
To help, follow the excerpt of where with the parameter being used:
"...Where (($X{IN, db.empresa, paramIdEmpresa}) OR $ P!{ParamIdEmpresa} IS NULL) and (db_view ... "
Error that appears in the preview with the above parameters:
net.sf.jasperreports.engine.JRException: Error executing SQL statement
for: unit1. at com.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport
(ReportController.java:551) at com.jaspersoft.studio.editor.preview.view.control.ReportController.access
(BaseFillHandle.java:135) at java.lang.Thread.run (Thread.java:748)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at
or near "["   Position: 199 at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse
(QueryExecutorImpl.java:2440) at
org.postgresql.core.v3.QueryExecutorImpl.processResults
the problem was in the query and not in jasper...
the correct query is:
where
(($X{IN,db.idempresa, paramIdEmpresa}) OR db.idempresa IS NULL )
thanks to GP...
The best possible way to solve it is simple:
create a parameter called $P!{paramWhere}. of your application
pass the complete where clause with this parameter, e.g. "id = 200"
In your query inside jasper, you put it like this: "... select * from <anywhere> where $P!{paramWhere} ..." and it will magically work.

Progress DB charindex syntax error

I'm trying to create a query in progress DB that gets the name portion off the email address. This is what I have so far:
substring("PUB"."NAME"."INTERNET-ADDRESS", 1, CHARINDEX('#', "PUB"."NAME"."INTERNET-ADDRESS") ) as Name
However, I'm getting a syntax error around the CHARINDEX(...
I'm not a progress guy and knowing SQL is just enough to get me into trouble...
Do you see the error in my ways?
Try this:
substring("PUB"."NAME"."INTERNET-ADDRESS", 1, INSTR("PUB"."NAME"."INTERNET-ADDRESS",'#') ).
Here you have the entire suite of documentation:
https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/1329.openedge-product-documentation-overview

Type Mismatch VBScript Error when getting RecordSet

I am working on some legacy code that is written in Classic ASP / VBSCript.
The code handles the data submitted via a HTML form, and breaks on the following line.
' Get all input questions
Set inputQuestions = getListOfInputQuestionsForPage("additional")
The function getListOfInputQuestionsForPage(pageName) is defined as follows:
Function getListOfInputQuestionsForPage(pageName)
' Instantiate Command
Set objCommand = Server.CreateObject("ADODB.Command")
' Inform Command what Connection to use.
Set objCommand.ActiveConnection = myConn
' SQL Query to run
objCommand.CommandText = "SELECT QUESTION_TABLE.PK_QUESTION AS ""QUESTION_ID"", QUESTION_TABLE.QUESTION AS ""QUESTION"", QUESTION_TABLE.INPUT_TYPE AS ""TYPE"", QUESTION_TABLE.IS_FOR_ALL_CUSTOMERS AS ""FOR_ALL_CUSTOMERS"" FROM QUESTION_TABLE WHERE QUESTION_TABLE.DISPLAY_PAGE = '" & pageName & "' ORDER BY PK_QUESTION ASC"
' Execute SQL and return result
Set getListOfInputQuestionsForPage = objCommand.Execute()
End Function
I find it strange that I am getting the following error:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'getListOfInputQuestionsForPage'
/site/path_to_file/edit_additional.asp, line 110
All I am doing is trying to grab some data from the database. And I know the data exists and a RecordSet is returned.
The error threw me off. The reason why it wasn't working was because the function getListOfInputQuestionsForPage(pageName) did not exist on the same page, and I had to include the file that contained the function definition, which now is very obvious, but because the error is so weird for what I'm trying to do (type mismatch) ... I did not think of that reason at all.
So in short, make sure your classic asp file knows about that function, ie has a link to the file containing the function, or the function is defined in the same file.

Connect to Access database from matlab

I was trying to connect to a Access database from matlab, by following the example given in matlab documentation
1 setdbprefs('DataReturnFormat','cellarray')
2 url = [['jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ='] dbpath];
3 con = database('','','','sun.jdbc.odbc.JdbcOdbcDriver', url);
4 sql = ['select * from ' table_name] ;
5 cursor = exec(con,sql);
6 cursor = fetch(cursor);
7 data.data = cursor.data;
I got the following error when I was requesting data from table A, at line 6, the error message was:
Error using cell
Size inputs must be integers.
Error in cursor/fetch (line 329)
outCursor.Data =
cell(rowLimit,
numberOfColumns);
I tried fetch data from other tables in the same database, it went without problem. What might be the issue?
Please refer to the documentation. fetch must be called with two parameters, connection and query and it returns the result, not a cursor.
Ok, I still hadn't got to the bottom of this yet, but retrieving the data incrementally worked for me, by setting the preference:
setdbprefs('FetchInBatches', 'yes');
setdbprefs('FetchBatchSize', '2');
#Daniel's answer also works fine, but it is difficult to get the column headers that way (let me know if you know how, I tried using another sql query but if did not work for me)...