I have a custom order clause that I am using in order to sort IP addresses. However, the order is not coming back correctly. When I switch to basic fetchmode, it appears to work correctly, but in Paged mode it doesn't.
Here is what my template looks like:
I turned on JDBC tracing to see what query was being run:
I'm not sure why the order by is needed twice, but it is doing the custom order by in one case, and overriding it with the non-customized order by and giving back the wrong order.
Here is what my template looks like:
Code:
<DataSource
tableName="device"
ID="device"
dataSourceVersion="1"
generatedBy="dev current"
serverType="sql"
>
<fields>
<field primaryKey="true" name="dev_id" type="number" hidden="true"></field>
<field name="dev_displayname" length="128" type="ntext" title="Device Display name"></field>
<field name="dev_address" length="50" type="ntext" title="Address"></field>
<field name="dev_ipaddress" length="32" type="ntext" title="Network: IP Address"></field>
</fields>
<operationBindings>
<operationBinding operationType="fetch" >
<orderClause>
#if($dsRequest.sortBy)
#if($dsRequest.sortBy == "dev_ipaddress")
cast(dbo.fnParseString(1,'.',dev_ipaddress) as INT),
cast(dbo.fnParseString(2,'.',dev_ipaddress) as INT),
cast(dbo.fnParseString(3,'.',dev_ipaddress) as INT),
cast(dbo.fnParseString(4,'.',dev_ipaddress) as INT)
#else
$defaultOrderClause
#end
#else
dev_displayname
#end
</orderClause>
</operationBinding>
</operationBindings>
</DataSource>
Code:
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY x.dev_ipaddress) AS rowID FROM (SELECT TOP 100 PERCENT device.display_name, device.dev_address, device.dev_ipaddress
ORDER BY
cast(dbo.fnParseString(1,'.',dev_ipaddress) as INT),
cast(dbo.fnParseString(2,'.',dev_ipaddress) as INT),
cast(dbo.fnParseString(3,'.',dev_ipaddress) as INT),
cast(dbo.fnParseString(4,'.',dev_ipaddress) as INT)
) x) y WHERE y.rowID BETWEEN 1 AND 75
Comment