↓ Archives ↓

Posts Tagged → mysql

Two patches for Lithium (li3)

First, added method _toBoolean to Lithium\data\source\database\adapter\MySql:

    protected function _toBoolean($value) {
        return (int) parent::_toBoolean($value);
    }

Now Lithium treat tinyint(1) in MySQL as boolean type, but when you insert/update with a field has been defined as tinyint(1), Lithium will try insert boolean type, then an SQL error will throws.

The second patch is for Lithium\data\source\Database. Try this:

class User extends Lithium\data\Model {}

$user = User::create();
$user->name = 'Leechael';
$user->email = 'blah@blah.blah';
$user->blah = 'Field that NOT exists in schema';
$user->save();

Than you will got an SQL error, said unknown column `blah`. The solution is add a few lines in method Database::create() and Database::update(). First one, go to line 190:

while (list($field, $value) = each($data['fields'])) { // This line is what we looking for!
    // Insert following block!
    if (!isset($schema[$field])) {
        continue;
    }
// other codes ....

Second, go to line line 274 (after previous patched):

while (list($field, $value) = each($data['fields'])) { // You looking for this!
    if (!isset($schema[$field])) {
        continue;
    }
// other codes ....

Done.

问题解决笔记三则

改用 homebrew 作为包管理工具

改用了 homebrew 作为包管理工具。 @jjgod 有一篇对 homebrew 的介绍,不过文中说的安装方法有点繁琐;我本就是想打算用 homebrew 来管理这些工具的。

官方提供了一个 Ruby 安装脚本,因此也可以通过这个方法进行安装:

ruby -e "$(curl http://gist.github.com/raw/323731/install_homebrew.rb)"

由于 homebrew 的哲学之一,就是避免使用 sudo,将程序的 owner 更改为 root,所以需要更改默认安装目录的权限来避免因为权限问题而出现的操作失败:

sudo chown -R `whoami` /usr/local

我是完整卸载 MacPorts 后才安装的 homebrew 的,自然得把缺的东西的装回来,倒是得先把一些工具装回来:

brew install git wget rsync

至于 Mercurial,homebrew 给出一个提示让我使用 pip 安装:

brew install pip && pip install mercurial

MySQL 无法启动

由于改用了 homebrew 作为包管理工具,原来 MacPorts 安装的 MySQL 得重新安装,但安装结束后却得到了一个错误,ERROR! Manager of pid-file quit without updating file,求救于 Google 大神,发现是 MacPorts 卸载时没有清理干净 MySQL 进程导致的问题killall mysql,然后进行剩余步骤:

mysql_install_db
launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
cp /usr/local/Cellar/mysql/5*/com.mysql.mysqld.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist

还得给 .profile 文件加上 alias,alias mysqlctl=”/usr/local/Cellar/mysql/5.1.47/share/mysql/mysql.server”,保存,source ~/.profile,然后 mysqlctl start,搞定。

MacVim 的配置问题

用上了 fugitive.vim 才知道 MacVim 的 $PATH 是有问题的,打开 Preferences,激活 Launch Vim processes in a login shell 这个选项,打开一个新的 MacVim 窗口,:!echo $PATH,问题就这样解决了。

z3n: web based checklist

early Sreenshot of z3n

z3n 是什么呢?

z3n 是一个可以用作 checklist / to-do list 的小工具。它需要 PHP 5.3.0 或以上版本才能运行。对于 Windows 用户来说,下载一个 WAMP5,再进行一些简单的设置即可运行。这个小工具并不建议于公共空间中运行——因为这是仅是一个小工具,没有任何对校验用户身份的代码。

z3n 的安装十分简单,在 MySQL 中创建一个数据库,然后在导入 z3n.init.sql 进行数据库的初始化;这些操作你都可以通过 PHPMyAdmin 完成。然后把 core 目录下的 config.example.php 重命名为 config.php,然后填写相应项进行设置。对于本地运行、例如利用 WAMP5 简单快速部署 z3n 的朋友,只需设置 Z3N_MYSQL_USERNAME,Z3N_MYSQL_PASSWORD,Z3N_MYSQL_SCHEMATA 这三个值就可以了。如果你觉得页面显示 Leechael 的这样的文字很碍眼,你可以把 Z3N_USERNAME 更改为你想要的字眼,例如 “Simpson” 或者 “Mr. Potatohead”;中文也是可以的,只要记得该文件是使用 UTF-8 编码格式保存即可。另一个设置是 Z3N_BACKGROUND_IMAGE,我在压缩包里面放了四张背景图片,根据喜好把图片名字替换 Z3N_BACKGROUND_IMAGE 的值即可。

输入条目时,可以通过按下 enter 保存;如果按下的是 ctrl + enter,则是在保存当前条目的同时创建一个新的条目,以保证你整个输入流程是连续的。

Z3N 是基于 BSD 协议发布,请随意使用。下载地址:http://yan-yan.info/files/z3n.tar.gz

Z3N 的原型是 @Livid 旧作 Project-Babel 中的 zen,一个很好用的小工具,但我们并不需要 Project-Babel 完整的功能,所以, Z3N 诞生了。

这是一个利用空余时间制作的小东西,没有进行严谨的调试,如果你在使用中出现莫名其妙的情况,请留言告知。

对了,你需要一个多人可协作版本的 Z3N 吗? ;-)