@@ -273,6 +273,33 @@ func TestRunInputFiles(t *testing.T) {
273273 }
274274}
275275
276+ // TestInitialQueryWithInputFile verifies that -q (initial query) executes before -i (input files)
277+ func TestInitialQueryWithInputFile (t * testing.T ) {
278+ o , err := os .CreateTemp ("" , "sqlcmdmain" )
279+ assert .NoError (t , err , "os.CreateTemp" )
280+ defer os .Remove (o .Name ())
281+ defer o .Close ()
282+ args = newArguments ()
283+ // Use -q to change session language, then -i to verify the setting persists
284+ // The initial query sets LANGUAGE to German, then the script selects @@LANGUAGE
285+ args .InitialQuery = "SET LANGUAGE German"
286+ args .InputFile = []string {"testdata/select_init_value.sql" }
287+ args .OutputFile = o .Name ()
288+ setAzureAuthArgIfNeeded (& args )
289+ vars := sqlcmd .InitializeVariables (args .useEnvVars ())
290+ vars .Set (sqlcmd .SQLCMDMAXVARTYPEWIDTH , "0" )
291+ setVars (vars , & args )
292+
293+ exitCode , err := run (vars , & args )
294+ assert .NoError (t , err , "run" )
295+ assert .Equal (t , 0 , exitCode , "exitCode" )
296+ bytes , err := os .ReadFile (o .Name ())
297+ if assert .NoError (t , err , "os.ReadFile" ) {
298+ // Verify that the language set in the initial query is reflected in the script output
299+ assert .Contains (t , string (bytes ), "Deutsch" , "Initial query should execute before input file" )
300+ }
301+ }
302+
276303func TestUnicodeOutput (t * testing.T ) {
277304 o , err := os .CreateTemp ("" , "sqlcmdmain" )
278305 assert .NoError (t , err , "os.CreateTemp" )
0 commit comments