Archive

Archive for September, 2009

Unresolved Eclipse Problem. Impossible: Unrelated (referring enablement-status) ContributionsItems for one command in multiple views

September 3rd, 2009 Comments off

The Problem:
Two views in the workbench window. Both contain a toolbar with a CommmandContributionItem. Both CommandContributionItems belong to the same command. Each one should set its enablement-status independently according to its view context. BUT: You cannot have one CommmandContributionItem enabled and the other not at the same time.

That Problem is described in http://www.eclipsezone.com/eclipse/forums/t112307.html

Excerpt from that article:
As I see it, the problem is not directly related to the handlers, but to
the commands themselves, which (being typically defined in the plug-in’s
plugin.xml file) are instantiated by the platform only once. Thus, if
two command contribution items in two workbench windows are associated
with the same command ID, they are also referencing the same command
object. Since this command can, in turn, only be associated with (at
most) one handler at any one time, and this handler is responsible for
determining the commands enabled status, it is (as Mark says) impossible
to enable the command contribution item in one workbench window, whilst
keeping the command contribution using the same command ID in the other
workbench window disabled (or vice versa).

You can reproduce that wrong behaviour with Eclipse 3.4 or Eclipse 3.5 as follows (excerpt from the mentioned article):

  1. Start Eclipse IDE, specifying a workspace containing at least one file editable via the Text Editor.
  2. Close any editors. The “Print” toolbar item should now be disabled.
  3. Open a new workbench window via “Window > New Window”
  4. Open the Text Editor on a workspace file.
  5. Note that the “Print” toolbar item is now not only (correctly) enabled for the new workspace window, but is also (incorrectly) enabled for the original workspace window, even though there is nothing to print there.
Categories: Development, Java Tags: ,

Auto increment with Prepared Statements in PHP & MySQL

September 2nd, 2009 Comments off

In MySQL you can define, that a column contains an auto increment value. This means that, whenever there is an insert command, the ID (this is what the auto increment value is usually used for) will be increment by a pre-defined value.

Now, when you use ad hoc queries (simple string concatenating like “Insert into user values (‘ ” . $username . ” ‘ , ‘ ” . $first_name . ” ‘) “” ); you can invoke the function mysql_insert_id to get the increment value of this insert operation.

But when you use Prepared Statements (Man Page) instead, you have to use the mysqli_insert_id function instead! When using this function, you also have to pass the connection object to the function.

If you try to use the mysql_insert_id function, you will receive an error message saying:
mysql_insert_id() function.mysql-insert-id: A link to the server could not be established in dbOps.php.

Also passing the connection object to function mysql_insert_id() will not help. The error will say then some like mysql_insert_id(): supplied argument is not a valid MySQL-Link resource in dbOps.php.