Recent Comments

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

2013年12月20日 星期五

PostgreSQL 安裝 pldebugger USE_PGSX

PostgreSQL 安裝 pldebugger USE_PGSX

使用 USE_PGSX=1 make,在pldebugger編好後就會直接把編好的plugin_debugger.so和pldbgapi--1.0.sql放到/usr/pgsql-9.3相對應的位置。

yum install git readline-devel zlib-devel openssl-devel

cd /opt
tar xvzf postgresql-9.3.2.tar.gz

cd /opt/postgresql-9.3.2
USE_PGXS=1 ./configure
USE_PGXS=1 make

cd /opt/postgresql-9.3.2/contrib/
git clone git://git.postgresql.org/git/pldebugger.git
make 

cd /opt/postgresql-9.3.2/contrib/pldebugger
USE_PGXS=1 make
USE_PGXS=1 make install

[root@localhost pldebugger]# USE_PGXS=1 make install                                                                                                         gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/include/et -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -shared -o plugin_debugger.so plpgsql_debugger.o plugin_debugger.o dbgcomm.o pldbgapi.o -L/usr/pgsql-9.3/lib -L/usr/lib64 -Wl,--as-needed
/bin/mkdir -p '/usr/pgsql-9.3/lib'
/bin/mkdir -p '/usr/pgsql-9.3/share/extension'
/bin/mkdir -p '/usr/pgsql-9.3/share/extension'
/bin/mkdir -p '/usr/share/doc/pgsql/extension'
/usr/bin/install -c -m 755  plugin_debugger.so '/usr/pgsql-9.3/lib/plugin_debugger.so'
/usr/bin/install -c -m 644 ./pldbgapi.control '/usr/pgsql-9.3/share/extension/'
/usr/bin/install -c -m 644 ./pldbgapi--1.0.sql ./pldbgapi--unpackaged--1.0.sql  '/usr/pgsql-9.3/share/extension/'
/usr/bin/install -c -m 644 ./README.pldebugger '/usr/share/doc/pgsql/extension/'


vim /var/lib/pgsql/9.3/data/postgresql.conf
加入下面的設定
shared_preload_libraries = '$libdir/plugin_debugger'

重新啟動
service postgresql-9.3 restart

安裝pldbgapi
su - postgres
psql
CREATE EXTENSION pldbgapi;
\dx

-bash-4.1$ psql
psql (9.3.2)
Type "help" for help.

postgres=# CREATE EXTENSION pldbgapi;
CREATE EXTENSION
postgres=# \dx
                              List of installed extensions
   Name    | Version |   Schema   |                     Description
-----------+---------+------------+------------------------------------------------------
adminpack | 1.0     | pg_catalog | administrative functions for PostgreSQL
pldbgapi  | 1.0     | public     | server-side support for debugging PL/pgSQL functions
plpgsql   | 1.0     | pg_catalog | PL/pgSQL procedural language
(3 rows)

================================================================
當pldebugger在USE_PGXS=1 make時出現下面的錯誤要安裝 openssl-devel套件,安裝好後再重新執行USE_PGXS=1 make

[root@localhost pldebugger]# USE_PGXS=1 make
gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/include/et -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I. -I. -I/usr/pgsql-9.3/include/server -I/usr/pgsql-9.3/include/internal -I/usr/include/et -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include  -c -o pldbgapi.o pldbgapi.c
In file included from pldbgapi.c:98:
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:25:25: error: openssl/ssl.h: No such file or directory
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:26:25: error: openssl/err.h: No such file or directory
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:36:27: error: gssapi/gssapi.h: No such file or directory
In file included from pldbgapi.c:98:
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:86: error: expected specifier-qualifier-list before ‘gss_buffer_desc’
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:176: error: expected specifier-qualifier-list before ‘SSL’
make: *** [pldbgapi.o] Error 1

PL/SQL 和 PL/pgSQL 旅行時間TRIGGER

以下TRIGGER內容主要是當區段旅行時間比對成功後,在INSERT AVI_SECTION_TRAVEL資料表後會執行下面的TRIGGER,將新的旅行時間更新到XML_AVI_VALUE表中,因為資料的時間需要是每五分鐘的顯示,如5分、10分,N_MIN_FIND就是找出現在旅行時間是在那個五分鐘區間中,如旅行時間是20131221 12:12:30,則 N_MIN_FIND會是20131221 12:15:00

以下是ORACLE和POSTGRESQL的寫法,主要差異在N_MIN_MOD和N_MIN_FIND兩個變數

ORACLE
=====================================================================
DECLARE
C_MIN_LOG_RANGE CONSTANT INTEGER := 5; --統計分鐘數
  N_MIN_MOD INTEGER;       --取餘數
  N_MIN_ADD INTEGER;       --以旅行時間要加的分鐘數 (統計分鐘數 - N_MIN_MOD)
  N_MIN_FIND TIMESTAMP;    --找volume記錄時間  = 旅行時間 + N_MIN_ADD
N_RECORD_COUNT INTEGER;
BEGIN
N_MIN_MOD := MOD(TO_CHAR(:NEW.DATETIME,'MI'),C_MIN_LOG_RANGE);
  N_MIN_ADD := C_MIN_LOG_RANGE-N_MIN_MOD;
  N_MIN_FIND := TO_TIMESTAMP(TO_CHAR(:NEW.DATETIME+(N_MIN_ADD/1440),'YYYY-MM-DD HH24:MI'),'YYYY-MM-DD HH24:MI');

SELECT COUNT(SECTION_ID) INTO N_RECORD_COUNT FROM XML_AVI_VALUE WHERE SECTION_ID=:NEW.SECTION_ID;

IF N_RECORD_COUNT>0 THEN
UPDATE XML_AVI_VALUE SET TRAVELTIME=:NEW.TRAVEL_SMOOTH,DATACOLLECTTIME=N_MIN_FIND  WHERE SECTION_ID=:NEW.SECTION_ID;
END IF;
END;


POSTGRESQL
=====================================================================
DECLARE
C_MIN_LOG_RANGE CONSTANT INTEGER := 5; --統計分鐘數
N_MIN_MOD INTEGER;       --取餘數
N_MIN_ADD INTEGER;       --以旅行時間要加的分鐘數 (統計分鐘數 - N_MIN_MOD)
N_MIN_FIND TIMESTAMP;     --找volume記錄時間  = 旅行時間 + N_MIN_ADD
N_RECORD_COUNT INTEGER; --找出XML_AVI_VALUE資料表中是否有該SECTION_ID的資料
BEGIN--

--insert avi_xml_value
        N_MIN_MOD := MOD(to_number(TO_CHAR(NEW.datetime,'MI'),'99'),C_MIN_LOG_RANGE);
        IF N_MIN_MOD=0 THEN
   N_MIN_ADD := 0;
ELSE
   N_MIN_ADD := C_MIN_LOG_RANGE-N_MIN_MOD;
END IF;

N_MIN_FIND := TO_TIMESTAMP(TO_CHAR(NEW.datetime,'YYYY-MM-DD HH24:MI'),'YYYY-MM-DD HH24:MI')+(TO_TIMESTAMP(TO_CHAR(N_MIN_ADD,'99'),'MI')-TO_TIMESTAMP(TO_CHAR(0,'99'),'MI'));

SELECT COUNT(SECTION_ID) INTO N_RECORD_COUNT FROM XML_AVI_VALUE WHERE SECTION_ID=NEW.SECTION_ID;

IF N_RECORD_COUNT>0 THEN
   UPDATE XML_AVI_VALUE SET TRAVELTIME=NEW.TRAVEL_SMOOTH,DATACOLLECTTIME=N_MIN_FIND  WHERE SECTION_ID=NEW.SECTION_ID;
END IF;
END;

PostgreSQL 安裝 pldebugger

yum install git readline-devel zlib-devel

cd /opt
tar xvzf postgresql-9.3.2.tar.gz
cd /opt/postgresql-9.3.2/contrib/
git clone git://git.postgresql.org/git/pldebugger.git

cd /opt/postgresql-9.3.2
./configure
make

cd /opt/postgresql-9.3.2/contrib/pldebugger
make
make install

/bin/mkdir -p '/usr/local/pgsql/lib'
/bin/mkdir -p '/usr/local/pgsql/share/extension'
/bin/mkdir -p '/usr/local/pgsql/share/extension'
/bin/mkdir -p '/usr/local/pgsql/share/doc//extension'
/usr/bin/install -c -m 755  plugin_debugger.so '/usr/local/pgsql/lib/plugin_debugger.so'
/usr/bin/install -c -m 644 ./pldbgapi.control '/usr/local/pgsql/share/extension/'
/usr/bin/install -c -m 644 ./pldbgapi--1.0.sql ./pldbgapi--unpackaged--1.0.sql  '/usr/local/pgsql/share/extension/'
/usr/bin/install -c -m 644 ./README.pldebugger '/usr/local/pgsql/share/doc//extension/'

cp /usr/local/pgsql/lib/plugin_debugger.so /usr/pgsql-9.3/lib/  
cp /usr/local/pgsql/share/extension/pldbgapi--1.0.sql /usr/pgsql-9.3/share/extension/  
cp /usr/local/pgsql/share/extension/pldbgapi--unpackaged--1.0.sql /usr/pgsql-9.3/share/extension/
cp /usr/local/pgsql/share/extension/pldbgapi.control /usr/pgsql-9.3/share/extension/

vim /var/lib/pgsql/9.3/data/postgresql.conf
加入
shared_preload_libraries = '$libdir/plugin_debugger'

service postgresql-9.3 restart

su - postgres
psql
CREATE EXTENSION pldbgapi;
\dx

-bash-4.1$ psql
psql (9.3.2)
Type "help" for help.

postgres=# CREATE EXTENSION pldbgapi;
CREATE EXTENSION
postgres=# \dx
                              List of installed extensions
   Name    | Version |   Schema   |                     Description
-----------+---------+------------+------------------------------------------------------
adminpack | 1.0     | pg_catalog | administrative functions for PostgreSQL
pldbgapi  | 1.0     | public     | server-side support for debugging PL/pgSQL functions
plpgsql   | 1.0     | pg_catalog | PL/pgSQL procedural language
(3 rows)

postgres=#

2012年9月2日 星期日

CentOS 設定使用者自動登入


 vim /etc/gdm/custom.conf

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=abc


2012年8月15日 星期三

找出重疊的元件


.cpp
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::___TEST(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int I;
TPoint pt;
TStringList *L = new TStringList;
GetCursorPos(&pt);
pt = this->ScreenToClient(pt);
for (I=0; I if (!Controls[I]->ClassNameIs("TPaintBox")){
continue;
}
if (!PtInRect(Controls[I]->BoundsRect , pt)){
continue;
}
L->Add(Controls[I]->Name);
}
ListBox1->Items->Text = L->Text;
delete L;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::PaintBox1Paint(TObject *Sender)
{
TPaintBox  *tPbx =((TPaintBox *)Sender);
tPbx->Canvas->Rectangle(0,0,tPbx->Width,tPbx->Height);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
for (int I=0; I if (!Controls[I]->ClassNameIs("TPaintBox")){
continue;
}
((TPaintBox*)Controls[I])->OnMouseDown = ___TEST;
}
}
//---------------------------------------------------------------------------

====================================================
.h
//---------------------------------------------------------------------------

#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TPaintBox *PaintBox1;
TPaintBox *PaintBox2;
TPaintBox *PaintBox3;
TListBox *ListBox1;
TButton *Button1;
void __fastcall PaintBox1Paint(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);

private: // User declarations
void __fastcall ___TEST(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif

2012年8月6日 星期一

移動滑鼠執行事件


  SetCursorPos(30,30);
mouse_event(MOUSEEVENTF_LEFTDOWN,30,30,NULL,NULL);
mouse_event(MOUSEEVENTF_LEFTUP,30,30,NULL,NULL);
mouse_event(MOUSEEVENTF_LEFTDOWN,30,30,NULL,NULL);
mouse_event(MOUSEEVENTF_LEFTUP,30,30,NULL,NULL);

2012年7月1日 星期日

shell script 數字補0

數字1、2、3、 補0 => 01、02、03

xx=`echo $num|awk'{printf "%02d", $1}'`
echo $xx;