sábado, 30 de julio de 2011

Using BETWEEN syntax with Symfony 1.4.x and MS SQL Server 2008

I´m using Symfony 1.4.8 and MS SQL Server 2008.

I had a query that read:



$q = Doctrine_Query::create()
->select('m.mapdate, m.created_at')
->from('GISMap m')
->where('m.mapdate BETWEEN ? AND ?', array($start_date, $end_date))
->orderBy('m.mapdate DESC');

This worked perfectly in MySQL, but when I switched to MS SQL Server I got an error like this one:



500 | Internal Server Error | Doctrine_Connection_Mssql_Exception



SQLSTATE[HY000]: General error: 10007 Incorrect syntax near '?'. [10007] (severity 5) [SELECT [g].[id] AS [g__id], [g].[mapdate] AS [g__mapdate], [g].[created_at] AS [g__created_at] FROM [gis_map] [g] WHERE ([g].[mapdate] BETWEEN '2010-03-24 10:32:24' AND ?) ORDER BY [g].[mapdate] DESC]. Failing Query: "SELECT [g].[id] AS [g__id], [g].[mapdate] AS [g__mapdate], [g].[created_at] AS [g__created_at] FROM [gis_map] [g] WHERE ([g].[mapdate] BETWEEN '2010-03-24 10:32:24' AND ?) ORDER BY [g].[mapdate] DESC"



After doing some research I found out that the replacement of the ? for the actual values is done by the PDO driver. So I decided that the problem was the driver for SQL Server didn´t like the array being passed to it.



I change the syntax to:

$q = Doctrine_Query::create()
->select('m.mapdate, m.created_at')
->from('GISMap m')
->where('m.mapdate >= ?', $start_date)
->andWhere('m.mapdate <= ?', $end_date)
->orderBy('m.mapdate DESC');

Now it works. It´s annoying to have to do this, but it´s been my experience that working with SQL Server will get you into these troubles.






Maven Error: Could not calculate build plan

I recently had to change computre and had some trouble with Maven.

I got the following message on Eclipse 3.5.2:

Could not calculate build plan: Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 from/to central (http://repo1.maven.org/maven2): Failed to transfer http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.4.3/maven-resources-plugin-2.4.3.pom. Error code 400, Bad Request jsimpleutils Unknown Maven Problem

On the following post http://vikashazrati.wordpress.com/2010/06/26/could-not-calculate-build-plan-missing-maven-resources-pluginmaven-plugin2-4-1/ a guy pointed out the he could find the directory but it had a filed with the extension .lastUpdated.

The solution was to delete the file with the .lastUpdated extension (maven-resources-plugin-2.4.1.maven-plugin.lastUpdated) and ran from eclipse maven->Update Project Configuration and the problem was resolved.






sábado, 23 de julio de 2011

Using IIS 7.5 with URL Rewrite and Symfony

The IIS URL Rewrite 2.0 is IIS module that promises to do what the mod_rewrite does for Apache.


Download the URL Rewrite module from http://www.iis.net/download/urlrewrite .


Installation


Install the rewrite_2.0_rtw_x32.msi (or rewrite_2.0_rtw_x64.msi if you´re using a 64bit OS).


201107231141.jpg


201107231142.jpg


Check the the fastcgi is properly configured in your php.ini. This is not part of the installation of the URL Rewrite module but I had to do it because I changed from PHP 5.3 to 5.2 (due to the reasons explained at http://tecnofuenteabierta.blogspot.com/2010/12/running-symfony-14-with-ms-sql-server.html ).


cgi.force_redirect=0


fastcgi.impersonate=1


fastcgi.logging=0


extension_dir = "C:\PHP\ext"


extension=php_pdo.dll


Importing the Rules


Next thing you need is to import the rules from the .htaccess file.


Open the Internet Information Services (IIS) Manager on the left pane click on your site (for details on how to configure IIS for Symfony take a look at [2]) and you´ll see an icon URL Rewrite


201107231152.jpg


Double click on the URL Rewrite icon. On the left pane named Actions click on Import Rules…


Select the .htaccess file on your web folder and click Import. Click on Apply.


201107231153.jpg

Click on Back to Rules… and you´ll see the rules imported.


201107231153.jpg

What this does is write a web.config file on your web folder than contains the rules for the URL Rewrite module and other fun thing Microsoft deems important.


Note: If you´re using rsync to update your site with –delete option be sure to copy the web.config file otherwise it will delete every time you update with rsync.


rsync -avr --delete --exclude-from=‘ path/exclude.txt‘ source/dir target/dir


201107231154.jpg


CREATOR OWNER SPECIAL


SYSTEM FULL CONTROL


ADMGISSVR SPECIAL


Administrators Full Control


Users Read & execute, List folder contents, Read


References


[1] http://www.iis.net/download/urlrewrite


[2] http://www.symfony-project.org/more-with-symfony/1_4/en/11-Windows-and-Symfony