Skip to content

Commit

Permalink
Merge pull request #45 from lahma/boolean_scalar_fix
Browse files Browse the repository at this point in the history
Use Convert.ToBoolean to parse returned scalar from database when expect...
  • Loading branch information
ferventcoder committed Jan 9, 2012
2 parents d13bd40 + da9fc62 commit c162fb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions db/SQLServer/TestRoundhousE/custom_db_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ USE master
IF NOT EXISTS(SELECT * FROM sys.databases WHERE [name] = '{{DatabaseName}}')
BEGIN
CREATE DATABASE {{DatabaseName}}
-- signal success
SELECT 1
END
21 changes: 14 additions & 7 deletions product/roundhouse/databases/DefaultDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,19 @@ public virtual bool create_database_if_it_doesnt_exist(string custom_create_data
{
foreach (var sql_statement in StatementSplitter.split_sql_on_regex_and_remove_empty_statements(create_script, sql_statement_separator_regex_pattern))
{
var return_value = run_sql_scalar(sql_statement, ConnectionType.Admin);
//should only receive a return value once
var return_value = run_sql_scalar_boolean(sql_statement, ConnectionType.Admin);
if (return_value != null)
{
database_was_created = (bool)return_value;
database_was_created = return_value.Value;
}
}
}
else
{
var return_value = run_sql_scalar(create_script, ConnectionType.Admin);
//should only receive a return value once
if (return_value != null)
{
database_was_created = (bool)return_value;
}
var return_value = run_sql_scalar_boolean(create_script, ConnectionType.Admin);
database_was_created = return_value.GetValueOrDefault(false);
}
}
catch (Exception ex)
Expand All @@ -131,6 +128,16 @@ public virtual bool create_database_if_it_doesnt_exist(string custom_create_data
return database_was_created;
}

private bool? run_sql_scalar_boolean(string sql_to_run, ConnectionType connection_type)
{
var return_value = run_sql_scalar(sql_to_run, connection_type);
if (return_value != null && return_value != DBNull.Value)
{
return Convert.ToBoolean(return_value);
}
return null;
}

public void set_recovery_mode(bool simple)
{
try
Expand Down

0 comments on commit c162fb4

Please sign in to comment.