Sharan Rao said the following, On 2007-12-01 21:17:

I was facing problems with the function Connection::querySingleString() in Sybase, as the " LIMIT " clause is not supported.

Sharan, thanks for your time; here's the patch you can apply for LIMIT 1 ussue. I am looking forward your opinion on it.

BTW, I propose to use [email protected] mailing list now. Who knows, maybe there's someone interested in tracking the development of the Sybase/MSSQL driver and can provide valuable feedback. (already CC'd).


Information for others: Sharan uses the db-lib from the FreeTDS project: http://www.freetds.org/

--
regards / pozdrawiam, Jaroslaw Staniek
 Sponsored by OpenOffice Polska (http://www.openoffice.com.pl/en) to work on
 Kexi & KOffice: http://www.kexi.pl/en, http://www.koffice.org
 KDE3 & KDE4 Libraries for MS Windows: http://kdelibs.com, http://www.kde.org
Index: kexidb/connection.cpp
===================================================================
--- kexidb/connection.cpp       (revision 744501)
+++ kexidb/connection.cpp       (working copy)
@@ -2460,7 +2460,7 @@
        Q_ASSERT(sql || query);
 //! @todo does not work with non-SQL data sources
        if (sql)
-               m_sql = addLimitTo1 ? (*sql + " LIMIT 1") : *sql; // is this 
safe?
+               m_sql = m_driver->addLimitTo1(*sql, addLimitTo1);
        KexiDB::Cursor *cursor;
        if (!(cursor = sql ? executeQuery( m_sql ) : executeQuery( *query ))) {
                KexiDBWarn << "Connection::querySingleRecord(): !executeQuery() 
" << m_sql << endl;
@@ -2501,7 +2501,7 @@
 tristate Connection::querySingleString(const QString& sql, QString &value, 
uint column, bool addLimitTo1)
 {
        KexiDB::Cursor *cursor;
-       m_sql = addLimitTo1 ? (sql + " LIMIT 1") : sql; // is this safe?;
+       m_sql = m_driver->addLimitTo1(sql, addLimitTo1);
        if (!(cursor = executeQuery( m_sql ))) {
                KexiDBWarn << "Connection::querySingleRecord(): !executeQuery() 
" << m_sql << endl;
                return false;
@@ -2569,13 +2569,13 @@
        if (m_driver->beh->SELECT_1_SUBQUERY_SUPPORTED) {
                //this is at least for sqlite
                if (addLimitTo1 && sql.left(6).toUpper() == "SELECT")
-                       m_sql = QString("SELECT 1 FROM (") + sql + ") LIMIT 1"; 
// is this safe?;
+                       m_sql = 
m_driver->addLimitTo1(QString::fromLatin1("SELECT 1 FROM (") + sql + ")", 
addLimitTo1);
                else
                        m_sql = sql;
        }
        else {
                if (addLimitTo1 && sql.left(6).toUpper() == "SELECT")
-                       m_sql = sql + " LIMIT 1"; //not always safe!
+                       m_sql = m_driver->addLimitTo1(sql, addLimitTo1);
                else
                        m_sql = sql;
        }
Index: kexidb/driver.h
===================================================================
--- kexidb/driver.h     (revision 744501)
+++ kexidb/driver.h     (working copy)
@@ -351,6 +351,13 @@
                        \a keywords should be 0-terminated array of 
null-terminated strings. */
                void initDriverSpecificKeywords(const char** keywords);
 
+               /* \return SQL statement @a sql modified by adding limiting 
command, 
+                (if possible and if @add is true). Used for optimization for 
the server side.
+                Can be reimplemented for other drivers. */
+               inline virtual QString addLimitTo1(const QString& sql, bool 
add) {
+                       return add ? (sql + QString::fromLatin1(" LIMIT 1")) : 
sql;
+               }
+
        friend class Connection;
        friend class Cursor;
        friend class DriverManagerInternal;
_______________________________________________
Kexi mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kexi

Reply via email to