Example #1
0
        private int ExecuteScalarOrNonQuery()
        {
            using var unmanagedString = CommandText.ToUnmanagedString();

            var result = PlatformIndependentBindings.NativeMethods.DuckDBQuery(connection.NativeConnection, unmanagedString, out var queryResult);

            if (!string.IsNullOrEmpty(queryResult.ErrorMessage))
            {
                throw new DuckDBException(queryResult.ErrorMessage, result);
            }

            if (!result.IsSuccess())
            {
                throw new DuckDBException("DuckDBQuery failed", result);
            }

            if (queryResult.ColumnCount > 0 && queryResult.RowCount > 0)
            {
                return(PlatformIndependentBindings.NativeMethods.DuckDBValueInt32(queryResult, 0, 0));
            }

            return(0);
        }