Feb
26
2009
0

update table with condition from different table

If we want to make an update to a table, but have to condition that update with values from a second one, we do something like this:

TABLE_1
id_t1 name fee
1 john 100
2 rita 100
3 peter 100

TABLE_2
id_t2 id_t1 type
1 1 single
2 2 single
3 3 married

If we want to update the field “fee” from TABLE_1, for example, to make single people pay more than married people (i know, stupid example, but bear with me), we can do this:

update TABLE_1 t1,TABLE_2 t2 set t1.fee=200 where t1.id_t1=t2.id_t1 and t2.type='single'

this is going to update all the rows in TABLE_1 that belong to “single” people, resulting in:

TABLE_1
id_t1 name fee
1 john 200
2 rita 200
3 peter 100

The update is an inner join with the comma operator.

Heres a link to the MySQL manual page on the update command as a reference. Has some nice examples:

http://dev.mysql.com/doc/refman/5.0/en/update.html

Written by 42 in: MySQL | Tags: , , ,
Feb
23
2009
2

Format/convert decimal to hexadecimal (or other numeral system)

My problem was to convert some calculations from decimal to hexadecimal to be used in a canvas background color. Specifically, convert from CMYK, from a pantone list, to RGB and apply the result to a canvas.

In a different post i will describe the convertion, might be useful for someone.

Flex has a way of converting to several numeral systems. For example, from the manual:

var myuint:uint = 9;
trace(myuint.toString(2)); // output: 1001 - binary system
trace(myuint.toString(8)); // output: 11 - octal system

And to create hexadecimal values, to be used in uint format:

var r:uint = 250;
var g:uint = 128;
var b:uint = 114;
var rgb:String = "0x" + r.toString(16) + g.toString(16) + b.toString(16);
trace(rgb); // 0xfa8072

All seems well, except when the result in hexadecimal is just one caracter long, so be sure to check and pad it with a zero.
A simple example:

var r:uint = 8
var rs:String = (r.toString(16).length == 1) ? "0"+r.toString(16) : r.toString(16);

Breaking it down:

r.toString(16) –> converts the var r to hexadecimal, which equals “8″.

I then check the length of the result and, in case it equals 1, add a “0″ to the beginning of the string to pad it.

UPDATE/FIX: As pointed out by Joe (comment below), r.toString(16) converts the decimal number to string representation of a hexadecimal number.

Written by 42 in: Flex | Tags: , , ,
Feb
18
2009
0

Automatic scroll to the bottom of a TextArea

On my current project, i have a debug TextArea that continuously lists some var values and traces. This way i can keep track of whats going on without stopping execution to debug in Flex.

As the list fills, the Text starts going off the screen, downwards. I needed to keep the scroll on the TextArea always on the last piece of text. I googled and i found a solution by Joan Lafferty, from the blog “flex butterflies and bugs”, so all credit goes to where its due. I leave a link to the original post at the end of this one.

Anyway, the solution is as follows:

<mx:TextArea
valueCommit=”txtl.verticalScrollPosition=txtl.maxVerticalScrollPosition”
id=”txtl”
x=”202″
y=”10″
height=”206″
width=”122″
text=”{log}”
editable=”false”
enabled=”true”
wordWrap=”true”
textAlign=”right”/>

Save for the usual dimension/position properties, what you should look at is the valueCommit method, which will simply keep the scroll at the last bit of content in the TextArea.

Joan’s post is far better explained than this, and has an example. I am just posting this here as a reminder to myself and to other forgetful geeks out there.

Heres the link to Joan’s blog post about this subject:

http://butterfliesandbugs.wordpress.com/2007/08/20/scrolling-to-the-bottom-of-a-container-or-textarea-automatically/

Written by 42 in: Flex | Tags: , ,

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes