Archives

You are currently viewing archive for November 2007
Category: Web dev
Posted by: hajime osako
Category: Study
Posted by: hajime osako
DELETE returns a true row count, but TRUNCATE TABLE returns 0.
TRUNCATE TABLE and DELETE without WHERE clause may reset the sequence number of AUTO_INCREMENT.
You can use ORDER BY and LIMIT clauses in DELETE statements.

TRUNCATE TABLE requires the DELETE privilege.
Category: Study
Posted by: hajime osako
The UPDATE statement does not have any effect if the statement does not actually change any column values, even there is a TIMESTAMP column with ON UPDATE CURRENT_TIMESTAMP.

You can use ORDER BY and LIMIT in the UPDATE statement.

The --safe-updates option is for preventing dangerous UPDATE statement, such as no WHERE clause.
Category: Linux tips
Posted by: hajime osako
RPMパッケージの利用例

パッケージの中身にどんなファイルが入っているのか調べる
$ rpm -qpl netkit-base-0.10_jp-5.i386.rpm

アンインストール
$ rpm -e package_name [--noscripts]

デバッグ情報を出力 -vv
$ rpm -Vvv package_name
Category: Web dev
Posted by: hajime osako
GRANT ... IDENTIFIED BY 'mypass' [WITH GRANT OPTION];

If you do not want to send the password in clear text and you know the hashed value that PASSWORD() would return for the password, you can specify the hashed value preceded by the keyword PASSWORD:

GRANT ... IDENTIFIED BY PASSWORD '*6C8989366...' [WITH GRANT OPTION];

"If you create a new user but do not specify an IDENTIFIED BY clause, the user has no password. This is very insecure. However, you can enable the NO_AUTO_CREATE_USER SQL mode to prevent GRANT from creating a new user if it would otherwise do so, unless IDENTIFIED BY is given to provide the new user a non-empty password."

SET sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER";

MySQL AB :: MySQL 5.1 Reference Manual :: 12.5.1.3 GRANT Syntax
Category: Web dev
Posted by: hajime osako
PHP TIPS Vol.5
header("Content-Disposition: inline; filename=\"".basename($path_file)."\"");
header("Content-Length: ".$content_length);
header("Content-Type: application/octet-stream");

あとHTMLヘッダーに:
<meta http-equiv="Content-Type" content="application/vnd.ms-excel; charset=UTF-8"/>
Category: Linux tips
Posted by: hajime osako
環境変数の一覧を表示するには printenv

設定するには export 環境変数名=値
Category: Linux tips
Posted by: hajime osako
SunのサイトよりJDKをダウンロードし、binを実行
Apache ANTのサイトよりantをダウンロードし、
 # cd /usr/local
 # tar -xzf apache-ant-1.x.x-bin.tar.gz
 # ln -s apache-ant-1.x.x ant
 # ln -s /usr/local/ant/bin/ant /usr/local/bin/ant
$ ant -buildfile build.xml -D[dir name]="[dir path" destination
Category: Study
Posted by: hajime osako
If both the column list and the VALUES list are empty, MySQL creates a new record with each column set to its default:

 INSERT INTO table_name () VALUES();

When you have many records to add, multiple-row statements provide better performance (but may reach the max_allowed_packet size.)

In error condition for multiple record INSERT statements, MyISAM inserts the records until the error record, but for InnoDB, the entire statement fails and no records are inserted.

INSERT ... ON DUPLICATE KEY UPDATE clause allows you to do in one statement what otherwise requires two (INSERT and UPDATE).

 INSERT INTO log_table (id, date_time, counter)
 VALUES (1, NOW(), 1)
 ON DUPLICATE KEY UPDATE counter=counter+1;

Note: If an already existing record is updated, the "rows affected" value is 2.

If a table contains multiple unique-valued indexes, REPLACE replaces each of those records (deletes the matching multiple rows, then inserts one row.)

REPLACE requires the INSERT and DELETE privilege.

11/15: Linux > RPM

Category: Linux tips
Posted by: hajime osako
自分で作るRPMパッケージ(1/3)
7.3. 標準で定義されているマクロ
$ rpm --showrc
$ rpm --eval "%{マクロ}"

ちなみに、標準で定義されているマクロは /usr/lib/rpm/macros

一般ユーザーでRPMパッケージをビルドするには
$  mkdir -p ~/rpm/{BUILD,RPMS,SOURCES,SPEC,SRPMS}

~/.rpmmacros
%_topdir                /home/user_name/rpm
%_builddir              %{_topdir}/BUILD
%_rpmdir                %{_topdir}/RPMS
%_sourcedir             %{_topdir}/SOURCES
%_specdir               %{_topdir}/SPECS
%_srcrpmdir             %{_topdir}/SRPMS
ちなみに、rpmbuildをインストールするには、yum install rpm-build

rpmbuild -ba --define 'param_name value' spac_file_name
Category: Study
Posted by: hajime osako
IN() always returns NULL when used to test NULL, even if NULL is included in the list.

IF() and CASE as used in expressions have somewhat different syntax than the IF and CASE statements such can be used within compound statements.

For approximate values, ROUND() uses the rounding method provided in the C library.

 SELECT ROUND(11.5), ROUND(-11.5); <--- returns 12 and -12
 SELECT ROUND(1.15E1), ROUND(-1.15E1); <--- returns 11 and -11

FLOOR() returns the largest integer not greater than its argument.

 SELECT FLOOR(14.7), FLLOR(-14.7); <--- returns 14 and -15

The LENGTH() and CHAR_LENGTH() functions determine string lengths in byte and character units, respectively.

The CONCAT() returns NULL if any of its arguments are NULL, however CONCAT_WS() ignores NULL values.

The STRCMP() function compares two strings and returns -1, 0, or 1.

MySQL encription functions:

 PASSWORD() (one-way)
 ENCODE() and DECODE()
 DES_ENCRYPTY() and DES_DECRYPT()
 AES_ENCRYPT() and AES_DECRYPT()

MAKEDATE() takes two arguments year and day of the year.
MAKETIME() produces a time from hour, minute, and secound arguments.

To determine the current date or time, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, or NOW().

MySQL disallows a double dash (--) without a space as comment.
/*! */ is not a comment in MySQL.

 CREATE TABLE t (i INT) /*! ENGINE = MEMORY */
 SHOW /*!50002 FULL */ TABLES; <-- If MySQL is 5.0.2 or newer.

11/14: LDAPの基礎

Category: Web dev
Posted by: hajime osako
Active Directoryオブジェクトの識別名(DN)とは − @IT

DN (Distinguished Name) = "CN=suzuki,OU=Eigyou1,DC=example,DC=co,DC=jp"

上のカンマで区切られたものが、RDN:Relative Distinguished Nameで、属性名はディレクトリ・サービスに依存する。

Active Directory例:
CN=Common-Name (ユーザー名やグループ名、コンピュータ名、ほか)
OU=Organizational-Unit-name (組織単位(OU))
DC=Domain-Component (ドメイン構成)
Category: Web dev
Posted by: hajime osako
Category: Web dev
Posted by: hajime osako
Category: N800
Posted by: hajime osako
"# Add the Maemo Repositories to the Application Manager * Maemo Base o http://repository.maemo.org/ o bora o free non-free * Maemo Extras o http://repository.maemo.org/extras/ o bora o free non-free * Maemo Hackers o http://maemo-hackers.org/apt/ o bora o main"
rwhitby.net :: Setting up my Nokia N800
Category: Study
Posted by: hajime osako
Temporal Expressions

To perform interval arithmetic, use the INTERVAL keyword and a unit value:

SELECT '2007-12-31' + INTERVAL 10 DAY; (or INTERVAL 10 DAY + '2007-12-31')
SELECT '2007-12-31' - INTERVAL 10 DAY;

* Not DAYS.

The INTERVAL can be specified in units such as SECOND, MINUTE, HOUR, DAY, MONTH or YEAR.


NULL Values

Use of NULL values in arithmetic or comparison operations normally produces NULL results. Even comparing NULL to itself results in NULL.
The following statements return NULL:

SELECT NULL + 1, NULL < 1;
SELECT NULL = 1, NULL != NULL;
SELECT NULL LIKE '%', NULL LIKE NULL;

In MySQL, <=> operator works like = and this works with NULL operand.
NULL values sort together (ORDER BY), group together (GROUP BY), and are not distinct.
Expressions that cannot be evaluated (such as 1/0) produce NULL as a result, but the result NULL value cannot be inserted. This is controlled by ERROR_FOR_DIVISION_BY_ZERO mode.
Category: Web dev
Posted by: hajime osako
SSL/TLS の導入 (1)

RSA 秘密鍵生成と確認
openssl genrsa -out server.key 1024
openssl rsa -in server.key -text -noout

CSR 生成と確認
openssl req -new -key server.key -out csr.pem -sha1
openssl req -in csr.pem -text -noout

CRT 署名と確認
openssl x509 -in csr.pem -out server.crt -req -signkey server.key -days 365 -sha1
openssl x509 -in server.crt -text -noout

CRTの確認2
openssl verify server.crt
openssl asn1parse -in server.crt
Category: Web dev
Posted by: hajime osako