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

Fix separation of columns #129

Merged
merged 7 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions odbc_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,7 @@ odbcImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
SQLLEN indicator;
const char* schema_name;
bool missing_foreign_schema = false;
bool first_column = true;

elog_debug("%s", __func__);

Expand Down Expand Up @@ -2008,10 +2009,15 @@ odbcImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
elog(NOTICE, "Data type not supported (%d) for column %s", DataType, ColumnName);
continue;
}
if (i > 1)
if (!first_column)
{
appendStringInfo(&col_str, ", ");
}
else
{
first_column = false;
}

appendStringInfo(&col_str, "\"%s\" %s", ColumnName, (char *) sql_type.data);
}
SQLCloseCursor(query_stmt);
Expand Down Expand Up @@ -2055,9 +2061,10 @@ odbcImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
if (SQL_SUCCESS == ret)
{
int excluded = false;
SQLRETURN getdata_ret;
TableName = (SQLCHAR *) palloc(sizeof(SQLCHAR) * MAXIMUM_TABLE_NAME_LEN);
ret = SQLGetData(tables_stmt, SQLTABLES_NAME_COLUMN, SQL_C_CHAR, TableName, MAXIMUM_TABLE_NAME_LEN, &indicator);
check_return(ret, "Reading table name", tables_stmt, SQL_HANDLE_STMT);
getdata_ret = SQLGetData(tables_stmt, SQLTABLES_NAME_COLUMN, SQL_C_CHAR, TableName, MAXIMUM_TABLE_NAME_LEN, &indicator);
check_return(getdata_ret, "Reading table name", tables_stmt, SQL_HANDLE_STMT);

/* Since we're not filtering the SQLTables call by schema
we must exclude here tables that belong to other schemas.
Expand All @@ -2066,8 +2073,8 @@ odbcImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
So we only reject tables for which the schema is not
blank and different from the desired schema:
*/
ret = SQLGetData(tables_stmt, SQLTABLES_SCHEMA_COLUMN, SQL_C_CHAR, table_schema, MAXIMUM_SCHEMA_NAME_LEN, &indicator);
if (SQL_SUCCESS == ret)
getdata_ret = SQLGetData(tables_stmt, SQLTABLES_SCHEMA_COLUMN, SQL_C_CHAR, table_schema, MAXIMUM_SCHEMA_NAME_LEN, &indicator);
if (SQL_SUCCESS == getdata_ret)
{
if (!is_blank_string((char*)table_schema) && strcmp((char*)table_schema, schema_name) )
{
Expand Down
37 changes: 29 additions & 8 deletions test/appveyor_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,33 @@
function Merge-Tokens($template, $tokens)
{
return [regex]::Replace(
$template,
'\$\{(?<tokenName>\w+)\}',
{
param($match)
$tokenName = $match.Groups['tokenName'].Value
return $tokens[$tokenName]
})
[regex]::Replace(
$template,
'\$\{(?<tokenName>\w+)\}',
{
param($match)
$tokenName = $match.Groups['tokenName'].Value
return $tokens[$tokenName]
}),
'(?ms)^\-\-\s+\!OUTPUT\!\s+.*?$',
''
)
}

function Merge-TokensExpected($template, $tokens)
{
return [regex]::Replace(
[regex]::Replace(
$template,
'\$\{(?<tokenName>\w+)\}',
{
param($match)
$tokenName = $match.Groups['tokenName'].Value
return $tokens[$tokenName]
}),
'(?ms)^\-\-\s+\!OUTPUT\!\s+',
''
)
}

# https://www.appveyor.com/docs/services-databases
Expand Down Expand Up @@ -43,8 +63,9 @@ $Config = @{
foreach ($c in $Config.GetEnumerator()) {
$tpl = Get-Content "$PSScriptRoot\template\$($c.Name)_installation_test.tpl" -Raw
$generated_test = Merge-Tokens $tpl $($c.Value)
$generated_test_expected = Merge-TokensExpected $tpl $($c.Value)
Set-Content -Path "$PSScriptRoot\sql/$($c.Name)_10_installation_test.sql" -Value $generated_test
Set-Content -Path "$PSScriptRoot\expected\$($c.Name)_10_installation_test.out" -Value $generated_test
Set-Content -Path "$PSScriptRoot\expected\$($c.Name)_10_installation_test.out" -Value $generated_test_expected
}

$env:Path += ";C:\Program Files\MySQL\MySQL Server 5.7\bin"
Expand Down
6 changes: 6 additions & 0 deletions test/expected/sqlserver_20_query_test.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ SELECT * FROM ODBCQuerySize('sqlserver_fdw', 'select * from sqlserver_test_table
1
(1 row)

SELECT * FROM sqlserver_test_table_with_unsupported_initial_column;
id | name
----+------
1 | aaaa
(1 row)

4 changes: 4 additions & 0 deletions test/fixtures/sqlserver_fixtures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ begin
-- Create fixture
create table sqlserver_test_table(id int, name text);
insert into sqlserver_test_table values (1, 'aaaa');

create table sqlserver_test_table_with_unsupported_initial_column(ignored varbinary(10), id int, name text);
insert into sqlserver_test_table_with_unsupported_initial_column(id, name) values (1, 'aaaa');

end
go
3 changes: 2 additions & 1 deletion test/sql/sqlserver_20_query_test_disabled.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SELECT * FROM sqlserver_test_table;
SELECT * FROM ODBCTablesList('sqlserver_fdw', 1);
SELECT * FROM ODBCTableSize('sqlserver_fdw', 'sqlserver_test_table');
SELECT * FROM ODBCQuerySize('sqlserver_fdw', 'select * from sqlserver_test_table');
SELECT * FROM ODBCQuerySize('sqlserver_fdw', 'select * from sqlserver_test_table');
SELECT * FROM sqlserver_test_table_with_unsupported_initial_column;
3 changes: 2 additions & 1 deletion test/template/sqlserver_installation_test.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ IMPORT FOREIGN SCHEMA dbo
INTO public
OPTIONS(
ApplicationIntent 'ReadOnly'
);
);
-- !OUTPUT! NOTICE: Data type not supported (-3) for column ignored