Qt ODBC SQL_SERVER - c++

I would like to use the SQL_ATTR_TRACE=SQL_OPT_TRACE_ON option of QSqlDatbase object.
QSqlDatabase db_;
db_.setConnectOptions("SQL_ATTR_TRACE=SQL_OPT_TRACE_ON");
I'm wondering where the resulting trace file is located ?
Is there a way to define the path ?
Thanks

it exists a SQL_ATTR_TRACEFILE attribute
db_.setConnectOptions("SQL_ATTR_TRACEFILE =c:\\odbc.log");

Related

How to Remove the Readonly attribute of a File MFC

In my MFC application I have set the read only attribute on a particular file.
I have done this by using the SetFileAttributes() function.
At some point I have to remove that attribute of that file again.
Can anyone explain how to do this?
Use SetFileAttributes again to reset the flag:
SetFileAttributes( pszFilename,
GetFileAttributes(pszFilename) & ~FILE_ATTRIBUTE_READONLY);
Might be worth adding that this method returns 0 if the function fails and you can use GetLastError().

Qt QSettings try to create ini file but none created why?

Im trying to create ini file that will hold me the configuration data, I have singletone class
that setting the QSettings object like this :
... #DEFINE CONFIG_FILE_NAME "myconfig.ini"
m_pSettings = new QSettings(QDir::currentPath()+"/"+CONFIG_FILE_NAME,QSettings::IniFormat);
this is accourding the document, but when i look in my application dir, there is none myconfig.ini file created, what im doing wrong ?
I believe in order to force QSettings file to appear you would need to set at least one value in it and then call sync() method. See if an example below would work for you:
QSettings* settings = new QSettings(QDir::currentPath() + "/my_config_file.ini", QSettings::IniFormat);
settings->setValue("test", "value");
settings->sync();
hope this helps, regards
I dont think that "/"+CONFIG_FILE_NAME return the expected result. May be the cause of your problem..
Anyway operator +() is present in QString class so QDir::currentPath() + "/my_config_file.ini" must work fine.

Qt C++ remove a read only file in windows using

I have set a file to be read-only (right click and check readonly). Now when I try to remove the file using the function bool QDir::remove(const QString & fileName) the file is not removed and false is returned.
How do I proceed with this? I have tried fiddling around by changing the permission of the file using QFile::setPermission, but that returns false too.
Can anybody advise an approach for the same?
file.setPermissions(QFile::ReadOther | QFile::WriteOther);
file.remove();
should work.
You can set file permissions with QFile
Of course this only for files you have user permission to do. The error may also be because the file is open in another app
First, have you checked QFile::error() to see why the file wasn't removed?
Second, in the event that you're still not getting a useful error message back, you could check the source to find out if you can get more information. Checking the source reveals the following, for example:
QFile::remove() uses the underlying file engine to do the removal. That file engine is platform specific and in qfsfileengine_win.cpp for windows. Line 830 shows that it's using DeleteFile to do the removal so you might be able to get more information by calling GetLastError, though I'd hope that Qt translates the error message appropriately.
QDir::remove() function is not a static function. so you can create QDir with parent file path and call then remove it:
QDir dir(parent's directory);
and then
dir.remove(fileName);
I think you should use this:
bool QFile::remove ( const QString & fileName ) [static]
instead of this:
QDir::remove ( const QString & fileName )
Have you tried to use bool QFile::remove(const QString &fileName)?

Qt4.4 how to get the user settings path

linux: $HOME/.config
windows: %APPDATA%
mac os: $HOME/.config
It can be set using http://qt-project.org/doc/qt-4.8/qsettings.html#setPath, but it seems as I am not able to retrieve it.
http://qt-project.org/doc/qt-4.8/qlibraryinfo.html#location QLibraryInfo::LibrariesPath returns the system wide settings dir, which is not what I want.
Any ideas, or do I have to code it separately for each platform?
€: I want to create a sub directory, and store files into it. (You may punish me if this is a bad idea)
This might not answer your question directly: if you want to store per-user persistent data, shouldn't you use QDesktopServices::storageLocation(QDesktopServices::DataLocation) instead?
This is a nasty workaround. First you create QSettings, then get its location.
QSettings cfg(QSettings::IniFormat, QSettings::UserScope,
"organization", "application");
QString config_dir = QFileInfo(cfg.fileName()).absolutePath() + "/";
Credits go to the Qt Centre forum.
QSettings stores the default config in the user AppData directory. See documentation for QSettings. Also this code instructs to store the config in the Ini file format.
this works on both qt 4 and qt 5
QApplication::setApplicationName("MyApp");
QApplication::setOrganizationName("Me");
QString homePath;
#if QT_VERSION >= 0x050000
homePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else
homePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#endif
Why do you need to know the settings path? If you are going to put settings in it, you could use QSettings. I could see making a subdirectory to hold various settings, but it seems like the easiest way would be to use QSettings directly.
As far as I can tell, you can't retrieve the path. In the Qt source, src/corelib/io/qsettings.cpp, there is a function to get the path:
static QString getPath(QSettings::Format format, QSettings::Scope scope)
{
...
but it's not accessible from code using Qt. You can't copy it and use it either, because it uses internal Qt globals to store the path...
EDIT: A solution was posted, using QDesktopServices.storageLocation(QDesktopServices.DataLocation) but it doesn't do exactly what the question was asking for, i.e. if I set a custom path using QSettings.setPath() it doesn't reflect the change.
What platform are you at?
Might be related or not but in windows, the default is to write QSettings to the registry.
I read more into the question than there was as it was originally posted. It is clearer after the edits. Ok, so can't you use..
QString QSettings::fileName () const
Returns the path where settings are written to using this QSettings object are stored.
On Windows, if the format is QSettings::NativeFormat, the return value is a system registry path, not a file path.

Monitor SQL currently in shared pool using Toad

Anyone have any idea? And any open source sofware which also seens to perform this kind of functionality?
Toad does it. It is under Tools|SGA Trace/optimization.
Here is your open source solution :-)
select distinct
vs.sql_text, vs.sharable_mem, vs.persistent_mem, vs.runtime_mem, vs.sorts, vs.executions,
vs.parse_calls, vs.module, vs.action, vs.buffer_gets, vs.disk_reads, vs.version_count,
vs.loaded_versions, vs.open_versions, vs.users_opening, vs.loads, vs.users_executing,
vs.invalidations, vs.serializable_aborts, vs.command_type,
to_char(to_date(vs.first_load_time,'YYYY-MM-DD/HH24:MI:SS'),'MM/DD HH24:MI:SS') first_load_time,
rawtohex(vs.address) address, vs.hash_value hash_value, vs.parsing_user_id
,rows_processed
,optimizer_mode
,vs.is_obsolete, vs.elapsed_time, vs.cpu_time
,vs.Child_latch, vs.fetches
,vs.program_id,vs.java_exec_time,vs.plsql_exec_time,vs.user_io_wait_time,
vs.cluster_wait_time, vs.concurrency_wait_time, vs.application_wait_time,
vs.direct_writes, vs.end_of_fetch_count
from v$sqlarea vs