Search code examples
mysqlvbscriptinto-outfile

Get path from VBscript variable to use with obj.sql(extQuery) extQuery = select * from table name into outfile '????'


I have this code i need to retrieve a path from a VBScript variable and use it with a mysql query.

set fso = WScript.CreateObject("Scripting.FileSystemObject")
Mypath = fso.GetAbsolutePathName(".")
Fullpath = fso.buildpath(Mypath,"test.txt")

then later in the code i need to launch a query with:

obj.sql(extQuery)

extQuery = "select * from table_name into outfile '?????'.....

What do i need to do to get the path from my variable and use it in the query ? Hope someone could show me an example. Thanks !


Solution

  • You use string concatiantion

    obj.sql(extQuery)
    
    extQuery = "select * from table_name into outfile '" & Fullpath  &  "'....
    
    
    extQuery = "SELECT *  INTO OUTFILE '" & Fullpath   & "'
      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
      LINES TERMINATED BY '\n'
      FROM table_name ;".
    

    You have also to add

     Fullpath = Replace(Fullpath , "\", "/") 
    

    As the \is an escape parameter in mysql