Thursday, September 6, 2012

Remote Desktop fullscreen

It seems that whenever I click the Window Restore icon on a fullscreen Remote Desktop instance, a subsequent Window Maximize does not bring me back to the fullscreen. Instead I'm back in crappy maximized-with-vertical-scrollbars land.

The solution?

CTRL-ALT-BREAK

This will toggle you between fullscreen and crappy mode.

Wednesday, March 21, 2012

[mysql] UPDATE-JOIN

I used this query to identify duplicated records:

SELECT date, user_id, record_id
FROM records
WHERE active=1
GROUP BY date, user_id
HAVING COUNT(*)=2

Say it returns 26 records. Now I want to run a query to update these records' active column to zero. Simple, just nest the above as an outer query's IN clause, right?

UPDATE records
SET active=0
WHERE record_id IN (
  SELECT record_id
  FROM records
  WHERE active=1
  GROUP BY date, user_id
  HAVING COUNT(*)=2);

Nope. MySql has a little something to say about that plan.

You can't specify target table 'records' for update in FROM clause

Great, you can't nest a SELECT of the table you're updating. Fortunately, there is a way out, rewriting the above as an UPDATE-JOIN.

UPDATE records a 
JOIN (
  SELECT record_id
  FROM records
  WHERE active=1
  GROUP BY date, user_id
  HAVING COUNT(*)=2) b 
ON a.record_id=b.record_id
SET a.active=0;

Tuesday, February 14, 2012

[php] PHP_Incomplete_Class

You've saved an object instance of YourClassName into session. On a subsequent retrieval of this object from session, you discover it's now a __PHP_Incomplete_Class object!

your_object = __PHP_Incomplete_Class Object
(
  [__PHP_Incomplete_Class_Name] => YourClassName
  [id] => 123
  [name] => Fred
)

Check where you're doing the session_start. Chances are you did not include YourClassName (plus any required files of its inheritance chain, if applicable) before starting the session.

Monday, February 13, 2012

[mysql] Opening another result tab in workbench

Even when I have multiple scratch tabs open, MySql Workbench 5.3 always reuses the same "Result (1)" tab for displaying query results. But what if you want to compare the results of two queries?

Click the thumbtack icon at the top right of the Result window ("toggle pinned state of the page") after running the first. Now your next query will be forced to create a second Result tab.

[mysql] Querying column definitions

To list the columns and their definitions, simply run the query:

show columns from your_table_name

[php] Show warnings/errors

I'm always forgetting this.

error_reporting(E_ALL);
ini_set('display_errors', '1');