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

Variable names with underscore characters ('_') are not getting substituted #129

Closed
jarnoj opened this issue Jan 27, 2022 · 2 comments · Fixed by #130
Closed

Variable names with underscore characters ('_') are not getting substituted #129

jarnoj opened this issue Jan 27, 2022 · 2 comments · Fixed by #130
Labels
bug Something isn't working

Comments

@jarnoj
Copy link

jarnoj commented Jan 27, 2022

Here is example that uses variable substitution (same SQL script also attached below). It inserts a new row where the First_Name variable does not get substituted (but LastName variable works ok):

DECLARE @FirstName VARCHAR(255)='#{First_Name}' -- underscore causes some issue
DECLARE @LastName VARCHAR(255)='#{LastName}'  -- this works (no underscore)

IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Employee]') AND type in (N'U'))
	CREATE TABLE [dbo].[Employee]( FirstName varchar(20), LastName varchar(20));

INSERT INTO dbo.Employee(FirstName, LastName) VALUES(@FirstName, @LastName)

SQLQuery1.zip

Related PowerShell commands (tested with v0.7.0 dbops module):

# create a package
$scriptPath = ''
$pkgPath = 'C:\tmp\dbops_var_test\pkg.zip'
$includePattern = '.*\.sql'
New-DBOPackage -Path $pkgPath -ScriptPath $scriptPath -Match $includePattern -Force

# deploy the package
$server = '.\SQL2017'
$db = 'Foo'
Install-DBOPackage -Path $pkgPath -Variables @{ First_Name = 'John'; LastName = 'Doe' } -SqlInstance $server -Database $db -SchemaVersionTable $null -CreateDatabase
@nvarscar nvarscar added the bug Something isn't working label Jan 28, 2022
@nvarscar
Copy link
Collaborator

This is controlled by the following regex, which only accounts for . and -:
https://github.com/dataplat/dbops/blob/development/internal/functions/Resolve-VariableToken.ps1#L27

Should be a simple fix.

@nvarscar
Copy link
Collaborator

Fixed in 0.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants