Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading DateTime has issue. #24

Closed
RPalejiya opened this issue Jan 15, 2022 · 1 comment
Closed

Reading DateTime has issue. #24

RPalejiya opened this issue Jan 15, 2022 · 1 comment

Comments

@RPalejiya
Copy link

RPalejiya commented Jan 15, 2022

Hello,

If I take the current Dev repo and try to select Datetime column. I get following Error.

System.Runtime.InteropServices.SEHException: 'External component has thrown an exception.'
This exception was originally thrown at this call stack:
DuckDB.NET.Windows.WindowsBindNativeMethods.DuckDBValueInt32(DuckDB.NET.DuckDBResult, long, long) in NativeMethods.Windows.cs
DuckDB.NET.Data.DuckDBDataReader.GetInt32(int) in DuckDBDataReader.cs
DuckDB.NET.Samples.Program.PrintQueryResults(System.Data.Common.DbDataReader) in Program.cs
DuckDB.NET.Samples.Program.AdoNetSamples() in Program.cs
DuckDB.NET.Samples.Program.Main(string[]) in Program.cs

Here is my Sample Project snippet to reproduce it.

private static void AdoNetSamples()
        {
            if (File.Exists("file.db"))
            {
                File.Delete("file.db");
            }
            using var duckDBConnection = new DuckDBConnection("Data Source=file.db");
            duckDBConnection.Open();

            var command = duckDBConnection.CreateCommand();

            command.CommandText = "Create table test2 (id Int, dt TIMESTAMP, string varchar  );";
            var executeNonQuery = command.ExecuteNonQuery();

            command.CommandText = "Insert into test2 values(1,'1992-09-20 11:30:00', 'Xyz');";
            executeNonQuery = command.ExecuteNonQuery();

            //command.CommandText = "select * from test2;";
            //var executeScalar = command.ExecuteScalar();

            command.CommandText = "select * from test2;";
            var reader = command.ExecuteReader();
            PrintQueryResults(reader);

            var results = duckDBConnection.Query<FooBar>("SELECT foo, bar FROM integers");

            try
            {
                command.CommandText = "Not a valid Sql statement";
                var causesError = command.ExecuteNonQuery();
            }
            catch (DuckDBException e)
            {
                Console.WriteLine(e.Message);
            }
        }
@Giorgi
Copy link
Owner

Giorgi commented Mar 11, 2022

@RPalejiya If your column is Timestamp, you should not be calling GetInt32. You can call GetValue that works for any type or call one of the specialized GetXXX methods. Please see the updated demo.

@Giorgi Giorgi closed this as completed Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants