Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

MySQL INTO OUTFILE Write Permissions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MySQL INTO OUTFILE Write Permissions

    I moved my development server to a new Win 7 machine. Everything works on the new machine, except I am having trouble with a sql statement that executes, but produces no result.

    dim sqlpath as c = "[PathAlias.ADB_Path]" + "\\" + "QBexport" + "\\"
    sqlpath = filename_decode(sqlpath)
    sqlpath = stuff(sqlpath,1,2,"")
    sqlpath = stritran(sqlpath,"\\","/")
    sqlpath = " '" + sqlpath + "QBexport" + timestamp + ".iif'"

    sql = <<%sql%
    SET @qbinsert = CONCAT ('QBexport',:A,'.iif');
    SET @t3 = :B;
    SET @user = :C;
    SET @compID = :D;
    SET @sqlpath = :E;
    SET @sql_text =
    CONCAT ("SELECT * FROM `qb_table2` into outfile", @sqlpath,"
    FIELDS ENCLOSED BY \'\"\'
    TERMINATED BY \'\t\'
    ESCAPED BY \'\n\';");
    PREPARE s1 FROM @sql_text;
    EXECUTE s1;
    DROP PREPARE s1;
    INSERT INTO qbdownload (fileUploadChar, fileNameShort, CreateTime, UploadedBy, Company_FK) values (@qbinsert, @qbinsert, @t3, @user, @compID)
    %sql%

    args.add("A",timestamp)
    args.add("B",t3)
    args.add("C",userName)
    args.add("D",comp_ID)
    args.add("E",sqlpath)

    flag = cn.execute(sql,args)

    This should do two things. First, create a file in a folder on the development server. Second, insert a record into the qbdownload table.

    The flag returns true, but it accomplishes neither task.

    I still have my old development machine, also Win 7, up and running, and it works fine there.

    I have tried various versions of this, and have discovered that if I eliminate the code for the into outfile, it will successfully execute the insert.

    I cannot get it to produce a file using into outfile.

    I think it is a security/permissions issue. I believe I need to grant write access (to folders) to localhost. But I have looked and looked and have not found the solution.

    #2
    Re: MySQL INTO OUTFILE Write Permissions

    What MySQL errcode are you getting back?

    I think you're making this a bit too difficult. I would break this into 2 sql statements. The following works. You didn't supply some of the variables, so I just made them up.

    Where, exactly, or relatively, do you want your .iif file created. Mine is just going into the PathAlias location, but it can go anywhere. I'm not running into any security issues.

    Code:
    function sqlTest as c (e as p)
    	
    debug(1)
    	
    dim cn as sql::Connection
    dim flag as l
    dim sqlStmt as c
    dim rs as sql::ResultSet
    dim args as sql::arguments
    
    flag = cn.open("::Name::Test")
    
    if flag then
    
    	dim st as Y
    	st = now()
    
    	dim sqlpath as c = "[PathAlias.ADB_Path]" + "\\" + "QBexport" + "\\"
    	dim timestamp as c = cshorttime(st)
    	sqlpath = filename_decode(sqlpath)
    '	sqlpath = stuff(sqlpath,1,2,"")
    '	sqlpath = stritran(sqlpath,"\\","/")
    	sqlpath = sqlpath + "QBexport" + timestamp + ".iif"	
    '	sqlpath = " '" + sqlpath + "QBexport" + timestamp + ".iif'"	
    	
    	sqlStmt = <<%sql%
    	SELECT * INTO OUTFILE :sqlPath
    	FIELDS ENCLOSED BY '"' 
    	TERMINATED BY '\t' 
    	ESCAPED BY '\n'
    	FROM tblCustomers
    	%sql%
    
    	args.set("sqlPath",sqlpath)
    	flag = cn.execute(sqlStmt,args)		
    	
    	sqlStmt = "INSERT INTO qbdownload (fileUploadChar, fileNameShort, CreateTime, UploadedBy, Company_FK) values (:qbinsert, :qbinsert, :t3, :user, :compID)"
    
    	args.set("qbinsert","QBexport" + timestamp + ".iif")
    	args.set("t3",date())
    	args.set("user","Username")
    	args.set("compId","1234")
    
    	flag = cn.Execute(sqlStmt,args)
    	if flag then
    		'ALL OK
    	else
    		'there was an error - close the connection and exit
    		cn.Close()
    		dim msg as c 
    		msg = "Could not execute the query. Error reported was: " + cn.CallResult.text
    		msg = js_escape(msg)
    		dim jscmd as c 
    		jscmd = "alert('" + msg + "');"
    		sqlTest = jscmd
    		exit function
    	end if  
    	
    else
    	'there was an error - close the connection and exit
    	dim msg as c 
    	msg = "Could not open the connection. Error reported was: " + cn.CallResult.text
    	msg = js_escape(msg)
    	dim jscmd as c 
    	jscmd = "alert('" + msg + "');"
    	sqlTest = jscmd
    	exit function
    end if
    
    cn.close()
    	
    end function

    Comment


      #3
      Re: MySQL INTO OUTFILE Write Permissions

      I am not getting any MySql error code.

      I've tried separating it into two statements. The insert statement works just fine.

      Running the into outfile part by itself fails, with no error code.
      sqlIIF = <<%sql%
      SET @sqlpath = :E;
      SET @sql_text =
      CONCAT ("SELECT * FROM `qb_table2` into outfile", @sqlpath,"
      FIELDS ENCLOSED BY \'\"\'
      TERMINATED BY \'\t\'
      ESCAPED BY \'\n\';");
      PREPARE s1 FROM @sql_text;
      EXECUTE s1;
      DROP PREPARE s1;
      %sql%

      I ran this in the Sql Command Window:

      SET @sql_text =
      CONCAT ("SELECT * FROM `qb_table2` into outfile", 'c:/Alpha5/FreightZone/QBexport/QBexport.iif',"
      FIELDS ENCLOSED BY \'\"\'
      TERMINATED BY \'\t\'
      ESCAPED BY \'\n\';");
      PREPARE s1 FROM @sql_text;
      EXECUTE s1;
      DROP PREPARE s1

      It returned "SQL command result: Success", but the file is not created.

      David, I like the way you have simplified it. I will work on it using your example.

      While researching INTO OUTFILE I read "The MySQL server process must have write access to the target file". I am writing to a folder within the PathAlias location. I can upload and download to other folders within the PathAlias location. Does INTO OUTFILE, because it is executing directly from MySql, need some special permission setting?

      Comment


        #4
        Re: MySQL INTO OUTFILE Write Permissions

        David, in working with your example, I changed the connection name and the name of the table in sqlStmt. However, the first flag = cn.execute(sqlStmt,args) returns false.

        The second sqlStmt works. It inserts a record into qbdownload table.

        dim todaysDate as d = date()
        dim stamp as c = dtoc(todaysDate,"1-")
        '12-14-15 This is DavidK's code

        dim cn as sql::Connection
        dim flag as l
        dim sqlStmt as c
        dim rs as sql::ResultSet
        dim args as sql::arguments

        flag = cn.open("::Name::FreightZoneMySql")

        if flag then

        dim st as Y
        st = now()

        dim sqlpath as c = "[PathAlias.ADB_Path]" + "\\" + "QBexport" + "\\"
        dim timestamp as c = cshorttime(st)
        sqlpath = filename_decode(sqlpath)
        ' sqlpath = stuff(sqlpath,1,2,"")
        ' sqlpath = stritran(sqlpath,"\\","/")
        sqlpath = sqlpath + "QBexport" + timestamp + ".iif"
        ' sqlpath = " '" + sqlpath + "QBexport" + timestamp + ".iif'"

        sqlStmt = <<%sql%
        SELECT * INTO OUTFILE :sqlpath
        FIELDS ENCLOSED BY '"'
        TERMINATED BY '\t'
        ESCAPED BY '\n'
        FROM qb_table2
        %sql%
        debug(1)
        args.set("sqlPath",sqlpath)
        flag = cn.execute(sqlStmt,args) 'flag = .F.

        sqlStmt = "INSERT INTO qbdownload (fileUploadChar, fileNameShort, CreateTime, UploadedBy, Company_FK) values (:qbinsert, :qbinsert, :t3, :user, :compID)"

        args.set("qbinsert","QBexport" + timestamp + ".iif")
        args.set("t3",date())
        args.set("user","Username")
        args.set("compId","1234")

        flag = cn.Execute(sqlStmt,args)
        if flag then
        'ALL OK
        else
        'there was an error - close the connection and exit
        cn.Close()
        dim msg as c
        msg = "Could not execute the query. Error reported was: " + cn.CallResult.text
        msg = js_escape(msg)
        dim jscmd as c
        jscmd = "alert('" + msg + "');"
        sqlTest = jscmd
        exit function
        end if

        else
        'there was an error - close the connection and exit
        dim msg as c
        msg = "Could not open the connection. Error reported was: " + cn.CallResult.text
        msg = js_escape(msg)
        dim jscmd as c
        jscmd = "alert('" + msg + "');"
        sqlTest = jscmd
        exit function
        end if

        cn.close()

        Comment


          #5
          Re: MySQL INTO OUTFILE Write Permissions

          You're better off running this in a function and debugging your way through it. The connection object returns properties containing an error code and message if there are any. I didn't have to set any write access... I believe that just means you can write to the drive... that it's not set read-only.

          Does your full path exist? It must. Not the file name... but the path... the folder structure must be in place. You're only creating a file... not a structure.

          As you step through the code, you can access any of the variables set. You can type these variable names into the debugger Expression section, or double-click on a variable name in the debugger code. Below is what you want to see as Expressions before you get to the statement that set the vars.

          SQL_Output.PNG
          Last edited by Davidk; 12-14-2015, 12:24 PM.

          Comment


            #6
            Re: MySQL INTO OUTFILE Write Permissions

            So I simplified my code, to just creating a file using into outfile.

            It works as expected on my former development machine. On the new machine, no error, and no file created. So something must be different.

            In comparing the two machines:

            AA logs onto MySql as root, and the user settings in MySql for root are identical.
            qb_table2 is identical.
            The folder security settings are identical.



            dim todaysDate as d = date()
            dim stamp as c = dtoc(todaysDate,"1-")
            t1 = time("", now() )
            t2 = time("-0h_0m_0s_2", t1)
            dim timestamp as c = stamp + t2
            dim t3 as c = time("0h:0m:0s",t1)

            dim cn as SQL::Connection
            dim flag as l
            dim args as sql::arguments
            flag = cn.open("::Name::FreightZoneMySql")

            dim sqlpath as c = "[PathAlias.ADB_Path]" + "\\" + "QBexport" + "\\"
            sqlpath = filename_decode(sqlpath)
            sqlpath = stuff(sqlpath,1,2,"")
            sqlpath = stritran(sqlpath,"\\","/")
            sqlpath = " '" + sqlpath + "QBexport" + timestamp + ".iif'"

            dim sql as c
            sql = <<%sql%
            SET @sqlpath = :E;
            SET @sql_text =
            CONCAT ("SELECT * FROM `qb_table2` into outfile", @sqlpath,"
            FIELDS ENCLOSED BY \'\"\'
            TERMINATED BY \'\t\'
            ESCAPED BY \'\n\';");
            PREPARE s1 FROM @sql_text;
            EXECUTE s1;
            DROP PREPARE s1;
            %sql%

            args.set("A",timestamp)
            args.set("B",t3)
            args.set("E",sqlpath)

            flag = cn.Execute(sql,args)
            cn.Close()

            Comment


              #7
              Re: MySQL INTO OUTFILE Write Permissions

              See post # 5 for additional info added.

              Comment


                #8
                Re: MySQL INTO OUTFILE Write Permissions

                Progress! I had just realized that I need to dig deeper into the debugging results....

                cn.CallResult.NativeText = The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

                I suspected it was some kind of permission setting with MySql.

                Comment


                  #9
                  Re: MySQL INTO OUTFILE Write Permissions

                  David, thanks for your help.

                  Here is what solved my problem:

                  Edit the my.ini file. Default location for windows is c:\ProgramData\MySQL\MySQL Server 5.6\my.ini

                  my.ini contains all the startup settings for MySql.


                  After making a backup copy of my.ini, Find and delete these lines:

                  # Secure File Priv.
                  secure-file-priv="C:/ProgramData/MySQL/MySQL Server 5.6/Uploads"

                  Stop the MySQL server and restart.

                  Apparently this only affects certain commands. INTO OUTFILE is one of them.

                  Comment


                    #10
                    Re: MySQL INTO OUTFILE Write Permissions

                    Good to hear. I couldn't work without the debugger... both XBasic and Javacsript. They are essential.

                    Comment

                    Working...
                    X