473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ODBC mdbtool SQL - problem with ORDER BY

4
Hello,

Debian with Perl, unixODBC.

I have a problem with "ORDER BY". An ordinary SQL workes fine and I can print it out to the webpage. But when I add the ORDER BY it stops working. Any Ideas??

Expand|Select|Wrap|Line Numbers
  1. my $dbh = DBI->connect('DBI:ODBC:Rotab'}) ;
  2. my $sql = qq/SELECT Ordernr, Kundnr, Kundnamn FROM Ordhuv WHERE Kundnamn LIKE '%link%' ORDER BY Ordernr DESC/;
  3. my $sth = $dbh->prepare($sql);
  4.  
/Fredrik
Aug 4 '07 #1
7 3878
numberwhun
3,509 Expert Mod 2GB
First, you should terminate your code tags with /code instead of just the word code. The example on the right side of editor shows the syntax.

As for your issue, I don't have tons of experience with ODBC, but have you tried executing the SQL to see if it works as it should?

Regards,

Jeff
Aug 4 '07 #2
solen
4
Sorry for that :(, this is my first add.

Yes, I have executed it with
$sth->execute();

still same problem.
Aug 4 '07 #3
numberwhun
3,509 Expert Mod 2GB
Actually, I was asking if you are sure that SQL statement works as expected. Can you take it out of your code, and execute it.

For instance, in MySQL, there is a MySQL interactive session which allows you to fully interact with the DB and execute commands. If they work there, they would work in your code.

Regards,

Jeff
Aug 5 '07 #4
solen
4
Well Jeff, the only way I know is to try to execute the SQL-statment with mdb-sql. But I see that this tool does not support ORDER BY command. The SELECT * FROM workes like charm with mdb-sql. I don't know how to continue debugging this error. All over internet people use ORDER BY with no problems...

/Fredrik
Aug 5 '07 #5
numberwhun
3,509 Expert Mod 2GB
I have done some checking and as far as the DBI::ODBC piece of your code, I don't find terribly much information beyond that it is for working with an Access database. You may want to check any documentation that you have to see if you can actually do an ORDER BY in that statement.

Regards,

Jeff
Aug 5 '07 #6
miller
1,089 Expert 1GB
Hello Fredrik,

As Jeff has already pointed out, if you ever have problems with using a SQL statement under perl, then you should try the statement out under the prompt provided by most databases. It is possible that an ORDER BY isn't allowed by the specific database you're using. We can't know that one way or the other, so you'll just have to test.

Additionally, you should always include error checking in your connect and execute database operations. They are of course only needed during the process of development normally, but they should always be part of every command anyway. In this instance, it is possible that a specific warning concerning the usage of ORDER BY may have been queued, but you aren't reporting it.

Expand|Select|Wrap|Line Numbers
  1. my $dbh = DBI->connect('DBI:ODBC:Rotab') or die "DB connect failed: $DBI::errstr";
  2. my $sth = $dbh->prepare(qq{SELECT Ordernr, Kundnr, Kundnamn FROM Ordhuv WHERE Kundnamn LIKE '%link%' ORDER BY Ordernr DESC});
  3. $sth->execute or die $dbh->errstr;
  4.  
- Miller
Aug 6 '07 #7
solen
4
Thanks for the quote Miller.

I have tested to use an error handler, but I never got it to work. I really need som nice example to look were I catch the error Flags. I have tested a few different but with bad results.

If you or someone have a nice sample code for catching errors, please send a link or the code.

Regards
Fredrik
Aug 8 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: test test | last post by:
Hello Python user, I've read your mail and analysed the problem. The testing i've done was with windows xp pro. First thin i have seen, was that you tried to open an existing registry...
0
by: Tomi Laamanen | last post by:
Hi, we have SQL Server 7.00.961 running on Windows 2000. On the client side we use ODBC driver 3.70.09.61 and an OCX component to retrieve rows from a table having about 600 000 rows. All works...
3
by: dror | last post by:
Hello, I have a problem that actually doesn't even make sense. I have 4 million rows in my database. I want to get all records into a DataReader and then read. So if I do it in DAO (either in VB...
2
by: Gianluca_Venezia | last post by:
Talking about high number of record seem ridiculus, if this number is about 88.000 but when I open a form, linked via ODBC to a MYSQL table, the open and the use of that form is slow, and very...
6
by: Andi Reisenhofer | last post by:
Hallo C# folks, Somebody know how to create a ODBC DSN dynamically in c# program. Also interesting for me would be the connectionstring for an Access Database. Thinks a lot Andreas
26
by: GreatAlterEgo | last post by:
Hi, This is my query which is embedded in a COBOL program. EXEC SQL SELECT DATE, AGE, DURATION, AMT INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT FROM TAB1 WHERE CODE = :KEY.CODE AND...
2
by: pedalpete | last post by:
I seem to have a few duplicates entries in a very large database. My database has two identical tables. One is written to on a regular basis (every few seconds) and the other is used for queries,...
2
by: gecashish | last post by:
If i use below query Select * from ADJ_ADJSTMNT fetch first 21 rows only with ur; works fine But if i use the same query with order by clause like below Select * from ADJ_ADJSTMNT order by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.