Sunday 1 September 2013

Why I got this MySql Error on update sql

Why I got this MySql Error on update sql

I have a table like.
CREATE TABLE `chart` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`item` char(6) NOT NULL DEFAULT '',
`IsLeaf` char(1) NULL DEFAULT 'Y',
`ParentId` int(10) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
)
Where parentId contains an id of another row , which is the parent of that
row Like
-----------------------------------------------------------------
| Id | item | IsLeaf | ParentId
-----------------------------------------------------------------
| 1 | Test1 | D |
-----------------------------------------------------------------
| 2 | Test3 | D |
-----------------------------------------------------------------
| 3 | Test4 | D | 1
-----------------------------------------------------------------
| 4 | Test5 | D | 1
-----------------------------------------------------------------
I want to update those rows which have at least one child row. I tried
like this
UPDATE chart AS c1 SET c1.IsLeaf='Y' JOIN chart c2 ON c2.ParentId=c1.id;
and got this error
[Err] 1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'JOIN chart c2 ON c2.ParentId=c1.id' at line 1

How to save contents of Array in CoreData in iOS 6

How to save contents of Array in CoreData in iOS 6

I am fetching the contents of AddressBook which in turn are copied into an
array.Now i want to save this array into CoreData.I know how to insert
single values in CoreData.How do i loop through an array to do the same?
Here is what i tried.
-(void)saveToDatabase
{
AddressBookAppDelegate *appDelegate =[[UIApplication
sharedApplication]delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription
insertNewObjectForEntityForName:@"AddressBook"
inManagedObjectContext:context];
[newContact setValue:@"GroupOne" forKey:@"groups"];
NSLog(@"%@",[newContact valueForKey:@"groups"]); //this works fine.
for (NSString *object in self.reterivedNamesMutableArray) // this array
holds the name of contacts which i want to insert into CoreData.
{
[newContact setValue:object forKey:@"firstName"];
NSLog(@"Saved the contents of Array");
}
[context save:nil];
NSLog(@"Saved firstName = %@",[newContact valueForKey:@"firstName"]);
// shows null
NSLog(@"Saved groups = %@",[newContact valueForKey:@"groups"]); //
works fine.
}

Saturday 31 August 2013

Unhandled Error: Cannot convert 'document.getElementById(punkte_liste_titel_user)' to object

Unhandled Error: Cannot convert
'document.getElementById(punkte_liste_titel_user)' to object

I have a html page (partly generated with PHP), and I have a JavaScript
file included at the bottom of the page that provides some onclick
functions. I was struggling to get the variables from PHP to JS, so I
created two <span>s with unique ids and put the content of the variables
there (numeric/int values). My idea was to use var php_get_userid =
document.getElementById(punkte_liste_titel_user).innerHTML; to have JS
read the values into variables, and then use them. However the
getElementById doesn't work although the <span> with the corresponding ID
definitly does exist. In Opera it says
Unhandled Error: Cannot convert
'document.getElementById(punkte_liste_titel_user)' to object
Chrome says
Uncaught TypeError: Cannot read property 'innerHTML' of null
The HTML of the area looks like this
<body>
<div id="wrapper">
<div id="punkte_liste_titel">
Points <span id="punkte_liste_titel_datum">20130901</span>/<span
id="punkte_liste_titel_user">3</span>
</div> <!-- Ende Punkteliste -->
<div id="punkte_liste">
...
the JS starts like this
$('.punkte_kategorie_element').click(function() {
var php_get_userid =
document.getElementById(punkte_liste_titel_user).innerHTML;
var php_get_datum =
document.getElementById(punkte_liste_titel_datum).innerHTML;
...
the JavaScript file is included right before the </body> tag
I tried to create a minimal version of this at
http://jsfiddle.net/WRfh5/2/ which doesn't run either... what am I
missing?

inserting data in mysql previously defined variables

inserting data in mysql previously defined variables

I am using this code to get data from Json and insert them to mysql.
However it inserts no records in the data base.
<?php
include("db.php");
$currsiteurl = 'http://graph.facebook.com/1597233119';
$graph = json_decode(file_get_contents($currsiteurl));
$id = $graph->id;
echo "id : ".$id;
echo "<br>";
$username = $graph->username;
echo "username : ".$username;
echo "<br>";
$gender = $graph->gender;
echo "gender : ".$gender;
echo "<br>";
$locale = $graph->locale;
echo "locale : ".$locale;
mysql_query("INSERT INTO users_data (id, username, gender, locale)
VALUES ('.$id', '.$username', '.$gender', '.$locale')");
?>
Can any one show me whereis the mistake ?

File size limit for boost memory mapped files?

File size limit for boost memory mapped files?

I am using the below code to open files which are approximately 400 to
800MB in size:
#include <boost\interprocess\file_mapping.hpp>
#include <boost\interprocess\mapped_region.hpp>
#include <iostream>
#include <vector>
#include <string>
using namespace boost::interprocess;
using namespace std;
int main(){
file_mapping fm("C:\\test\\1.txt",read_only);
mapped_region region(fm,read_only);
const char* const data = static_cast<const char*>(region.get_address());
const size_t max_size = region.get_size();
cout << max_size;
int b;
cin >> b;
}
If I point the above code to a small file I get no exception. However,
when looking at the several-hundred-MB-files (on an external USB) I get an
exception:
Unhandled exception at at 0x7521C41F in ReadingFiles.exe: Microsoft C++
exception: boost::interprocess::interprocess_exception at memory location
0x0040FBD4.
I have 2.4GB of RAM free- so it shouldnt be that I have run out of memory?

What's the best way to exclude routes from a sitemap using Flask?

What's the best way to exclude routes from a sitemap using Flask?

Getting a list of all routes to use in building sitemaps is simple, e.g.,
rules = current_app.url_map.iter_rules(). But a number of routes are
intended for administrative functions and these should be excluded from
sitemaps (both XML and human-readable). All such administrative routes
have a decorator @auth_role(...) (shown below, and which is very similar
to the @login_required decorator described in
http://flask.pocoo.org/docs/patterns/viewdecorators/). URLs do not have a
special segment that sets them apart from other non-administrative URLs.
So I'd like to be able to filter routes to exclude those pointing to view
functions that also have the @auth_role(...) decorator. Does it make sense
to do it this way? If so, how can this be done? If not should I revise all
administrative routes to include some segment that sets them apart from
routes for public consumption?
def auth_role(roles):
def _auth_role_required(f):
@wraps(f)
def _inner(*args, **kwargs):
try:
if g.user is None:
flash (u'You must login to access the requested
resource.', CSS.ERR)
path = urlsplit(request.url).path
if path in ['', '/', '/admin', '/admin/login']:
return redirect('/admin/login')
else:
return redirect('/admin/login?d=%s' % path)
if not g.user.is_active():
flash (u'Your account is no longer active.', CSS.ERR)
return abort(403)
if not g.user.is_authorized(roles):
flash (u'Your current role does not grant access to
this resource.', CSS.ERR)
return abort(403)
except KeyError:
return abort(401)
return f(*args, **kwargs)
return _inner
return _auth_role_required

Java resize image from an URL?

Java resize image from an URL?

I want to resize the an image from an URL to 50x50 px.
This is how i load the image:
jLabel1.setIcon(new javax.swing.ImageIcon(new
URL("http://url.com/picture.jpg")));
How can i make picture.jpg 50x50px ?
Any ideas?