<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 25 02:44:45 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-1028/DDC-1028.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DDC-1028] MsSQL-Server DateTime microseconds issue</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-1028</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;The string for the function getDateTimeFormatString() in the MsSqlPlatform class is &apos;wrong&apos;.&lt;br/&gt;
The Microsoft-SQL-Server just uses 3 digits for microseconds and not 6. &lt;br/&gt;
So the string &apos;Y-m-d H:i:s.u&apos; fails and the server states: &lt;span class=&quot;error&quot;&gt;&amp;#91;SQL Server&amp;#93;&lt;/span&gt;Fehler beim Konvertieren  einer Zeichenfolge in einen datetime-Wert (Error when converting a string to a datetime-value) .&lt;/p&gt;

&lt;p&gt;So this string works, but does not regard the microseconds for those how rely on them: &apos;Y-m-d H:i:s.000&apos;&lt;/p&gt;

&lt;p&gt;See also: &lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;...&amp;#93;&lt;/span&gt; The MS datetime column is documented to have an accuracy of only about .3 seconds anyway &lt;span class=&quot;error&quot;&gt;&amp;#91;...&amp;#93;&lt;/span&gt; &lt;br/&gt;
&lt;a href=&quot;http://bytes.com/topic/sql-server/answers/80150-inserting-datetime-milliseconds-sql-server&quot; class=&quot;external-link&quot;&gt;http://bytes.com/topic/sql-server/answers/80150-inserting-datetime-milliseconds-sql-server&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-gb/library/ms186819.aspx&quot; class=&quot;external-link&quot;&gt;http://msdn.microsoft.com/en-gb/library/ms186819.aspx&lt;/a&gt; (Section: Remarks)&lt;/p&gt;</description>
                <environment>WindowsXP/Windows2008 R2 / PHP 5.3 / MsSQL-Server 2005 / MsSQL-PDO_PHP-Driver</environment>
            <key id="12379">DDC-1028</key>
            <summary>MsSQL-Server DateTime microseconds issue</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                    <security id="10000">All</security>
                        <assignee username="juokaz">Juozas Kaziukenas</assignee>
                                <reporter username="le_shatai">Martin Weise</reporter>
                        <labels>
                    </labels>
                <created>Fri, 11 Feb 2011 12:09:38 +0000</created>
                <updated>Mon, 9 Jan 2012 13:19:12 +0000</updated>
                    <resolved>Mon, 9 Jan 2012 13:19:12 +0000</resolved>
                            <version>2.0.1</version>
                                <fixVersion>2.2</fixVersion>
                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="15275" author="beberlei" created="Fri, 11 Feb 2011 17:00:06 +0000"  >&lt;p&gt;Assigned to juozas, but i think the issue here is that you have to use Datetime2, or add your own type replacing the shipped one to support the old datetime.&lt;/p&gt;</comment>
                    <comment id="15303" author="le_shatai" created="Mon, 14 Feb 2011 06:34:49 +0000"  >&lt;p&gt;Ok, I had another problem with the datetime, but this does not regard the problem of this issue ( at least not totally).&lt;br/&gt;
The problem with the MsSQL-Server before 2008 is that there is no data type named &apos;datetime2&apos;, just &apos;datetime&apos;.&lt;br/&gt;
The next problem is that every date conversion for a query is done in the language set upon conection time.&lt;br/&gt;
Thus leads to a problem, when it is not possible to set the connection language. &lt;/p&gt;

&lt;p&gt;So the problem is that the MsSQL-Server relies on the settings above.&lt;br/&gt;
In my case the datetime conversion failed, as the server always thought that the datetime-string would come in&lt;br/&gt;
the following format: Y-d-m . This is not true, as the default format string is: Y-m-d . So every insert/update query fails.&lt;br/&gt;
To solve the problem I did that: $entityManager-&amp;gt;getConnection()-&amp;gt;exec(&apos;SET DATEFORMAT ymd&apos;); .&lt;br/&gt;
This way I ensured that the dateformat string works fine, except the issue problem.&lt;/p&gt;

&lt;p&gt;To solve the problem in general, it would be helpful to subclass the MsSqlPlatform into a class named MsSql2005Platform or something like this and just override the getDateTimeFormatString and upon connection setting the format for the queries&lt;br/&gt;
as mentioned before.&lt;/p&gt;

&lt;p&gt;Hope this helps out.&lt;br/&gt;
Besides, here a link to the datetime problem (in german): &lt;a href=&quot;http://www.insidesql.org/blogs/frankkalis/2010/08/19/der-ultimative-guide-fuer-die-datetime-datentypen&quot; class=&quot;external-link&quot;&gt;http://www.insidesql.org/blogs/frankkalis/2010/08/19/der-ultimative-guide-fuer-die-datetime-datentypen&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="15304" author="juokaz" created="Mon, 14 Feb 2011 06:47:07 +0000"  >&lt;p&gt;I have somehow manage to miss the fact that datetime2 wasn&apos;t around in datetime... What I&apos;m thinking now is there a need for datetime2 in Doctrine at all. If only thing it brings is additional accuracy for microseconds, maybe best idea would be to use datetime for 2008 installs too if used from Doctrine. However datetime is now a standard and Microsoft recommends to use it for new installs. What I can do is I can always insert 3 fractional points to datetime column as both datetime2 and datetime would accept it as valid date string. &lt;/p&gt;

&lt;p&gt;We can have separate platforms for 2008 and 2005 servers, but that would be quite resource intensive. Let me see what is the best way to fix it.&lt;/p&gt;

&lt;p&gt;Regards to Dateformat, I guess the solution would be to set format on connection, how you suggested. How about you create a separate ticket for this and assign it to me.&lt;/p&gt;</comment>
                    <comment id="15305" author="beberlei" created="Mon, 14 Feb 2011 08:28:37 +0000"  >&lt;p&gt;Oracle also has an Session Init Listener that handles the date format things, i guess we can take this as example. However I think having Mssql2005Platform sounds goods also, it would be only one method to override.&lt;/p&gt;</comment>
                    <comment id="16303" author="le_shatai" created="Tue, 9 Aug 2011 14:05:08 +0000"  >&lt;p&gt;To solve this issue, at least for MsSQL-Server datetime data types, change the following TypeClass of Doctrine by adding&lt;br/&gt;
this check before converting to PHP\DateTime in &apos;convertToPHPValue()&apos; :&lt;/p&gt;

&lt;p&gt;if( strlen($value) == 24 &amp;amp;&amp;amp; $platform-&amp;gt;getDateTimeFormatString() == &apos;Y-m-d H:i:s.u&apos;)&lt;br/&gt;
	$value = $value.&apos;000&apos;;&lt;/p&gt;

&lt;p&gt;I know this is propably very specific, but I do not know, how other DBs handle microseconds in datetime strings.&lt;/p&gt;</comment>
                    <comment id="16455" author="le_shatai" created="Thu, 8 Sep 2011 07:47:19 +0000"  >&lt;p&gt;I fixed this bug with some changes in the DateTimeType class. As there is no Explicit MSSQL2005 Plattform this change would also affect datetime2 type in the SQLServer 2008 plattform, which is the data type that has 6 microseconds.&lt;br/&gt;
So either populate a MSSQLServer2005 Plattform, or introduce a new DateTimeType for the 2005 platform.&lt;/p&gt;



&lt;div class=&quot;code panel&quot; style=&quot;border-style: solid;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;border-bottom-style: solid;&quot;&gt;&lt;b&gt;DateTimeType.php&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
&amp;lt;?php
/*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * &lt;span class=&quot;code-quote&quot;&gt;&quot;AS IS&quot;&lt;/span&gt; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * &amp;lt;http:&lt;span class=&quot;code-comment&quot;&gt;//www.doctrine-project.org&amp;gt;.
&lt;/span&gt; */

namespace Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
 * Type that maps an SQL DATETIME/TIMESTAMP to a PHP DateTime object.
 *
 * @since 2.0
 */
class DateTimeType &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Type
{
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getName()
    {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Type::DATETIME;
    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $platform-&amp;gt;getDateTimeTypeDeclarationSQL($fieldDeclaration);
    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
		&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;( $value === &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
			&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;

		$value = $value-&amp;gt;format($platform-&amp;gt;getDateTimeFormatString());

		&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;( strlen($value) == 26 &amp;amp;&amp;amp;
			$platform-&amp;gt;getDateTimeFormatString() == &apos;Y-m-d H:i:s.u&apos; &amp;amp;&amp;amp;
			$platform &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; \Doctrine\DBAL\Platforms\MsSqlPlatform )
			$value = substr($value, 0, \strlen($value)-3);

		&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $value;

    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function convertToPHPValue($value, AbstractPlatform $platform)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($value === &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
        }

		&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;( strlen($value) == 24 &amp;amp;&amp;amp; $platform-&amp;gt;getDateTimeFormatString() == &apos;Y-m-d H:i:s.u&apos;)
			$value = $value.&apos;000&apos;;

        $val = \DateTime::createFromFormat($platform-&amp;gt;getDateTimeFormatString(),$value);
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (!$val) {
            &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; ConversionException::conversionFailedFormat($value, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getName(), $platform-&amp;gt;getDateTimeFormatString());
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $val;
    }
}

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="17197" author="beberlei" created="Mon, 9 Jan 2012 13:19:12 +0000"  >&lt;p&gt;Added SQLServer2005 platform that uses DATETIME and the .000 format as per instructions of Martin.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
            <subtask id="12386">DDC-1032</subtask>
        </subtasks>
        </item>
</channel>
</rss>