Invalid Identifier When Editing an ADO Query - oracle10g

I have an ADO query that I use to gather data and later use to update that data. (Embarcadaro C++ Xe2 & Oracle 10g). Rownum (aliased to pgnum) is also selected and in this query. When posting data edited via this query, I receive invalid identifier "pgnum". This seems to be an issue specifically with ADO as this same code worked in previous versions of our software. We recently converted all our queries to ADO from Tquery (old BDE Driven). Adding "pgnum" to the queries persistent fields does not help. Any advice would be greatly appreciated.
Table1 is an ADOQuery.
sql = "SELECT ROWNUM PGNUM, A.* FROM DOCUMENT_IMAGE A WHERE DOCNO = " + String(Form1->qryDocumentDOCNO->AsInteger) + " ORDER BY ROWNUM ";
Table1->Close();
Table1->SQL->Clear();
Table1->SQL->Add(sql);
Table1->Open();
Table1->Edit();
Table1IMAGE->LoadFromFile(filepath);
if (Table1->Modified){
Table1->Post();
}

After tons of research and testing I could get nothing to work while keeping rownum in the query. I'm honestly not sure what it was accomplishing, I took this project over from someone else. Anyway, I removed rownum and used a different field to order the query by, problem solved.

Related

Faster/efficient alternative to IN clause in custom/native queries in spring data jpa

I have a custom query along these lines. I get the list of orderIds from outside. I have the entire order object list with me, so I can change the query in any way, if needed.
#Query("SELECT p FROM Person p INNER JOIN p.orders o WHERE o.orderId in :orderIds)")
public List<Person> findByOrderIds(#Param("orderIds") List<String> orderIds);
This query works fine, but sometimes it may have anywhere between 50-1000 entries in the orderIds list sent from outside function. So it becomes very slow, taking as much as 5-6 seconds which is not fast enough. My question is, is there a better, faster way to do this? When I googled, and on this site, I see we can use ANY, EXISTS: Postgresql: alternative to WHERE IN respective WHERE NOT IN or create a temporary table: https://dba.stackexchange.com/questions/12607/ways-to-speed-up-in-queries-under-postgresql or join this to VALUES clause: Alternative when IN clause is inputed A LOT of values (postgreSQL). All these answers are tailored towards direct SQL calls, nothing based on JPA. ANY keyword is not supported by spring-data. Not sure about creating temporary tables in custom queries. I think I can do it with native queries, but have not tried it. I am using spring-data + OpenJPA + PostgresSQL.
Can you please suggest a solution or give pointers? I apologize if I missed anything.
thanks,
Alice
You can use WHERE EXISTS instead of IN Clause in a native SQL Query as well as in HQL in JPA which results in a lot of performance benefits. Please see sample below
Sample JPA Query:
SELECT emp FROM Employee emp JOIN emp.projects p where NOT EXISTS (SELECT project from Project project where p = project AND project.status <> 'Active')

SQL and Crystal Reports in ADO.NET

I've created crystal reports using ADO.NET datasets, the reports are working just fine but now my question is:.
How do I make my report to get data from multiple tables because I tried using INNER JOIN method and it didn't work,it displayed nothing....
So can someone give me an idea on how to make crystal report to get data from multiple tables using VB.NET? And tell me the purpose of "SQL Expression" in Crystal Reports.
Please, Thank You.
Con.close
Con.open
Query = "select customers.cust_id,customers.cust_fname,customers.cust_lname,invoices.inv_id,invoices.inv_date from customers Inner Join Invoices ON customers.cust_id = invoices.cust_id where customers.cust_id = '"& txtcustnr.text & "'"
Con.close
Read this to get you started on the purpose of SQL Expression Fields. And without any code for your table joins nobody will be able to help you out.
EDIT:
Instead of where customers.cust_id = '"& txtcustnr.text & "'" try where customers.cust_id = txtcustnr.text
I don't know what data is in "txtcustnr.text", but if you you want the data from txtcustnr.text to be the same as customers.cust_id, then try the above WHERE clause.

How to build a select using Zend with a DISTINCT specific column?

I'm using Zend Framework for my website and I'd like to retrieve some data from my PostgreSQL database.
I have a request like :
SELECT DISTINCT ON(e.id) e.*, f.*, g.* FROM e, f, g
WHERE e.id = f.id_e AND f.id = g.id_f
This request works well but I don't know how to convert the DISTINCT ON(e.id) with Zend.
It seems that I can get DISTINCT rows but no distinct columns.
$select->distinct()->from("e")->join("f", "e.id = f.id_e")
->join("g", "f.id = g.id_f");
Any idea on how to make a select with distinct column ?
Thanks for help
You probably can't do this with Zend Framework since distinct on is not part of the SQL standard (end of page in Postgres documentation). Although Postgres supports it, I would assume its not part of Zend Framework because you could in theory configure another database connection which does not offer support.
If you know in advance that you're developing for a specific database (Postgres in this case), you could use manually written statements instead. You'll gain more flexibility within the queries and better performance at the cost of no longer being able to switch databases.
You would then instantiate a Zend_Db_Apdapter for Postgres. There a various methods available to get results for SQL queries which are described in the frameworks documentation starting at section Reading Query Results. If you choose to go this route I'd recommend to create an own subclass of the Zend_Db_Adapter_Pgsql class. This is to be able to convert data types and throw exceptions in case of errors instead of returning ambiguous null values and hiding error causes.

iphone sqlite query optimization

I am currently using this sqlite query in my application. Two tables are used in this query.....
UPDATE table1 set visited = (SELECT COUNT(DISTINCT table1.itemId) from 'table2' WHERE table2.itemId = table1.itemId AND table2.sessionId ='eyoge2avao');
It is working correct.... My problem is it is taking around 10 seconds to execute this query and retrieve the result..... Don't know what to do... Almost all other process are in right way.. So it seems the problem is with this query formation...
Plz someone help with how to optimize this query....
Regards,
Brian
Make sure you have indexes on the following (combinations of) fields:
table1.itemId
(This will speed up the DISTINCT clause, since the itemId will already be in the correct order).
table2.itemId, table2.sessionId
This will speed up the WHERE clause of your SELECT statement.
How many rows are there in these tables?
Aso try doing an EXPLAIN on your SELECT command to see if it gives you any helpful advice.

(Postgres) row_number OVER Partition in 8.2

some time ago I happend to resolve a PG related problem with this SO question of mine.
Basically it's about using row_number over a partition in 8.4.
Sadly now I have to create the same thing for 8.2 since one of my customers is on
8.2 and needs it desperatly.
What I do know (on 8.4) is the following:
SELECT custId, custName, 'xyz-' || row_number() OVER (PARTITION by custId)
AS custCode
Basically counting the occurances of custId and assigning custCodes from that.
(just an example, to show what I to; of course the query is way more complex)
I figured the solutions provided to the question mentioned above, but did'nt get them
working since there's one more hurdle to take. I don't run SQL directly I have to
embed it into a xml based config file which creates a certain xml format from the query
results. So creating temp stuff or procedures is not really an option.
So here's the question, does anyone of you guys have an idea how to port that solution of
mine to PG 8.2?
TIA
K
use depesz solution http://www.depesz.com/index.php/2007/08/17/rownum-anyone-cumulative-sum-in-one-query/