SQL Syntax Error (with MySQL)

Say you are writing a new stored procedure (for MySQL) and when you execute it, you get an error something like shown below - as you probably figured out all it means is that there is a syntax error with in the SQL. Often the error is misleading especially if it is a complicated query. One easy way to help narrow down the issue is to run it in a SQL Console which usually provides a better clue that can be your pointer to fixing the issue. ...

December 24, 2010 · Amit Bahree

Impressed with Doxygen

I have recently started using Doxygen in anger and have been quite impressed with it. In addition to the documentation of code that you would expect, one of the most powerful and coolest features is the ability to create various types of diagrams showing various aspects of the application such as collaboration diagrams object and call graphs, etc. The easiest way to configure your application is to use Doxywizard . On Linux, if you do want the object and call graphs then you would need to choose to enable the DOT option. If you do that you will need to have Message Sequence Charts installed (typically found in /usr/bin/mscgen) and also Graphviz. DOT can typically be found in /usr/bin/dot. ...

October 30, 2010 · Amit Bahree

MySQL++

I had a need to dump some data I am getting from a real-time sensor network to a database and I choose MySQL - just because it is cheap and cheerful and will fit perfectly with what I am looking for. Now, I have never programmed for MySQL though I have used it in the past as a consumer (e.g. the backend of this blog). MySQL does expose a C API that one can use, but it seems quite arcane to use and does not quite conform to the C++ style (especially when using STL). ...

October 23, 2010 · Amit Bahree

invalid use of incomplete type ‘blah'

When you try and compile some code and you get an error along the lines of invalid use of an incomplete type ‘whatever type’ then in most cases it means you need to include the header file where that type is displayed. For example I had the following events in my header file: 1 2 3 protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); When when I tried to compile gave the following error: invalid use of incomplete type ‘struct QGraphicsSceneMouseEvent’ ...

April 18, 2010 · Amit Bahree

Finding an element in a list

Often you need to search through an array or list to find a specific element and of course you need this search to be as fast and efficient as possible. One of the best ways to do this is using a binary predicate function. A binary function is a function object (which are also called Functors ) and is any object which can be called as if it was a function. Depending on your language and platform of choice, Function objects are also known as callback functions , function pointers and delegates (.NET). Generally, there are three types of function objects: ...

April 5, 2010 · Amit Bahree

Printing code and making it look pretty

If you are on Linux and want to print some code and also make it look pretty then check out a2ps (Any to postscript filter). Of course if you can avoid printing in the first place and saving paper and trees and make it greener that is ideal - however there are times that is not possible. I tried printing from CDT, but the printing options from CDT just looks plain ugly and big fonts and can spread over 10 pages for a simple code file (spanning 293 lines). Sure I can tweak the font in CDT, but that is the only option available - enter a2ps . It seems to have more options, but I have not had a chance to play with those. ...

March 1, 2010 · Amit Bahree

Ten commandments of Programming

I came across the Ten commandments of Programming while looking at a question on StackOverflow and I can’t believe I have not seen these before. I think every developer, lead, architect, dba, pm, whoever should print this out! 8-) Understand and accept that you will make mistakes. The point is to find them early, before they make it into production. Fortunately, except for the few of us developing rocket guidance software at JPL, mistakes are rarely fatal in our industry, so we can, and should, learn, laugh, and move on. You are not your code. Remember that the entire point of a review is to find problems, and problems will be found. Don’t take it personally when one is uncovered. No matter how much “karate” you know, someone else will always know more. Such an individual can teach you some new moves if you ask. Seek and accept input from others, especially when you think it’s not needed. Don’t rewrite code without consultation. There’s a fine line between “fixing code” and “rewriting code.” Know the difference, and pursue stylistic changes within the framework of a code review, not as a lone enforcer. Treat people who know less than you with respect, deference, and patience. Nontechnical people who deal with developers on a regular basis almost universally hold the opinion that we are prima donnas at best and crybabies at worst. Don’t reinforce this stereotype with anger and impatience. The only constant in the world is change. Be open to it and accept it with a smile. Look at each change to your requirements, platform, or tool as a new challenge, not as some serious inconvenience to be fought. The only true authority stems from knowledge, not from position. Knowledge engenders authority, and authority engenders respect—so if you want respect in an egoless environment, cultivate knowledge. Fight for what you believe, but gracefully accept defeat. Understand that sometimes your ideas will be overruled. Even if you do turn out to be right, don’t take revenge or say, “I told you so” more than a few times at most, and don’t make your dearly departed idea a martyr or rallying cry. Don’t be “the guy in the room.” Don’t be the guy coding in the dark office emerging only to buy cola. The guy in the room is out of touch, out of sight, and out of control and has no place in an open, collaborative environment. Critique code instead of people—be kind to the coder, not to the code.As much as possible, make all of your comments positive and oriented to improving the code. Relate comments to local standards, program specs, increased performance, etc.

February 17, 2010 · Amit Bahree

Copying strings in C++

Here is a good example on why either you love C++ or hate it with such terse expression oriented code; I think its pretty cool. If you want to copy one string to another, one option can be something like this. 1 2 3 4 5 6 void mycopy(char *p, char *q) { int len = strlen(q); for(int i=0; i<=len; i++) p[i] = q[i]; } However this achieves the same thing as above and is more efficient: ...

January 23, 2010 · Amit Bahree

‘QPainter painter’ has initialiser but incomplete type

If you ever got an error something like [some-class] has initialiser but incomplete type, it basically means the compiler cannot understand the type and you need to add the include for it. 1 2 3 4 5 QPixmap pixmap(20,10); pixmap.fill(Qt::white); QPainter painter(&pixmap); QPen pen(Qt::blue); Take the code snipped above when you compile it you might get an error something along the lines of the following for line 4. ...

January 10, 2010 · Amit Bahree

Making sense of primary-expression error

If you are new to C++ then some of the compiler errors can be a bit confusing and daunting at first. For example if the compiler given you an expected primary-expression error (e.g. expected primary-expression before ‘.’ token), at face value it does not make sense. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void RGBViewer::accept() { QMessageBox::information(this, "Button Clicked", "You clicked OK", QMessageBox::Ok); QColor color = QColor(Ui_RGBViewerClass.spinBoxRed->value(), Ui_RGBViewerClass.spinBoxGreen->value(), Ui_RGBViewerClass.spinBoxBlue->value(), 255); qDebug() << color; QBrush brush(color); brush.setStyle(Qt::SolidPattern); ui.graphicsView->setBackgroundBrush(brush); ui.graphicsView->backgroundBrush(); } When I compile the above code snippet, I get the following error from the compiler: ...

December 22, 2009 · Amit Bahree

Sandbox is Up!

As promised earlier, the Sanbox is up - go give it a whirl and let me know your thoughts. Also the code and release build of the World Clock are up there. Check it out and let me know what you think of it and also any bugs and feature enhancements you would like to see. ...

March 21, 2005 · Amit Bahree