tweetnestのアーカイブを日本語(2byte文字)対応させる

tweetnestでつぶやきをアーカイブしていたのだが、長いつぶやきのアーカイブが途中で切れていた。いろいろと調べてみると、ある一定の文字数を超えると、途中できれたり化けたりしていた。

原因を探ってみると、tweetnestでつぶやきを格納しているDBの絡むがvarchar(255)で設定されていた。varchar(255)だと、日本語で140文字も格納できない。そのため、途中でデータが切れていたようである。他のカラムの設定を見てみると、text型で設定されているところもあるので、少々アバウトだが、対象のカラムをtext型に変換してみた。変換に使ったSQL文は以下。

mysql> alter table tn_tweets modify text text not null;

これで拡張は終了。次のつぶやき取得から、日本語で140文字あってもちゃんとアーカイブされる。

おまけ。
通しで作業をするとこんな感じ。

mysql> use tweetnest;
mysql> desc tn_tweets;
+--------------+---------------------+------+-----+---------+----------------+
| Field        | Type                | Null | Key | Default | Extra          |
+--------------+---------------------+------+-----+---------+----------------+
| id           | int(10) unsigned    | NO   | PRI | NULL    | auto_increment |
| userid       | int(10) unsigned    | NO   |     |         |                |
| tweetid      | bigint(20) unsigned | NO   |     |         |                |
| type         | tinyint(4)          | NO   |     | 0       |                |
| time         | int(10) unsigned    | NO   |     |         |                |
| text         | varchar(255)        | NO   | MUL |         |                |
| source       | varchar(255)        | NO   |     |         |                |
| favorite     | tinyint(4)          | NO   |     | 0       |                |
| extra        | text                | NO   |     |         |                |
| coordinates  | text                | NO   |     |         |                |
| geo          | text                | NO   |     |         |                |
| place        | text                | NO   |     |         |                |
| contributors | text                | NO   |     |         |                |
+--------------+---------------------+------+-----+---------+----------------+
13 rows in set (0.07 sec)

mysql> alter table tn_tweets modify text text not null;
Query OK, 1287 rows affected (0.28 sec)
Records: 1287  Duplicates: 0  Warnings: 0

mysql> desc tn_tweets;
+--------------+---------------------+------+-----+---------+----------------+
| Field        | Type                | Null | Key | Default | Extra          |
+--------------+---------------------+------+-----+---------+----------------+
| id           | int(10) unsigned    | NO   | PRI | NULL    | auto_increment |
| userid       | int(10) unsigned    | NO   |     |         |                |
| tweetid      | bigint(20) unsigned | NO   |     |         |                |
| type         | tinyint(4)          | NO   |     | 0       |                |
| time         | int(10) unsigned    | NO   |     |         |                |
| text         | text                | NO   | MUL |         |                |
| source       | varchar(255)        | NO   |     |         |                |
| favorite     | tinyint(4)          | NO   |     | 0       |                |
| extra        | text                | NO   |     |         |                |
| coordinates  | text                | NO   |     |         |                |
| geo          | text                | NO   |     |         |                |
| place        | text                | NO   |     |         |                |
| contributors | text                | NO   |     |         |                |
+--------------+---------------------+------+-----+---------+----------------+
13 rows in set (0.00 sec)

mysql>

スポンサーリンク

シェアする

  • このエントリーをはてなブックマークに追加

フォローする