The Views module provide a default page and block to display archive. The data sort using month and year and also show counting of node in the month and year.

The module provide query compatible to MySQL, pgsql, Sqlite only. In order to use views with MSSQL module should provide compatible query.

Here is small addition in "views_date_sql_field" function code that it can be use with MSSQL. There is lot of line of code that should be add in addition work views with MSSQL.

function views_date_sql_field($field, $field_type = 'int', $set_offset = NULL) {
$db_type = Database::getConnection()->databaseType();
$offset = $set_offset !== NULL ? $set_offset : views_get_timezone();
if (isset($offset) && !is_numeric($offset)) {
$dtz = new DateTimeZone($offset);
$dt = new DateTime("now", $dtz);
$offset_seconds = $dtz->getOffset($dt);
}

switch ($db_type) {
case 'sqlsrv':
switch ($field_type) {
case 'int':
$field = "DATEADD(second, $field, '1970-01-01')"; //DATEADD(second, @timestamp,{d '1970-01-01'});
break;
case 'datetime':
break;
}
if (!empty($offset)) {
$field = "DATEADD(second, $offset_seconds, $field)"; //"($field + INTERVAL $offset_seconds SECOND)";
}
return $field;
case 'mysql':
switch ($field_type) {
case 'int':
$field = "DATE_ADD('19700101', INTERVAL $field SECOND)";
break;
case 'datetime':
break;
}
if (!empty($offset)) {
$field = "($field + INTERVAL $offset_seconds SECOND)";
}
return $field;

Comments

govind.maloo’s picture

Component: node data » Code
dawehner’s picture

I don't think that views itself should have code which is specific for databases which aren't supported by drupal core.

govind.maloo’s picture

The views handler file have the code which is execute based on database type. Take a look you can easily find out what I am trying to show you.

dawehner’s picture

I totally understand your problem: Every database has a different kind of views how to deal with dates.
Views itself at the moment supports mysql, pgsql and sqlite.

rob_johnston’s picture

Title: MSSQL support » MSSQL support for archive view
Version: 7.x-3.5 » 7.x-3.7
Assigned: govind.maloo » Unassigned
Issue summary: View changes

@dawehner, that's a completely useless answer as it doesn't help resolve the problem. Views should not use sql-specific dialects. Maybe it's necessary for the dates but other people use MS SQL Server, Oracle, etc. That's a fact that cannot be ignored.

@govind.maloo, I also found the problem but decided to first get opinions from the sqlsrv module as to how best handle it there before patching the views module. See #1927306: SQL Server needs the mySql DATE_FORMAT function. I didn't notice this issue until now.

mustanggb’s picture

Status: Active » Closed (won't fix)

dawehner does have a point though, it's quite logical for views to only support the databases that core does.

It should be possible that such functionality can be implemented by sqlsrv.