[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdeextragear-1/amarok/src
From: Christian Muehlhaeuser <chris () chris ! de>
Date: 2005-03-01 3:45:11
Message-ID: 20050301034511.D0B6316EF1 () office ! kde ! org
[Download RAW message or body]
CVS commit by muesli:
* ADD: GroupBy and SQL-function support added to QueryBuilder. (thanks to Untouch!)
CCMAIL:amarok-devel@lists.sf.net
M +38 -2 collectiondb.cpp 1.311
M +5 -0 collectiondb.h 1.138
--- kdeextragear-1/amarok/src/collectiondb.cpp #1.310:1.311
@@ -2159,5 +2159,5 @@ QueryBuilder::addReturnValue( int table,
if ( table & tabStats && value & valScore ) m_values += "round(";
- if ( value == tabDummy )
+ if ( value == valDummy )
m_values += "''";
else
@@ -2173,4 +2173,15 @@ QueryBuilder::addReturnValue( int table,
}
+void
+QueryBuilder::addReturnFunctionValue( int function, int table, int value)
+{
+ if ( !m_values.isEmpty() && m_values != "DISTINCT " ) m_values += ",";
+ m_values += functionName( function ) + "(";
+ m_values += tableName( table ) + ".";
+ m_values += valueName( value )+ ")";
+
+ m_linkTables |= table;
+ m_returnValues++;
+}
uint
@@ -2427,4 +2437,14 @@ QueryBuilder::sortBy( int table, int val
}
+void
+QueryBuilder::groupBy( int table, int value )
+{
+ if ( !m_group.isEmpty() ) m_group += ",";
+ m_group += tableName( table ) + ".";
+ m_group += valueName( value );
+
+ m_linkTables |= table;
+}
+
void
@@ -2462,4 +2482,5 @@ QueryBuilder::buildQuery()
m_query = "SELECT " + m_values + " FROM " + m_tables + " " + m_join + " \
WHERE 1 " + m_where; if ( !m_sort.isEmpty() ) m_query += " ORDER BY " + m_sort;
+ if ( !m_group.isEmpty() ) m_query += " GROUP BY " + m_group;
m_query += m_limit;
}
@@ -2485,4 +2506,5 @@ QueryBuilder::clear()
m_where = "";
m_sort = "";
+ m_group = "";
m_limit = "";
@@ -2536,4 +2558,18 @@ QueryBuilder::valueName( int value )
}
+QString
+QueryBuilder::functionName( int value )
+{
+ QString function;
+
+ if ( value & funcCount ) function += "Count";
+ if ( value & funcMax ) function += "Max";
+ if ( value & funcMin ) function += "Min";
+ if ( value & funcAvg ) function += "Avg";
+ if ( value & funcSum ) function += "Sum";
+
+ return function;
+}
+
#include "collectiondb.moc"
--- kdeextragear-1/amarok/src/collectiondb.h #1.137:1.138
@@ -359,4 +359,5 @@ class QueryBuilder
valCreateDate = 2048, valAccessDate = 4096, \
valPercentage = 8192, valArtistID = 16384, valAlbumID = 32768,
valYearID = 65536, valGenreID = 131072, valDummy = 0 \
}; + enum qBuilderFunctions { funcCount = 1, funcMax = 2, funcMin = 4, \
funcAvg = 8, funcSum = 16 };
enum qBuilderFilter { modeNormal = 0, modeFuzzy = 1 };
@@ -365,4 +366,5 @@ class QueryBuilder
void addReturnValue( int table, int value );
+ void addReturnFunctionValue( int function, int table, int value);
uint countReturnValues();
@@ -382,4 +384,5 @@ class QueryBuilder
void setOptions( int options );
void sortBy( int table, int value, bool descending = false );
+ void groupBy( int table, int value );
void setLimit( int startPos, int length );
@@ -394,4 +397,5 @@ class QueryBuilder
QString tableName( int table );
QString valueName( int value );
+ QString functionName( int value );
void linkTables( int tables );
@@ -403,4 +407,5 @@ class QueryBuilder
QString m_where;
QString m_sort;
+ QString m_group;
QString m_limit;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic