Code Monkey home page Code Monkey logo

amazon-redshift-odbc-driver's Introduction

Redshift ODBC Driver

The Amazon ODBC Driver for Redshift database connectivity through the standard ODBC application program interfaces (APIs). The Driver provides access to Redshift from any C/C++ application.

The driver has many Redshift specific features such as,

  • IAM authentication
  • IDP authentication
  • Redshift specific datatypes support
  • External schema support as part of SQLTables() and SQLColumns() ODBC API

Amazon Redshift provides 64-bit ODBC drivers for Linux, and Windows operating systems.

Build Driver

Prerequisites

  • https://git-lfs.com/ (for correctly cloning this repository)
  • Visual Stuido 2022 Community Edition (For Windows)
  • gcc (For Linux)
  • cmake >= 3.12 (For Linux)
  • Dependencies: To see a list of Linux dependencies, please look into src/odbc/rsodbc/CMakeLists.txt (windows: Dependencies are already included).

Build Artifacts

On Windows system run:

build64.bat n.n.n n 
e.g. build64.bat 2.0.1 0

It builds rsodbc.dll file under src\odbc\rsodbc\x64\Release directory.

export DEPENDENCY_DIR= Ensure proper dependencies are provided on Unix systems by configuring the dependency variable: Set the DEPENDENCY_DIR variable in the exports_basic.sh`` file. For further details, consult the BUILD.CMAKE.md` file. Then run:

build64.sh n.n.n n
e.g. build64.sh 2.0.1 0

It builds librsodbc64.so file under src/odbc/rsodbc/Release directory.

Installation and Configuration of Driver

Driver Name: Amazon Redshift ODBC Driver (x64)

Default Installation Directory:

  • C:\Program Files\Amazon Redshift ODBC Driver x64\ (For Windows)
  • /opt/amazon/redshiftodbcx64/ (For Linux)

See Amazon Redshift ODBC Driver Installation and Configuration Guide for more information.

Here are download links for the latest release:

Report Bugs

See CONTRIBUTING for more information.

Contributing Code Development

See CONTRIBUTING for more information.

Changelog Generation

An entry in the changelog is generated upon release using gitchangelog <https://github.com/vaab/gitchangelog>. Please use the configuration file, .gitchangelog.rc when generating the changelog.

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

amazon-redshift-odbc-driver's People

Contributors

amazon-auto avatar iggarish avatar rueiyhuang avatar vahid110 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amazon-redshift-odbc-driver's Issues

Failed to Parse login form with IdentityProvider: PingFederate

Driver version

Amazon Redshift ODBC Driver (x64) v2.00.00.03

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.46523

Client Operating System

Win 10

Problem description

Cannot connect to Redshift cluster using pingfed saml integration and plugin PingFederate.

  1. Expected behaviour: User is authenticated, and connection is established.
  2. Actual behaviour: Error message received.
  3. Error message/stack trace: Connection failed (HY000): [Redshift][ODBC Driver][Server][860:8:IAMConnectionError]: Failed to parse login form.
  4. Any other details that can be helpful: Same connection works with very old ODBC version 1.3.7.1000 but has other issues with external schemas and data shares.

SQL Server linked server error "The provider reported an unexpected catastrophic failure."

Driver version

2.0.0.11

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.61191

Client Operating System

Windows10 Version 22H2 (OS Build 19045.3803)

Table schema

N/A (connectivity problem)

Problem description

Trying to use this driver for a linked server from SQL Server, and am getting this error message:

select x from openrowset('MSDASQL', 'Driver={Amazon Redshift ODBC Driver (x64)};Host=...;Database=...;UID=...;Password=...',
    'select 1 as x')

> The OLE DB provider "MSDASQL" for linked server "(null)" reported an error. The provider reported an unexpected catastrophic failure.
> Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "(null)".

..if I use version 1.5.9.1011 it works normally:

select x from openrowset('MSDASQL', 'Driver={Amazon Redshift (x64)};Host=...;Database=...;UID=...;Password=...',
    'select 1 as x')

> x
> 1

ODBC trace logs

amazonredshiftodbcdriver.log
amazonredshiftodbcdriver_connection_1.log

Failing to successfully 'link table' with this driver version with MS Access 365.

Driver version

2.00.00.01

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.40182

Client Operating System

Winbdows 2011 64 bit

Table schema

All tables & vies

Problem description

Failing to successfully 'link table' with this driver version with MS Access 365.

Notable errors from the odbc driver connection log:
Jul 21 07:42:11.386 TRACE 26864 Simba::ODBC::Connection::SQLGetConnectAttr: +++++ enter +++++
Jul 21 07:42:11.386 INFO 26864 Simba::ODBC::Connection::SQLGetConnectAttr: Attribute: Unknown Attribute (30002)
Jul 21 07:42:11.399 ERROR 26864 Simba::ODBC::Connection::SQLGetConnectAttr: [Amazon][ODBC] (10210) Attribute identifier invalid or not supported: 30002

Our prior installed version driver (1.04.56.1000) does not return this error. Thank you :)

->

Driver crashing with large number of rows

Driver version

2.00.00.11

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.61631

Client Operating System

Windows 10 x64

Table schema

Single integer field. No table needed

Problem description

When selecting a very large number of rows our application crashes with the following error.

[Redshift][ODBC Driver]An I/O error occurred while reading streaming cursor.

The attached code reproduces the problem. I don't have a thread.sleep there, so it will hang while running.

ODBC trace logs

Trace logs attached (zip file). Here is the tail.

TestOdbcCommand 1edc-5dec EXIT SQLFetch with return code -1 (SQL_ERROR)
HSTMT 0x0000020FF8D3D1C0

	DIAG [24000] [Redshift][ODBC Driver]An I/O error occurred while reading streaming cursor. (0) 

TestOdbcCommand 1edc-5dec ENTER SQLGetDiagRecW
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0000020FF8D3D1C0
SQLSMALLINT 1
SQLWCHAR * 0x000000A2B19FEA50
SQLINTEGER * 0x000000A2B19FEC78
SQLWCHAR * 0x0000020FFB144BD0
SQLSMALLINT 1024
SQLSMALLINT * 0x000000A2B19FEC80

TestOdbcCommand 1edc-5dec EXIT SQLGetDiagRecW with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0000020FF8D3D1C0
SQLSMALLINT 1
SQLWCHAR * 0x000000A2B19FEA50 [ 5] "24000"
SQLINTEGER * 0x000000A2B19FEC78 (0)
SQLWCHAR * 0x0000020FFB144BD0 [ 76] "[Redshift][ODBC Driver]An I/O error occurred while reading streaming cursor."
SQLSMALLINT 1024
SQLSMALLINT * 0x000000A2B19FEC80 (76)

TestOdbcCommand 1edc-5dec ENTER SQLGetDiagRecW
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0000020FF8D3D1C0
SQLSMALLINT 2
SQLWCHAR * 0x000000A2B19FEA50
SQLINTEGER * 0x000000A2B19FEC78
SQLWCHAR * 0x0000020FFB144BD0
SQLSMALLINT 1024
SQLSMALLINT * 0x000000A2B19FEC80

TestOdbcCommand 1edc-5dec EXIT SQLGetDiagRecW with return code 100 (SQL_NO_DATA_FOUND)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0000020FF8D3D1C0
SQLSMALLINT 2
SQLWCHAR * 0x000000A2B19FEA50
SQLINTEGER * 0x000000A2B19FEC78
SQLWCHAR * 0x0000020FFB144BD0
SQLSMALLINT 1024
SQLSMALLINT * 0x000000A2B19FEC80

TestOdbcCommand 1edc-5dec ENTER SQLGetInfoW
HDBC 0x0000020FF8D3A820
UWORD 6 <SQL_DRIVER_NAME>
PTR 0x0000020F801EBEB0
SWORD 100
SWORD * 0x000000A2B19FEC48

TestOdbcCommand 1edc-5dec EXIT SQLGetInfoW with return code 0 (SQL_SUCCESS)
HDBC 0x0000020FF8D3A820
UWORD 6 <SQL_DRIVER_NAME>
PTR 0x0000020F801EBEB0 [ 20] "rsodbc.dll"
SWORD 100
SWORD * 0x000000A2B19FEC48 (20)

TestOdbcCommand 1edc-5dec ENTER SQLGetConnectAttrW
SQLHDBC 0x0000020FF8D3A820
SQLINTEGER 1209
SQLPOINTER [Unknown attribute 1209]
SQLINTEGER 4
SQLINTEGER * 0x000000A2B19FEC48

TestOdbcCommand 1edc-5dec EXIT SQLGetConnectAttrW with return code 0 (SQL_SUCCESS)
SQLHDBC 0x0000020FF8D3A820
SQLINTEGER 1209
SQLPOINTER [Unknown attribute 1209]
SQLINTEGER 4
SQLINTEGER * 0x000000A2B19FEC48 (0)

TestOdbcCommand 1edc-5dec ENTER SQLMoreResults
HSTMT 0x0000020FF8D3D1C0

Reproduction code

Reproduction code attached.

TraceLog.zip
TestOdbcCommand.zip

The 'Identity Provider: Browser Azure AD OAUTH2' authentication method does not work if the client secret is mandatory for the application registered in Azure AD.

Driver version

2.00.01.00

Redshift version

'PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.63269

Client Operating System

Windows 10

Table schema

Not relevant.

Problem description

  1. Expected behaviour: ODBC driver should be able to connect using Auth Type: Identity Provider: Browser Azure AD OAUTH2 when the client secret is required by the application registered in Azure AD
  2. Actual behaviour: ODBC driver is not able to connect using Auth Type: Identity Provider: Browser Azure AD OAUTH2.
  3. Error message/stack trace: The driver returns the following message:
    Authentication failed in the Browser server. Please check the IdP Tenant and Client ID
  4. Any other details that can be helpful:
    The clientSecret is not provided in the request to obtain the access token after the browser returns the authorization code.
    The problem is located in the RequestAccessToken function from the IAMBrowserAzureOAuth2CredentialsProvider. The following code fragment should include the client secret that should be an optional field in the configuration of this authentication type:

const std::map<rs_string, rs_string> paramMap =
{
{ "grant_type", "authorization_code" },
// { "requested_token_type", "urn:ietf:params:oauth:token-type:jwt" },
{ "response_type", "token" },
{ "scope", scope },
{ "client_id", m_argsMap[IAM_KEY_CLIENT_ID] },
{ "code", authCode },
{ "redirect_uri", "http://localhost:" + m_argsMap[IAM_KEY_LISTEN_PORT] + "/redshift/" }
// { "resource", m_argsMap[IAM_KEY_CLIENT_ID] }
};

Also, it is important to notice that the following article (Which describes the required configuration to enable OAuth authentication for Redshift) includes a step to define a client secret in the application created in Azure AD. So if anyone follows that article will not be able to use this authentication type in the ODBC driver:

ODBC trace logs

The following log fragment could explain the issue:

[DEBUG] 2024-03-05 12:48:45.191 [IAMCRD:IAMBrowserAzureOAuth2CredentialsProvider.cpp:250] [45908] IAMBrowserAzureOAuth2CredentialsProvider::RequestAccessToken
[DEBUG] 2024-03-05 12:48:45.191 [IAMCRD:IAMBrowserAzureOAuth2CredentialsProvider.cpp:283] [45908] IAMBrowserAzureOAuth2CredentialsProvider::RequestAccessToken
[DEBUG] 2024-03-05 12:48:45.191 [IAM:IAMPluginCredentialsProvider.cpp:226] [45908] IAMPluginCredentialsProvider::GetHttpClient
[DEBUG] 2024-03-05 12:48:45.191 [IAM_HTTP_CLNT:IAMHttpClient.cpp:43] [45908] IAMHttpClient::GetClientConfiguration
[DEBUG] 2024-03-05 12:48:45.200 [ODBCDLL:dllmain.c:50] [15156] DLL_THREAD_ATTACH
[DEBUG] 2024-03-05 12:48:45.406 [ODBCDLL:dllmain.c:50] [25936] DLL_THREAD_ATTACH
[DEBUG] 2024-03-05 12:48:45.747 [IAMCRD:IAMBrowserAzureOAuth2CredentialsProvider.cpp:311] [45908] IAMBrowserAzureOAuth2CredentialsProvider::RequestAccessToken: response {"error":"invalid_client","error_description":"AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'. Trace ID: 7ac524f7-b73c-417f-bd4d-089cca48a300 Correlation ID: f4072a68-4ea2-4d26-899a-7b3d86a3bb09 Timestamp: 2024-03-05 12:48:45Z","error_codes":[7000218],"timestamp":"2024-03-05 12:48:45Z","trace_id":"7ac524f7-b73c-417f-bd4d-089cca48a300","correlation_id":"f4072a68-4ea2-4d26-899a-7b3d86a3bb09","error_uri":"https://login.microsoftonline.com/error?code=7000218"}
[DEBUG] 2024-03-05 12:48:45.747 [IAMCRD:IAMJwtPluginCredentialsProvider.cpp:259] [45908] IAMJwtPluginCredentialsProvider::~IAMJwtPluginCredentialsProvider
[DEBUG] 2024-03-05 12:48:45.747 [Redshift::IamSupport::%s::%s():IAMCredentialsProvider.cpp:105] [45908] IAMCredentialsProvider

Reproduction code

I was able to reproduce the issue clicking on Test button of a DSN with the following parameters defined:

  • Data Source Name
  • Server
  • Port
  • Database
  • Auth type --> Set to Identity Provider: Browser Azure AD OAUTH2
  • Azure Client ID
  • Idp Tenant

image

Latest version of driver crash when selecting from PG_TABLE_DEF

Driver version

2.0.0.6

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.51304

Client Operating System

Windows 10

Table schema

PG_TABLE_DEF

Problem description

Wen executing select DISTINCT tablename from PG_TABLE_DEF where schemaname = 'public'" (or any other selections on PG_TABLE_DEF) via the driver, the hosting application crashes (e.g., running a SQL query from PowerShell makes PowerShell crash:
[process exited with code 3221226356 (0xc0000374)].

  1. Expected behaviour: it should be possible to select data from PG_TABLE_DEF
  2. Actual behaviour: the driver kills the application trying to fetch data
  3. Error message/stack trace: In powershell, process exited with code 3221226356 (0xc0000374).
  4. Any other details that can be helpful: Have not tried any other selections. There might be other things that causes this to happen. but no issues was seen on 2.0.0.5.

ODBC trace logs

DEBUGG logs are provided.
redshift_odbc.zip
(Added as zip since log.1 files cannot be uploaded.)

Reproduction cod

A select as described above seems to trigger this. No other code tested.

Build is failed in Windows platform

Driver version

2.0.0.7

Redshift version

Client Operating System

Windows Server 2022 Datacenter

Table schema

Problem description

2>C:\Users\Administrator\amazon-redshift-odbc-driver\src\pgclient\src\port\thread.c(139,12): warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
2>RC : fatal error RC1110: could not open src\interfaces\libpq\libpq.rc
2>
2>Done building project "libpq.vcxproj" -- FAILED.
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
========== Rebuild started at 3:11 AM and took 12.015 seconds ==========
Failure during "devenv" step: Exit code is 1
Failure during "devenv" step: Exit code is 1

ODBC trace logs

Reproduction code

Timeout due to max_query_execution_time can lead to undefined behavior in SQLFetch call

Driver version

I've tested this behavior with Redshift ODBC 2.0.0.8 & 2.0.0.9

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.56899

Client Operating System

Edition: Windows 10 Pro
Version: 22H2
OS build: 19045.3448
Experience: Windows Feature Experience Pack 1000.19044.1000.0

Table schema

CREATE TABLE public.nasty_cat (
    generated_on timestamp without time zone ENCODE az64,
    sparta_route_code character varying(256) ENCODE bytedict,
    destination_spec character varying(256) ENCODE bytedict,
    load_region character varying(256) ENCODE bytedict,
    load_port character varying(256) ENCODE bytedict,
    discharge_region character varying(256) ENCODE bytedict,
    discharge_port character varying(256) ENCODE bytedict,
    vessel_type character varying(256) ENCODE bytedict,
    load_date character varying(256) ENCODE lzo,
    delivery_date character varying(256) ENCODE lzo,
    load_month_year character varying(256) ENCODE bytedict,
    load_window character varying(256) ENCODE bytedict,
    delivery_month_year character varying(256) ENCODE bytedict,
    delivery_window character varying(256) ENCODE bytedict,
    granularity character varying(256) ENCODE bytedict,
    delivered_pricing_basis_1_name character varying(256) ENCODE bytedict,
    delivered_pricing_basis_1_price double precision ENCODE raw,
    delivered_pricing_basis_1_margin double precision ENCODE raw
) DISTSTYLE AUTO;

Problem description

The Problem occurs when attempting to load lots of data through ODBC when Redshift has a too small max_query_execution_time.
After the given time amount, the Redshift ODBC driver receives a failure signal and aborts the SQLFetch call. However during this, there is a heap corruption du to freeing the result and then accessing it again.

In the example we're loading 28 million records for 18 columns but the max_query_execution_time is set to 400 seconds. In the minimum reproducible example I'm loading the same data set, but with a max query timeout of 20 seconds.

  1. Expected behaviour:
    Due to max_query_execution_time the query is aborted, fails and indicates to the C++ ODBC caller (= me) that an error occurred by returning an SQL return code of -1 (or 100 SQL_NO_DATA if necessary).

Subsequently, SQLFetch returns an error indication so that the ODBC caller can abort any further SQLFetch calls.

  1. Actual behaviour:
    The Redshift SQLFetch implementation recognizes the error, clears up the PGresult* of RS_RESULT_INFO* and afterwards attempts to retrieve the number of tuples using PQntuples(const PGresult *res). This is a read access violation with gflags. Without gflags this is simply reading out garbage. In a Release build of our application this has led to a number of crashes with a customer using Redshift.

  2. Error message/stack trace:

When activating gflags /p /enable Test.exe /full for our test application we receive:

Unhandled exception thrown: read access violation.
res was 0x236A4BC9F10.

with this stack trace:

>	rsodbc.dll!PQntuples(const pg_result * res) Line 2882	C
 	rsodbc.dll!RS_STMT_INFO::RS_SQLFetchScroll(void * phstmt, short hFetchOrientation, __int64 iFetchOffset) Line 1342	C++
 	rsodbc.dll!SQLFetch(void * phstmt) Line 405	C++
 	[External Code]	
 	Test.exe!main() Line 101	C++
  1. Any other details that can be helpful:
    Things I've found out:
  • _pqGetResultLoopOnThread actually catches that an error occurs and one can see the following error message:
ERROR:  Query (6501378[child_sequence:1]) cancelled by WLM abort action of Query Monitoring Rule "max_query_execution_time".
DETAIL:  
  -----------------------------------------------
  error:  Query (6501378[child_sequence:1]) cancelled by WLM abort action of Query Monitoring Rule "max_query_execution_time".
  code:      1078
  context:   Query (6501378[child_sequence:1]) cancelled by WLM abort action of Query Monitoring Rule "max_query_execution_time".
  query:     0
  location:  wlm_query_action.cpp:179
  process:   wlm [pid=1073782836]
  -----------------------------------------------
  • PQclear(PGresult *res) has been called before calling PQntuples, thus freeing the result.

ODBC trace logs

Reproduction code

Please note that this example code is simply a copy'n'paste of the SQLBindCol exampel code from Microsoft which can be found here: https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlbindcol-function?view=sql-server-ver16

The only changes are:

  • I've connected to our Redshift database using SQLDriverConnectA
  • I've bound 3 of the 18 columns to verify (through debug breakpoints) that data is loaded properly. Which it is.

Other than that it's basically the example code. I hope this can help.

HWND dhwnd = nullptr;
SQLCHAR outstr[1024];
SQLSMALLINT outstrlen;

SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt = 0;
SQLRETURN retcode;

unsigned int nBufferSize = 4096;
auto m_pBuffer = new char[nBufferSize * 4096]();
auto m_pIndicators = new SQLLEN[nBufferSize]{ 0 };

auto m_pBuffer2 = new wchar_t[nBufferSize * 4096]();
auto m_pIndicators2 = new SQLLEN[nBufferSize]{ 0 };

auto m_pBuffer3 = new float[nBufferSize]();
auto m_pIndicators3 = new SQLLEN[nBufferSize]{ 0 };


// Allocate environment handle  
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);

// Set the ODBC version environment attribute  
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
	retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3, 0);

	// Allocate connection handle  
	if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
		retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);

		// Set login timeout to 5 seconds  
		if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
			// Connect to data source  
			retcode = SQLDriverConnectA(hdbc,
				dhwnd,
				(SQLCHAR*)"DSN=AWS Redshift", // DSN we've setup
				SQL_NTS,
				outstr,
				sizeof(outstr),
				&outstrlen,
				SQL_DRIVER_NOPROMPT); 
			SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0);

			// Allocate statement handle  
			if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
				retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);

				retcode = SQLExecDirect(hstmt, (SQLWCHAR*)L"SELECT * FROM \"dev\".\"public\".\"nasty_cat\"", SQL_NTS);
				if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {

					// Bind columns 1, 2, and 3  
					retcode = SQLBindCol(hstmt, 1, SQL_C_CHAR, m_pBuffer, 1028, m_pIndicators);
					retcode = SQLBindCol(hstmt, 2, SQL_C_WCHAR, m_pBuffer2, 1028, m_pIndicators2);
					retcode = SQLBindCol(hstmt, 3, SQL_C_FLOAT, m_pBuffer3, 1028, m_pIndicators3);

					// Fetch and print each row of data. On an error, display a message and exit.  
					for (int i = 0; ; i++) {
						retcode = SQLFetch(hstmt);
						if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
							printf("error\n");
						if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
						{
							// do something meaningful
						}
						else
							break;
					}
				}

				// Process data  
				if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
					SQLCancel(hstmt);
					SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
				}

				SQLDisconnect(hdbc);
			}

			SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
		}
	}
	SQLFreeHandle(SQL_HANDLE_ENV, henv);
}

If there's any other things I can assist you with, I'm happy to help :)

Attempted to read or write protected memory. This is often an indication that other memory is corrupt error with timestamptz column on driver 2.00.00.01

Driver version

2.00.00.01

Redshift version

Redshift 8.0.2
PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.44126

Client Operating System

Win 10 21H2 (19044.2251)

Table schema

Relevant column is of type timestamptz

Problem description

  1. Expected behaviour: return the column properly in a select statement

  2. Actual behaviour: ODBC error

  3. Error message/stack trace:
    Unexpected error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Details:
Microsoft.Mashup.Evaluator.Interface.ErrorException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.Mashup.Engine1.Library.Odbc.Interop.OdbcStatementHandle.GetData(Int32 index, SQL_C sqlctype, IntPtr buffer, Int64 bufferLength, Int64& cbActual)
at Microsoft.Mashup.Engine1.Library.Odbc.OdbcPageReader.OdbcPage.GetData(SQL_C cType, Int32 rowIndex, Int32 columnIndex, Int64 pos)
at Microsoft.Mashup.Engine1.Library.Odbc.OdbcPageReader.OdbcPage.LoadCellData(OdbcPageReaderColumnInfo columnInfo, Column column, Int32 rowIndex, Int32 rowSetIndex, Int32 columnIndex)
at Microsoft.Mashup.Engine1.Library.Odbc.OdbcPageReader.OdbcPage.SyncColumnsPage(Byte* boundColumnsDataPtr)
at Microsoft.Mashup.Engine1.Library.Odbc.OdbcPageReader.OdbcPage.Read(OdbcStatementHandle statement, RowRange rowRange)
at Microsoft.Mashup.Engine1.Library.Odbc.OdbcPageReader.Read(OdbcPage page)
at Microsoft.Mashup.Common.IPageReaderExtensions.NotifyingPageReader.Read(IPage page)
at Microsoft.Mashup.Engine.Interface.Tracing.TracingPageReader.Read(IPage page)
at Microsoft.Mashup.Common.IPageReaderExtensions.NotifyingPageReader.Read(IPage page)
at Microsoft.Mashup.Common.IPageReaderExtensions.NotifyingPageReader.Read(IPage page)
at Microsoft.Mashup.Engine1.Library.Odbc.OdbcDataSource.ExceptionHandlingPageReader.<>c__DisplayClass2_0.b__0()
at Microsoft.Mashup.Engine1.Library.Common.DbExceptionHandler.<>c__DisplayClass11_0.b__0()
at Microsoft.Mashup.Engine1.Library.Common.DbExceptionHandler.RunWithRetryGuard[T](Int32 maxRetryAttempts, Func1 action) at Microsoft.Mashup.Engine1.Library.Common.DbExceptionHandler.Invoke[T](Int32 maxRetry, Func1 action)
at Microsoft.Mashup.Engine1.Library.Common.DbExceptionHandler.InvokeWithoutRetry(Action action)
at Microsoft.Mashup.Engine1.Library.Common.ProgressPageReader.Read(IPage page)
at Microsoft.OleDb.Serialization.PageReaderDataReader.Read()
at Microsoft.Mashup.Engine1.Library.Common.DbData.CachingDbDataReader.<>c__DisplayClass47_0.b__0()
at Microsoft.Mashup.Engine1.Library.Common.DbData.CachingDbDataReader.TraceException(Func1 tracer, Action action) at Microsoft.Mashup.Engine1.Library.Common.DbData.CachingDbDataReader.WrappedRead() at Microsoft.Mashup.Engine1.Library.Common.DbData.CachingDbDataReader.Read() at Microsoft.Mashup.Engine1.Runtime.SkipTakeEnumerator1.MoveNext()
at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.ValuePreviewValueSource.TableValuePreviewValueSource.SerializeRows(Int32 count)
at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.ValuePreviewValueSource.TableValuePreviewValueSource.get_SmallValue()
at Microsoft.Mashup.Evaluator.Interface.TracingPreviewValueSource.get_SmallValue()
at Microsoft.Mashup.Evaluator.RemotePreviewValueSource.<>c__DisplayClass0_0.b__0()
at Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(String entryName, IEngineHost engineHost, IMessageChannel channel, Action action)
--- End of inner exception stack trace ---
at Microsoft.Mashup.Evaluator.EvaluationHost.<>c__DisplayClass17_0.b__1()
at Microsoft.Mashup.Common.SafeExceptions.IgnoreSafeExceptions(IEngineHost host, IHostTrace trace, Action action)
at Microsoft.Mashup.Evaluator.EvaluationHost.TryReportException(IHostTrace trace, IEngineHost engineHost, IMessageChannel channel, Exception exception)
at Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(String entryName, IEngineHost engineHost, IMessageChannel channel, Action action)
at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.<>c__DisplayClass12_11.<OnBeginGetResult>b__0() at Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(IHostTrace trace, IEngineHost engineHost, IMessageChannel channel, Action action) at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetResult[T](IMessageChannel channel, BeginGetResultMessage message, Action1 action)
at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetPreviewValueSource(IMessageChannel channel, BeginGetPreviewValueSourceMessage message)
at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.ChannelMessenger.OnMessageWithUnknownChannel(IMessageChannel baseChannel, MessageWithUnknownChannel messageWithUnknownChannel)
at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.EvaluationHost.Run()
at Microsoft.Mashup.Container.EvaluationContainerMain.Run(Object args)
at Microsoft.Mashup.Evaluator.SafeThread2.<>c__DisplayClass9_0.b__0(Object o)
at Microsoft.Mashup.Container.EvaluationContainerMain.SafeRun(String[] args)
at Microsoft.Mashup.Container.EvaluationContainerMain.Main(String[] args)
--- End of inner exception stack trace ---
at Microsoft.Mashup.Evaluator.EvaluationHost.OnException(IEngineHost engineHost, IMessageChannel channel, ExceptionMessage message)
at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.Interface.IMessageChannelExtensions.WaitFor[T](IMessageChannel channel)
at Microsoft.Mashup.Evaluator.RemotePreviewValueSource.PreviewValueSource.WaitFor(Func1 condition, Boolean disposing) at Microsoft.Mashup.Evaluator.RemotePreviewValueSource.PreviewValueSource.get_SmallValue() at Microsoft.Mashup.Evaluator.Interface.TracingPreviewValueSource.get_SmallValue() at Microsoft.Mashup.Host.Document.Analysis.PackageDocumentAnalysisInfo.PackagePartitionAnalysisInfo.SetPreviewValue(EvaluationResult21 result, Func1 getStaleSince, Func1 getSampled)

  1. Any other details that can be helpful:
    Works as expected with driver 1.04.59.1000

ODBC trace logs

Not sure how to collect these

Reproduction code

Don't have it, using it as a query in PowerBI.

Unicode chars incorrectly read with driver 2.0

Driver version

2.00.00.01

Redshift version

Redshift 8.0.2
PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.44126

Client Operating System

Win 10 21H2 (19044.2251)

Table schema

Any varchar column

Problem description

  1. Expected behaviour: Non-printable Unicode characters shouldn't be shown.
  2. Actual behaviour: Non-printable Unicode characters are shown
  3. Error message/stack trace: N/A
  4. Any other details that can be helpful: Problem is easy to reproduce. Store a concat of CHR(8203) and any string. Unicode 8203 is "zero width space". JDBC driver and ODBC v1 properly output this as empty space to clients.

ODBC trace logs

N/A

Reproduction code

Any table with a varchar column. Insert data containing char(8203), and try to consume in clients. In my case, the client is PowerBI. Messy values with the new driver
image

old driver, same dataset, showing the right values
image

Regression. Invalid streaming cursor state. Unable to open 2 SQLHSTMT in the same SQLHDBC when using certain queries

Driver version

AmazonRedshiftODBC64-2.0.0.1.msi

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.44126

Client Operating System

Windows/Linux

Table schema

dev

Problem description

  1. Expected behaviour: Expected to work as described in the API
  2. Actual behaviour: Invalid streaming cursor state
  3. Error message/stack trace: [HY000] [Redshift][ODBC Driver]Invalid streaming cursor state (0)
  4. Any other details that can be helpful:

I had a problem in application using this version of the driver. I wrote a simple test to simplify the reproduction.
This is a regression problem, in the old version of the "AmazonRedshiftODBC64-1.4.62.1000" driver works fine.
Reproduction is very simple. Need to open 2 statements with a specific queries within 1 session and the driver breaks.

redshift_bug.txt
Attached test file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.