vscode-cfml icon indicating copy to clipboard operation
vscode-cfml copied to clipboard

Syntax highlighting breaks with \#

Open Daemach opened this issue 2 years ago • 2 comments

Great library. I appreciate your time in developing and maintaining it. With the code below, syntax highlighting breaks on the line that restores the database, with the first instance of #. If you insert a space, it fixes the highlighting but breaks the file path, of course.

  function restoreDBase(name, backup=true, backupPath="h:") {
    
    fileWrite("#getTempDirectory()#/#arguments.name#.bak", hyper.get('https://myserver/#arguments.name#.bak').getData())
    utils.notify("#name# restore started...","Updating...","info", 3000)
    saveContent variable="saved" {
      dump("Download complete.  Restoring...");
      var res = queryExecute("
        use master

        ALTER DATABASE #ARGUMENTS.NAME# SET SINGLE_USER WITH ROLLBACK IMMEDIATE

        RESTORE DATABASE #ARGUMENTS.NAME# FROM  DISK = N'#getTempDirectory()#\#arguments.name#.bak' WITH  FILE = 1,  MOVE N'#ARGUMENTS.NAME#' TO N'H:\MSSQL\Data\#ARGUMENTS.NAME#.mdf',  MOVE N'#ARGUMENTS.NAME#_log' TO N'H:\MSSQL\Data\#ARGUMENTS.NAME#_log.ldf',  NOUNLOAD,  REPLACE,  STATS = 5

        ALTER DATABASE [#ARGUMENTS.NAME#] SET MULTI_USER

        use #arguments.name#
        DROP USER IF EXISTS cfusion
        CREATE USER cfusion FOR LOGIN cfusion
        EXEC sp_addrolemember N'db_owner', N'cfusion'

        DROP USER IF EXISTS marsuser
        CREATE USER marsuser FOR LOGIN marsuser
        EXEC sp_addrolemember N'db_owner', N'marsuser'
      ")

      dump(res);
      dump("Deleting #arguments.name#.bak");

      if ( arguments.backup ){
        fileCopy("#getTempDirectory()#/#arguments.name#.bak", "#backupPath#/#arguments.name#.bak")
      }
      fileDelete("#getTempDirectory()#/#arguments.name#.bak")
    }
    utils.notify("#name# restore complete!","Done","info", 3000)
    return saved
  }

Daemach avatar Jan 11 '22 18:01 Daemach

Just an FYI, a workaround would be using named params in your SQL statement as follows:

use :dbName

and then use named params in queryExecute() as follows:

queryExecute(sql="
        use master
        ....
        use :dbName
    ", 
    params=[
        {name="dbName", value=arguments.name, cfsqltype="cf_sql_varchar"}
    ],
    options={
        datasource: dsn
    }
);

redtopia avatar Jan 11 '22 21:01 redtopia

@redtopia no argument here. I was just being lazy, but figured this might pop up in other cases as well.

Daemach avatar Jan 11 '22 22:01 Daemach