Pass Windows path to MySQL stored procedure - mysql

I have a stored procedure based on this question: How to store output of a stored procedure on to disk. For some reason I can't make it work with a Windows path. Always get the file writing error.
Any idea on how to pass the parameter?

Just tried this and struggled a bit too. Here's how I got it working:
On the folder(s) where MySQL will write files, make sure the appropriate privileges are given for write access. If security isn't a concern, a brute-force way of doing this is to right-click on the root folder, click on Properties -> Security tab, add "Everyone" and grant "Full Control". However, depending on where and why you are doing this you might need to be a lot more careful/selective...
Run the stored proc using something like:
CALL export_dynamic('C:/dump/test1.txt');
...or...
CALL export_dynamic('C:\\\\dump\\\\test2.txt');
(assuming C:\dump is the folder where files will be written with the permissions set as above.)
Note: There are other possible issues with disk space, anti-virus etc. but personally I didn't see anything like that (have Microsoft Security Essentials running).

The file name must be given as a literal string. On Windows, specify backslashes in path names as forward slashes or doubled backslashes.
As of MySQL 5.1.6, the character_set_filesystem system variable controls the interpretation of the file name.

It should be a permission issue... Check the folder permissions of the folder you are trying to write. Grant access to everyone.. Right Click on folder -> Properties -> Permissions -> Everyone -> Give full rights... now run the script.

Related

LOAD_FILE returns NULL

I am trying to insert an image into my MySQL server. I have done some research and it looks like the best way to do that is through LOAD_FILE(). However, LOAD_FILE() always returns null. I know there are 4 conditions for LOAD_FILE():
The file must be located on the server host
You must specify the full path name to the file, and you must have the FILE privilege.
The file must be readable by all and its size less than max_allowed_packet bytes.
If the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.
I am currently using:
select LOAD_FILE('/Users/pricedb/Desktop/FolderName/imageName');
and it returns NULL
I have confirmed that all privileges are granted to the user. What does it mean that the file must be located on the server host? The server is being run off my local computer and and file is located there, so does that mean I am good on that?
Any advice would be greatly appreciated, I do not know why it's not returning a value.
I had the same issue.
Fond out that the file to be loaded, needs to be in the folder location where mysql/mariadb has privileges to read it.
It can be configured, BUT the data folder is already has access right.
In my case I copied my file to data folder: C:\Program Files\MariaDB 10.3\data
And than I just called it with full path:
select load_file('C:\\Program Files\\MariaDB 10.3\\data\\test.txt');
Here is my command on windows 7:
select load_file("C:/Program Files (x86)/MySQL/MySQL Workbench CE 6.0.7/images/hieuImages/a.jpg");
And it worked!
You maybe try to copy your images into that directory and select again in mysql.
"FILE" is an administrative privilege.
When you say that ALL privileges have been granted, does that include global administrative privileges too?
Here's the syntax http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-global-privileges, but I found "MySQL Workbench" GUI more helpful.
Check out OS file permissions, too.
Using MySQL Workbench 8.0:
In the Result Grid panel where you can see the rows and columns, right-click the cell that will hold the BLOB value (currently shown as NULL).
In the context menu that appears, select the first item: Open Value in Editor.
In the lower-left corner, there are two buttons. Click on: Load...
Browse to your image file.
The Binary tab is filled with the image's binary data.
Click: Apply. You'll return to the Result Grid panel again. Notice NULL has been replaced by BLOB.
Right-click BLOB and select Open Value in Editor once more.
You'll find a new tab at the top: Image. There you can preview the image you just added.
Greetings!
show variables like 'secure_file_priv';
Load file in this directory.
select load_file('directory_from_1');

TCL/TK - Get Desktop path

My TCL/TK application prompts the user to choose a location where to save a file.
What should the value of the -initialdir option be so that the Desktop is the default location?
I tried %userprofile%\desktop, but it's not working.
set dir [tk_chooseDirectory -title "Where do you want to save the config file?" -initialdir %userprofile%\desktop]
Thanks
The safest way is to use twapi's get_shell_folder command with the argument "csidl_common_desktopdirectory" to get the path to the "all users" desktop directory, or "csidl_desktopdirectory" to get the current user's desktop.
If you don't want to depend on twapi, the paths can be found in the registry, but I don't know how reliable it is. For example:
package require registry
puts [registry get "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders" "Desktop"]
This returns "%USERPROFILE%\Skrivbord" on my system. You still have to expand the USERPROFILE variable (and any other variables). That's best done with twapi::expand_environment_strings, but since you're not using twapi, try regsub:ing %USERPROFILE% with $env(HOME) instead.
Or if you don't care about people with non-english Windows, just use "~/Desktop".

Can I add some public meta data to an encrypted Access 2010 database?

My application stores its data in an Access 2010 database (accdb) file. It's password protected, which means it's encrypted w/ AES-128.
I'd like to add some meta data to the file that's publically available. This way older verisons of my application can investigate the file to see if it's even worth trying to open. Otherwise, they'll just get the dreaded "Unrecognized Database Format" error, which is usually associated with file corruptions.
In Windows, you can right-click on a file, click "Properties" and see attributes under the Details tab. I'd love it if I add attributes like the version of my application that last touched the file, and maybe other details. I'd like to avoid having a different file extension for each version of my app!
Is it possible to add some public meta data to an encrypted Access 2010 database?
You can add custom database properties : http://support.microsoft.com/default.aspx?scid=kb;en-us;q178745
You can change the file extension of an encrypted Access database and change the properties for that extension. The extension .enc is fairly descriptive and does not seem to be widely used.
The file will open normally when clicked and ask for the password. The icon will be recognizably Access and the description, "Encrypted MS Access" in this case, will appear under Type in a directory listing.
With NTFS, you can add an alternate data stream (ADS):
notepad.exe z:\docs\testde.enc:Extra.txt
Reading the stream:
more < testde.enc:extra.txt
More information: http://www.think-techie.com/2010/04/alternate-data-streams.html
http://www.irongeek.com/i.php?page=security/altds
This is a tough nut to crack! An application must read information about the ACCDB, but that information can't be stored in the ACCDB because you want the read without opening the ACCDB. And you can't use the suggested file system methods because this must work under Wine on Mac (I assume from another of your questions).
The only solution I can see is to create a companion file (with same base name but different extension) to hold the metadata. So if your application wants to know about SomeDb.accdb, it would look for a file named SomeDb.metadata and read that instead.
I suggested a kludge for your earlier question ... unfortunately this is another. :-) However, it's a simple kludge and it should work ... even on Mac.

SQL Server Agent Adding a Parameter for a CmdExec

I want to add a parameter to a step that runs an operating system (CmdExec) in SQL Server Agent. I have searched everywhere and asked my coworkers and none of them had tried it before. I have attached a picture of the screen. I was thinking that I might be able to add the parameter (file path) after the .exe statement, but wasn't sure.
I thought the following might work:
Executable Path Parameter Path
C:\MyProgram\MyApp.exe E:\AppInfo\Client\Config.txt
This is on a production server and I didn't want to break anything if this isn't correct.
Thanks!
Yes You can use parameters, so your command would be:
C:\MyProgram\MyApp.exe E:\AppInfo\Client\Config.txt
If there is a space in the name don't forget to use quotes as specified in tip in screenshot:
"C:\My Program\MyApp.exe" "E:\App Info\Client\Config.txt"
Since You want to try it on production server, consider testing your configuration and software on test environment first. If You doubt that this will work, You can set job to execute only this single step to make sure it will work as expected.

MS Access - Open database form from URL

I'm trying to open a form from an url. This ms access database will be hosted on a shared folder in an network, and the costumer has asked me if it's possible to open an database form (i'll have to pass an ID).
If this were in web environment i would do this without any problem, but honestly in ms access i have no idea how to do this.
Can someone help me?
Have a look at Register protocol and Registering an Application to a URL Protocol. They have a example registry file on how to register a protocol:
REGEDIT4
[HKEY_CLASSES_ROOT\foo]
#="URL:foo Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\foo\shell]
[HKEY_CLASSES_ROOT\foo\shell\open]
[HKEY_CLASSES_ROOT\foo\shell\open\command]
#="\"C:\\Program Files\\Application\\program.exe\" \"%1\""
You can change the last line to something like:
#="\"C:\\Program Files\\Office\\access.exe\" \"C:\\path\\to\\your\\db.mdb\" /cmd \"%1\""
If you URL is foo:241245, the following command is called:
"C:\Program Files\Office\access.exe" "C:\path\to\your\db.mdb" /cmd "241245"
In Access, the commandline arguments are returned by the Command function:
In the direct window:
?Command
241245
The database can be opened from a URL like any other file:
file://server/share/path/database.mdb
This won't work if the database has user-level security on it though. I've only ever done that by using a windows shortcut.
If you're not using user-level security and the URL works, you can set the desired form to open automatically on load by going to the Access Options screen and the Current Database tab, then selecting the desired form from the Display Form drop-down list.
Oops - I just noticed that you said you'd need to pass an ID. I don't know if that's possible using a URL.
Open your Access database from the network location (i.e., with a UNC path, not from a drive letter, or locally).
Navigate so you can see the form listed in your database.
Drag the form to your desktop. A shortcut directly to the form will be created there.
I don't think this is a good idea, though. It's a substitute for a user interface in your Access application. Additionally, your description of the problem sounds like you're intending to have multiple people opening the same database file. This is a really bad practice -- best practice is for the database to be split (back end with data tables only on the server, and individual copy of the front end with forms/reports/etc. on each user's workstation), and more than one user should never be opening the same front end at the same time.