網頁

2015年6月2日 星期二

Henplus下複製整個Table資料到新的資料庫

前陣子寫了Henplus下使用Alert Table,但想到最好是能下個SQL(使用Henplus的關係)直接複製整個table的資料,最好連建table都不用,看半天後沒想到真的有,只要利用SELECT INTO
henplus> select * into database_name.new_table from old_table;
affected 47186 rows (547 msec) //成功

這麼簡單就搞定建table及放入所有資料。

不過官網文字有個注意事項
WARNING! Be careful about running select into across databases if you have column names that exist in both databases, as this may cause problems.

另外,以官網Back Up Data to a New Table所記載,最好是先用sp_spaceused查詢下資料庫或資料表的使用空間,不過使用henplus只會看到如下的回覆文字,得使用DbVisualizer或其他方式吧,有發現再做更新。
sp_spaceused old_table;
affected 1 rows (50 msec)

注意事項:做這之前要先設定auto-commit為on,否則會一直出現FAILURE: The 'CREATE TABLE' command is not allowed within a multi-statement transaction in the 'xxxx' database.
henplus>set-session-property auto-commit on;

參考網址:
Back Up Data to a New Table
SQL SELECT INTO 语句

2015年6月1日 星期一

強制刪除目錄下特定名稱的檔案或目錄

今天處理個舊專案,原本是用svn,現在要改用git,要先將每個目錄下原關於svn的目錄都刪除掉,以前都傻傻一個個刪除,想想沒有這麼笨吧,找了下相關資料,只要使用底下的shell script即可搞定

cd 你的目錄
find . -type d -name '.svn' <--先確認檔案
find . -type d -name '.svn' | while read f;do rm -rf "$f"; done <-- 全部強制刪除

這樣就ok了,若要刪除檔案,type後的d就改成f

參考網址:
Linux: remove file extensions for multiple files

2015年5月24日 星期日

Log4j deploy error: log4j:WARN No appenders could be found for logger

今天在處理一個很舊很舊的Tomcat案子時,因為一時手滑,弄丟了所有的設定,將備份的放進去後,一直發生底下的error

資訊: Deploying web application directory TEST
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
2015/5/23 下午 03:19:43 org.apache.catalina.core.StandardContext start
嚴重的: Error listenerStart
2015/5/23 下午 03:19:43 org.apache.catalina.core.StandardContext start
嚴重的: Context [/TEST] startup failed due to previous errors

總覺得很奇怪,從沒發生過這問題,google了下,看到這篇WARN No appenders could be found for logger的解决方法,有點半信半疑下將web.xml中跟log4j的設定都
org.springframework.web.context.ContextLoaderListener前後再start,就真的正常了,用了快十來年的J2EE,我還真的第一次遇到這問題,再不然就是之前從來沒記錄過吧,哈哈哈

參考網址:
WARN No appenders could be found for logger的解决方法

2015年5月18日 星期一

Henplus下使用Alter Table

因為連接sybase的環境只有文字介面,所以使用henplus來操作,不過這次想要新增個欄位,執行了底下的sql後
henplus> alter table test add specs char(2) null;

卻一直出現底下的訊息:
FAILURE: The 'ALTER TABLE' command is not allowed within a multi-statement transaction in the 'db' database.

查了半天,看不出所以然來,似乎跟transaction有關,想到henplus預設auto-commit是off,於是執行了底下的指令
henplus>set-session-property auto-commit on;

用底下的指令查一下設定,只要看到on就成功了
henplus>set-session-property
-----------------+----------------+-----------------------------------------------+
      Name       |     Value      |                  Description                  |
-----------------+----------------+-----------------------------------------------+
 auto-commit     | on             | Switches auto commit                          |
 isolation-level | read-committed | sets the transaction isolation level          |
 read-only       | off            | Switches on read only mode for optimizations. |
-----------------+----------------+-----------------------------------------------+

再執行
henplus> alter table test add specs char(2) null;

回覆,這樣就成功囉~
ok. (13 msec)

=====2015/6/2 新增======

若是要改變column name,使用rename column一直無法成功,只能使用sp_rename這個內建函式,使用方式如下
henplus> sp_rename 'test.specs', 'test.specs2';

回覆如下就成功了
affected 1 rows (119 msec)

=====2015/6/2 新增======

=====2015/6/9 新增======

使用Henplus下複製整個Table資料到新的資料庫所提及的複製方式會有個問題,就是primary key無法跟著複製過去,所以要再加上primary key可以用底下的sql
henplus> alter table test add primary key (id);

=====2015/6/9 新增======

參考網址:
Adaptive Server Enterprise 15.7 > Reference Manual: Commands > Commands > alert table

2015年5月14日 星期四

清除Facebook Open Graph快取及測試Facebook分享的畫面

一般在沒有申請Facebook API的情況下,只是做分享都會用使用https://www.facebook.com/sharer.php?u=<你的link>這樣的方式來分享網址,但若是在實作過程中先測試過了,會造成Fabcebook將其cache畫面及資料,即使之後再加上og:xxx之類的meta,也無法更動內容,這時可以先到https://developers.facebook.com/tools/debug/



填入你的網址後,就會類似下圖:


這邊看來og:type沒加上,我再加上<meta property="og:type" content="website"/>,再按下“Fetch new scrape information”,就成功了,處理好後會發現cache內容也被更動了

另外,Debug過程發現og meta的順序如下:
type -> url -> title -> images

這樣就可以使用https://www.facebook.com/sharer.php?u=<你的link>來做些細節的調整了

參考網址:
Facebook Open Graph not clearing cache
og:image Open Graph Warnings image size
https://developers.facebook.com/tools/debug/ (Debugger)
https://developers.facebook.com/tools/debug/og/object/

https://developers.facebook.com/docs/reference/opengraph/object-type/website/

The Open Graph protocol