ReallySimpleDatabase icon indicating copy to clipboard operation
ReallySimpleDatabase copied to clipboard

String not recognized as valid DateTime

Open jdhitsolutions opened this issue 5 years ago • 0 comments

I haven't dug deeply into the code but here is a problem. I have a very small and simple test database that doesn't like your query method.

PS C:\> $d = get-database C:\scripts\my.db
PS C:\> $d.InvokeSql("Select * from Main")
PS C:\> $d.GetTable("Main")

Name       Count RowState   HasErrors  Definition
----       ----- --------   ---------  ----------
Main           3 Unchanged  False      CREATE TABLE Main (Name 'string',Date 'datetime')

PS C:\> $d.InvokeSql("Select * from Main")
Exception calling "Fill" with "1" argument(s): "String was not recognized as a valid DateTime."
At C:\Program Files\WindowsPowerShell\Modules\ReallySimpleDatabase\1.0.0\logic.ps1:349 char:5
+     $null = $da.fill($ds)
+     ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FormatException

I can query the Name column just fine. Here's what it looks like using sqlite3.exe

PS C:\>  c:\scripts\sqlite3.exe c:\scripts\my.db "Select * from Main"
Server1|12/1/2016 09:10AM
Server2|12/11/2016 12:1PM
Server4|12/11/2016 12:11PM

And PowerShell doesn't have an issue.

PS C:\> "12/1/2016 09:10AM" -as [datetime]

Thursday, December 1, 2016 9:10:00 AM

I appreciate trying to create typed output, but as a fallback I think you should at least write everything out as a string.

jdhitsolutions avatar Jan 14 '21 15:01 jdhitsolutions