I am in the beginning phase of both sqlite, as well as QT.
There are various examples under QtSDK IDE for sqlite database. This is an excerpt from one of the examples :
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
This works just fine. but if I try to replace ":memory:" with an actual sqlite3 database file,...
void MainWindow::on_pushButton_5_clicked()
{
QSqlQuery query;
accounts_db = new QSqlDatabase();
*accounts_db = QSqlDatabase::addDatabase("QSQLITE"); perror("");
accounts_db->setDatabaseName("/home/aditya/test.db.sqlite");
QSqlError *a = new QSqlError();
*a = accounts_db->lastError();
perror(a->text().toLatin1());
if (!accounts_db->open()) {
perror("database open error :");
QMessageBox::critical(0,qApp->tr("db.open\n"),a->text(),QMessageBox::Cancel);
goto end; // quit if not successful
}
if ( !accounts_db->isOpen() ) {
perror("database is not open");
}
query.exec("select accno,branchcode,fname,lname,curbalance,accdate from accounts");
while(query.next()) {
QString str = query.value(0).toString();
std::cerr << qPrintable(str) << std::endl;
}
end:
;
}
...then I am not so lucky. Not sure exactly how lastError() works, but tried it anyway. I am getting these errors...
No such file or directory
: Invalid argument
QSqlQuery::exec: database not open
I have tried changing the permissions n'all on the concerned files and folders as suggested on different forums, but to no results. Just a note, I am working on Ubuntu Linux (...if that matters), I have also tested this test.db database file with the sqlite3 command line program, that works flawless.
Any guidance is appreciated...thanks.
EDIT:
Very sorry that I completely forgot to explain what the error is... :|
Created a brand new database, and it works !!!
not clear why it was not working before though... I definitely need to study more.
Anyway, thanks a lot ppl :) .
Related
i have an error with redis set command on local redis server(127.0.0.1:6379)
versions:
npm version : 2.15.0;
node version : 4.4.2;
nodejs verison : 0.10.25;
redis version : 2.7.1;
Error:
events.js:141 throw er; // Unhandled 'error' event
ReplyError: ERR wrong number of arguments for 'set' command at parseError
(/opt/xxx/xxx/node_modules/redis/node_modules/redis
parser/lib/parser.js:193:12) at parseType
(/opt/xxx/xxx/node_modules/redis/node_modules/redis-
parser/lib/parser.js:303:14)
all of my codes look like this:
redis.set("key","value")
on my local machine the code is running successfully , but on aws linux machine i got this error.
var matchedMaps = map.get(publicURIField);
if(matchedMaps) {
matchedMaps.forEach(function(matchedMap){
var patternToValidate = matchedMap.pattern;
var type = matchedMap.type;
var tagID = matchedMap.tagID;
var patternToCheck = "cs-uri-stem";
var patternToSave = "";
if(type==1){
patternToCheck = "c-referrer";
}
var regexToFind = new RegExp(patternToValidate.substring(1,patternToValidate.length-1));
var matchedPattern;
if (regexToFind.test(rawLogParsed[patternToCheck].toString())) {
if (matchedMap.regexType=="&"){
matchedMap.patterns.forEach(function(patternObject){
var key = patternObject.pattern.split("=")[0];
var value = rawLogParsed[patternToCheck].toString().split(key)[1];
if(rawLogParsed[patternToCheck].toString().split(key)[1].split("&")){
value = rawLogParsed[patternToCheck].toString().split(key)[1].split("&")[0];
}
patternToSave += key+value+"&";
});
}else{
matchedMap.patterns.forEach(function(patternObject){
if(patternObject.pattern.indexOf("*")>-1){
patternObject.pattern = patternObject.pattern.replace(/\*!/g, '.*');
}
patternToSave += rawLogParsed[patternToCheck].toString().match(patternObject.pattern)+"/";
});
}
patternToSave = patternToSave.substring(0,patternToSave.length-1);
var matchedField = publicURIField,matchedPattern = patternToSave
,key = tagID + "_"+userID+"_"+ matchedField + "_" + matchedPattern + "_" + type + "_" + fixedMinuteNumber;
if (tagUsageInfo[startKeyForRedis+key] == undefined) {
var tagObject = {
pattern:matchedPattern,
matchedField:matchedField,
userID:userID,
tagName:matchedMap.tagName,
monthNumber:parseInt(mMonthToCheck),
minuteNumber: parseInt(fixedMinuteNumber),
hourNumber: parseInt(yearMonthDayHourToCheck),
dayNumber: parseInt(yearMonthDayToCheck),
tagID: tagID,
matchedPattern: matchedPattern,
totalRequests: 1,
totalEgress: parseInt(bytes),
totalTransfered: parseInt(bytes),
totalRest: parseInt(totalWorld),
totalUS: parseInt(totalUS)
}
if(isIngress){
tagObject.totalIngres += parseInt(bytes);
}
dbclient1.set(startKeyForRedis+"tagUsage_"+key,JSON.stringify(tagObject));
tagUsageInfo[startKeyForRedis+"tagUsage_"+key] = startKeyForRedis+key;
}
else {
dbclient1.get(startKeyForRedis+"tagUsage_"+key, function(err, tagObject) {
var tagObjectJson = JSON.parse(tagObject);
tagObjectJson.totalRequests += 1;
tagObjectJson.totalEgress += parseInt(bytes);
tagObjectJson.totalTransfered += parseInt(bytes);
tagObjectJson.totalRest += parseInt(totalWorld);
tagObjectJson.totalUS += parseInt(totalUS);
tagObjectJson.totalRequests += 1;
if(isIngress){
tagObject.totalIngres += parseInt(bytes);
}
dbclient1.del(startKeyForRedis+"tagUsage_"+key);
dbclient1.set(startKeyForRedis+"tagUsage_"+key, JSON.stringify(tagObjectJson));
});
}
}
});
}
any help?
1)If your trying to run redis on windows set accepts only two arguments cause the redis version issue
2)try latest version of redis on linux it will work
Try installing this version of Redis on windows from the following link. You can find more information here https://github.com/ServiceStack/redis-windows
This link provides three options to install Redis on windows
Option 1) Install Redis on Ubuntu on Windows
Option 2) Running the latest version of Redis with Vagrant
Option 3) Running Microsoft's native port of Redis
I personally prefer option 3.
Hope this helped. Thanks.
all of my codes look like this: [...]
It's not important how all of your code looks like. It's important how the specific line that caused the problem looks like but unfortunately you didn't include it.
The errors that you provided include some files and line numbers but you seem to have removed the ones that are related to your code. If you read those messages carefully then you should be able to know what lines those errors are related to and focus on those lines.
If the errors show up on a server and not on your desktop then I would suspect that maybe you're trying to use some environment variables or files on the file system to populate some variables in your program, and those are not available on the server resulting in putting undefined there.
You will surely find the problem when you add console.log() statements to every place where you want to access Redis so that you first print it and then call to Redis. That way at least you will know what data is causing the problem. I suspect that you are having some undefined values or something like that.
Remember that JSON.stringify(undefined) returns undefined instead of a valid JSON string. Something like that may be causing problems. Adding debug messages will help to narrow it down.
Some extra advice: You can use prefix parameter of the redis module then you will not have to add startKeyForRedis+ all over the place. You can set a prefix once and have it prepended automatically. See the docs:
https://www.npmjs.com/package/redis
I was doing learning to use KUE a nodejs library for job scheduling that uses redis for saving data.
I got this error while running client.js(that puts jobs in queue) and worker.js(that process the schedule jobs).
I was running worker before running the client and that is why this happened.
I reversed the order and everything went fine!
To fix this error on windows Redis from v.3 required.
That's why I've took zipped release 3.0.504 from here and now all is working.
Quite simple.
I have faced similar type of error which was because of older version of Redis. This is compatibility issue which fixes a bug in Redis after Redis 2.6.12. Make sure you install recent version of Redis v3.X.
My co-workers and I are working on a Coded UI project. We both have the same version of the project thanks to TFS, but on his computer all the test cases run, and on mine they don't. They used to run perfectly fine on my machine until one morning they decided to not work. I always keep getting the same error that the UI Test Controls are not found, even though the mappings are correct. Let me remind you that they work perfectly fine on my co-workers machine. We also have the same version of IE (11).
What could be the cause for this?
Thanks for the help in advance.
My co-worker seemed to resolve the situation, but we still don't understand why the previous version of the code worked for everyone but my machine. The problem occurred in our LaunchBrowser method which would use 2 different instantiations of the browser variable. He got rid of the unnecessary one and the playback commands and seemed to have fixed the problem.
Below are two versions of the code, the previous one and the newly written one:
Old:
public static void LaunchBrowser(string url)
{
GlobalVariable.browser = new BrowserWindow();
CloseAllBrowsers();
BrowserWindow.CurrentBrowser = GlobalVariable.BrowserType;
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.Disabled;
GlobalVariable.browser = BrowserWindow.Launch();
System.Uri URI = new System.Uri(url);
GlobalVariable.browser.NavigateToUrl(URI);
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.UIThreadOnly;
GlobalVariable.browser.Maximized = true;
if (BrowserWindow.CurrentBrowser == "Firefox")
{
Mouse.Click(_fireFoxAuthOK);
}
Logging.WriteLog("Browser was navigated to " + url + " in browser: <" + GlobalVariable.BrowserType + ">");
}
New:
public static void LaunchBrowser(string url)
{
CloseAllBrowsers();
BrowserWindow.CurrentBrowser = GlobalVariable.BrowserType;
GlobalVariable.browser = BrowserWindow.Launch(new Uri(url));
GlobalVariable.browser.Maximized = true;
if (BrowserWindow.CurrentBrowser == "Firefox")
{
Mouse.Click(_fireFoxAuthOK);
}
Logging.WriteLog("Browser was navigated to " + url + " in browser: <" + GlobalVariable.BrowserType + ">");
}
I think the problem is in this line :
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.UIThreadOnly;
Because the browser's foreground thread is not ready to start the playback. you may try this
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;
or different alternative ways in your pc.
Refer this link Mathew Aniyan's Blog for further information.
I'm trying to get a way to reach and parse all JSON file from a directory, witch inside an Intel Xdk project. All files in my case stored in '/cards' folder of the project.
I have tried to reach theme with fs.readdirSync('/cards') method, but that wasn't pointed to the location what I expected, and I haven't got luck with 'intel.xdk.webRoot' path.
With the simulator I've managed to get files, with a trick:
fs.readdirSync(intel.xdk.webRoot.replace('localhost:53862/http-services/emulator-webserver/ripple/userapp/', '')+'cards');
(intel.xdk.webRoot contains absolute path to my '/cards' folder)
and its work like a charm, but it isn't working in any real device what I'd like to build it.
I have tried it with iOS7 and Android 4.2 phones.
Please help me to use in a great way the fs.readdirSync() method, or give me some alternate solution.
Thanks and regards,
satire
You can't use nodejs api's on mobile apps. It is a bug that the XDK emulator lets you do it. The bug is fixed in the next release of XDK.
You could write a node program that scans the directory and then writes out a js file with the contents of the directory. You would run the node script on your laptop before packaging the app in the build tab. The output would look like this:
files.js:
dir = {files: ['file1.txt', 'file2.txt']}
Then use a script tag to load it:
And your js can read the dir variable. This assumes that the contents does not change while the app is running.
The location of your application's root directory will vary depending on the target platform and can also vary with the emulator and the debug containers (e.g., App Preview versus App Analyzer). Here's what I've done to locate files within the project:
// getWebPath() returns the location of index.html
// getWebRoot() returns URI pointing to index.html
function getWebPath() {
"use strict" ;
var path = window.location.pathname ;
path = path.substring( 0, path.lastIndexOf('/') ) ;
return 'file://' + path ;
}
function getWebRoot() {
"use strict" ;
var path = window.location.href ;
path = path.substring( 0, path.lastIndexOf('/') ) ;
return path ;
}
I have not been able to test this exhaustively, but it appears to be working so far. Here's an example where I'm using a Cordova media object and want it to play a file stored locally in the project. Note that I have to "special case" the iOS container:
var x = window.device && window.device.platform ;
console.log("platform = ", x) ;
if(x.match(/(ios)|(iphone)|(ipod)|(ipad)/ig)) {
var media = new Media("audio/bark.wav", mediaSuccess, mediaError, mediaStatus) ;
}
else {
var media = new Media(getWebRoot() + "/audio/bark.wav", mediaSuccess, mediaError, mediaStatus) ;
}
console.log("media.src = ", media.src) ;
media.play() ;
Not quite sure if this is what you are looking for...
You will need to use the Cordova build in the Intel XDK, here is information on building with Cordova:
https://software.intel.com/en-us/html5/articles/using-the-cordova-for-android-ios-etc-build-option
And a DirectoryReader example:
function success(entries) {
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
}
}
function fail(error) {
alert("Failed to list directory contents: " + error.code);
}
// Get a directory reader
var directoryReader = dirEntry.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(success,fail);
I am trying to use the Fl_Native_File_Chooser from fltk 1.3 and the class works fine except for setting the start directory.
const char *start_dir = "C:\\Program Files (x86)";
Fl_Native_File_Chooser native(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
native.directory( start_dir );
native.title( "Select a directory");
native.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
std::string directoryName;
switch ( native.show() )
{
case -1: break; //fprintf(stderr, "ERROR: %s\n", native.errmsg()); break; // ERROR
case 1: break; //fprintf(stderr, "*** CANCEL\n"); fl_beep(); break; // CANCEL
default: // PICKED FILE
if ( native.filename() ) directoryName = native.filename();
break;
}
std::cout << directoryName << std::endl;
I've looked into the code.
In Fl_Native_File_Chooser_WIN32.cxx and int Fl_Native_File_Chooser::showdir()
I don't understand why the _binf.pidlRoot is not set.
I have looked at Fl_Native_File_Chooser::showfile() but the way the dialoge is setup is different.
So has anyone successfully set the startup directory for the Fl_Native_File_Chooser when you are browsing for a directory?
The strange thing to me is that the normal Fl_File_Chooser works.
Your code works for me, although I'm not sure what you mean by "_binf.pidlRoot".
What do you expect the code to do, and what does it actually do? Is there any code before or after the part that you posted? This could affect things...
I have a (from what I can tell) perfectly working Linux setup (Ubuntu 8.04) where all tools (nslookup, curl, wget, firefox, etc) are able to resolve addresses. Yet, the following code fails:
$s = new IO::Socket::INET(
PeerAddr => 'stackoverflow.com',
PeerPort => 80,
Proto => 'tcp',
);
die "Error: $!\n" unless $s;
I verified the following things:
Perl is able to resolve addresses with gethostbyname (ie the code below works):
my $ret = gethostbyname('stackoverflow.com');
print inet_ntoa($ret);
The original source code works under Windows
This is how it supposed to work (ie. it should resolve hostnames), since LWP tries to use this behavior (in fact I stumbled uppon the problem by trying to debug why LWP wasn't working for me)
Running the script doesn't emit DNS requests (so it doesn't even try to resolve the name). Verified with Wireshark
From a quick look, the following code from IO::Socket::INET
sub _get_addr {
my($sock,$addr_str, $multi) = #_;
my #addr;
if ($multi && $addr_str !~ /^\d+(?:\.\d+){3}$/) {
(undef, undef, undef, undef, #addr) = gethostbyname($addr_str);
} else {
my $h = inet_aton($addr_str);
push(#addr, $h) if defined $h;
}
#addr;
}
suggests (if you look at the caller of this code) the work-around of adding MultiHomed => 1, to your code.
Without that work-around, the above code appears to try to call inet_aton("hostname.com") using the inet_aton() from Socket.pm. That works for me in both Win32 and Unix, so I guess that is where the breakage lies for you.
See Socket.xs for the source code of inet_aton:
void
inet_aton(host)
char * host
CODE:
{
struct in_addr ip_address;
struct hostent * phe;
if (phe = gethostbyname(host)) {
Copy( phe->h_addr, &ip_address, phe->h_length, char );
} else {
ip_address.s_addr = inet_addr(host);
}
ST(0) = sv_newmortal();
if(ip_address.s_addr != INADDR_NONE) {
sv_setpvn( ST(0), (char *)&ip_address, sizeof ip_address );
}
}
It appears that the Perl gethostbyname() works better than the C gethostbyname() for you.
Could you perhaps tells us exactly how your code fails? You've got error checking code in there but you haven't reported what the error is!
I've just tried the original code (with the addition of the "use IO::Socket::INET" on my Mac OS X machine and it works fine.
I suspect that the Multihomed option is an unnecessary hack and some other issue is the root cause of your problem.
Make sure that you have the statement
use IO::Socket::INET;
At the beginning of your source code. If you leave this out, you are probably getting the error message:
Can't locate object method "new" via
package "IO::Socket::INET"
Beyond that you might verify that DNS is working using Net::DNS::Resoler, see more information here.
use Net::DNS;
my $res = Net::DNS::Resolver->new;
# Perform a lookup, using the searchlist if appropriate.
my $answer = $res->search('example.com');