2016/06/26

オブジェクトの名称はすべて小文字にしておくこと - Postgresql

"Postgresqlでは、オブジェクト(テーブル名、カラム名)の名称はすべて小文字にすること"
-理由

 DB内には、大文字・小文字で区別して登録される
 SQL内では、"(ダブルクォーテーション)で囲まれているとそのままの文字列だが、
 囲まれていないと小文字に変換される(らしい)
 結果、アンマッチがおきる


--------------------------------------------------------
testdb=> \d iris
                Table "public.iris"
    Column     |         Type          | Modifiers 
---------------+-----------------------+-----------
 Id            | integer               | not null
 SepalLengthCm | numeric(15,2)         | 
 SepalWidthCm  | numeric(15,2)         | 
 PetalLengthCm | numeric(15,2)         | 
 PetalWidthCm  | numeric(15,2)         | 
 Species       | character varying(20) | 
Indexes:
    "iris_pkey" PRIMARY KEY, btree ("Id")

testdb=> select * from iris where SepalLengthCm > 5.0; -> ダメ
ERROR:  列"sepallengthcm"は存在しません
LINE 1: select * from iris where SepalLengthCm > 5.0;
                                 ^
HINT:  Perhaps you meant to reference the column "iris.SepalLengthCm".
testdb=> select * from iris where "iris.SepalLengthCm" > 5.0;->ダメ
ERROR:  列"iris.SepalLengthCm"は存在しません
LINE 1: select * from iris where "iris.SepalLengthCm" > 5.0;
                                 ^
testdb=> select * from iris where "SepalLengthCm" > 5.0; -> OK
testdb=> select * from iris where iris."SepalLengthCm" > 5.0; -> OK

testdb=> 

雑多な1行コマンド&SQLメモ - Postgresql

メモ for Postgresql

‐Postgresql編

-- テーブル情報の表示
testdb=> \d -- teble 一覧表示
リレーションの一覧
スキーマ | 名前 | 型 | 所有者
----------+------------+----------+--------
public | department | テーブル | toshi
(1 行)
testdb=> \d department -- tableのカラム名/型を表示
テーブル "public.department"
列 | 型 | 修飾語
--------+---------------+----------
id | integer | not null
dept | character(50) | not null
emp_id | integer | not null
インデックス:
"department_pkey" PRIMARY KEY, btree (id)
-- 接続終了
testdb=> \q
-- 設定ファイルの確認
testdb=> SHOW config_file



2016/06/25

Virtualbox上のUbuntu16.4にPostgresql 9.5をインストールする

MACのVirtualbox上のUbuntu16.4にPostgresql9.5をインストールする。
以下のSTEPをサーバー上で行う。(SSHでも可能)
#1# インストール
#2# Postgresqlを開始する
#3# postgresの初期パスワードを設定する
#4# postgres でログインして、DB作成と別userでもログインできるようにする

#5# クライアントからの接続を許可する

# POSTGRESQLのインストールからクライアント接続するまで(ubuntu 16.4 LTS on VIRTUALBOX with MAC)
#1# INSTALL
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
$ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib
#2# START
$ sudo /etc/init.d/postgresql start
$ sudo /etc/init.d/postgresql status
#3# SET initial password for postgres
$ sudo passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
#4# login as postgres and create DB and user
$ su - postgres ## userをpostgresに変更する
$ createdb <dbname> ## dbを作成する
$ psql <dbname> ## dbにpostgresでログインする
psql (9.5.3)
"help" でヘルプを表示します.
<dbname>=# create role <username> with login; ## <username>でログインできるようにする
CREATE ROLE
<dbname>=# \q
$ su - <username> ## userを変更する
$ psql <dbname> ## dbに<username>でログインする
psql (9.5.3)
"help" でヘルプを表示します.
<dbname>=>
#5# Allow to access from client
$ vi /etc/postgresql/9.5/main/postgresql.conf ## postgresql.conf のセッティングを変更する
##以下抜粋##
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' ##初期は、クライアントからの接続を許可していないので
##'*’に変更する
##編集終了##
$ /etc/init.d/postgresql restart ## リスタートする
$ vi /etc/postgresql/9.5/main/pg_hba.conf ## pg_hba.conf のセッティングを変更する
##以下抜粋##
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all all trust
## これは、ADDRESSにALLをセット、MethodにTrustをセット。これはどの端末からでも
## どのDBへの接続も許可している。
##編集終了##
$ /etc/init.d/postgresql restart ## リスタートする
## このあとクライアントソフトからテストして確認する ##
view raw postgresql.sh hosted with ❤ by GitHub

## pg_hba.confのセッティングについては、以下参考
-postgresqlのページ
https://www.postgresql.jp/document/9.5/html/auth-pg-hba-conf.html

2016/06/17

限界費用ゼロ社会 <モノのインターネット>と共有型経済の台頭

ちょっと興味ありKindle版購入

限界費用ゼロ社会 <モノのインターネット>と共有型経済の台頭





.bash コマンドメモ

.bash のコマンドメモ

#1# bash の種類を確認
$ which bash
/bin/bash
#この結果をスクリプトの一行目に表示する
#!/bin/bash
#2# フォルダの変更
$ cd .. #一つ上のフォルダへ
#3# フォルダの中身を表示
$ ls #ただ表示するだけ
bin drafts pages tmp
$ ls -a #.始まりも表示 隠しファイルも表示
. .. .git bin drafts pages tmp
$ ls -l #リスト表示
total 8
drwxr-xr-x 5 Toshi_Admin staff 170 Jun 14 22:39 bin
drwxr-xr-x 3 Toshi_Admin staff 102 Jun 14 22:17 drafts
drwxr-xr-x 9 Toshi_Admin staff 306 Jun 14 22:15 pages
-rw-r--r-- 1 Toshi_Admin staff 357 Jun 16 22:22 tmp
$ ls -la #リストと隠しファイル表示を同時に実行
total 8
drwxr-xr-x 7 Toshi_Admin staff 238 Jun 16 22:22 .
drwx------+ 7 Toshi_Admin staff 238 Jun 13 22:15 ..
drwxr-xr-x 12 Toshi_Admin staff 408 Jun 16 22:24 .git
drwxr-xr-x 5 Toshi_Admin staff 170 Jun 14 22:39 bin
drwxr-xr-x 3 Toshi_Admin staff 102 Jun 14 22:17 drafts
drwxr-xr-x 9 Toshi_Admin staff 306 Jun 14 22:15 pages
-rw-r--r-- 1 Toshi_Admin staff 357 Jun 16 22:22 tmp
#4#ファイル、フォルダの削除
$ rm xxxxxx.conf #ファイルの削除
$ rm -r pages # フォルダの削除
#5#ファイルのコピー
$ cp xxxxxx.txt xxxx123.txt #ファイル単体のコピー
$ cp -r YYYYY ZZZZZ # フォルダーのコピー
#6# ディレクトリを作成
$ mkdir xxxxx #xxxxx ディレクトリをカレントディレクトリに作成
view raw .bash hosted with ❤ by GitHub

2016/06/14

インターネットからの開発者サイトへのアクセスを禁止する - APEX

  • 状況
    インターネットからの開発者サイトへのアクセス時、ログイン画面が表示される。そのアクセスに対して、403エラーを返す。
    また、イントラ向けアプリとインターネット向けアプリが混在している場合、インターネットからのイントラ向けアプリへのアクセスに対して、403エラーを返す。

    以下の画面をインターネットから表示させない。
  • Solution
    mod_rewrite でコントロールする。

    (例) - APEX 4.2.x + OHS を想定
    開発者向け画面(アプリケーション番号は、四千番台:4xxx)と1で始まるアプリケーション番号(1xxx)へのインターネットからのアクセスを403リダイレクトする。

    1. HTTP 接続の場合 - httpd.conf ファイルに以下を追記する

    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^p=1 [OR]
    RewriteCond %{QUERY_STRING} ^p=4
    RewriteRule ^(.*) - [F]


    2. HTTPS接続の場合 - ssl.conf ファイルのvirtualhost内に上記を追記する。
       (注) mod_osslが利用できるようになっていることを確認する。

    ssl.conf のサンプル
    ###################################################################
    # Oracle HTTP Server mod_ossl configuration file: ssl.conf #
    ###################################################################
    # OHS Listen Port
    Listen 4443
    <IfModule ossl_module>
    ##
    ## SSL Global Context
    ##
    ## All SSL configuration in this context applies both to
    ## the main server and all SSL-enabled virtual hosts.
    ##
    #
    # Some MIME-types for downloading Certificates and CRLs
    AddType application/x-x509-ca-cert .crt
    AddType application/x-pkcs7-crl .crl
    # Pass Phrase Dialog:
    # Configure the pass phrase gathering process.
    # The filtering dialog program (`builtin' is a internal
    # terminal dialog) has to provide the pass phrase on stdout.
    SSLPassPhraseDialog builtin
    # Inter-Process Session Cache:
    # Configure the SSL Session Cache: First the mechanism
    # to use and second the expiring timeout (in seconds).
    SSLSessionCache "shmcb:${ORACLE_INSTANCE}/diagnostics/logs/${COMPONENT_TYPE}/${COMPONENT_NAME}/ssl_scache(512000)"
    SSLSessionCacheTimeout 300
    # Semaphore:
    # Configure the path to the mutual exclusion semaphore the
    # SSL engine uses internally for inter-process synchronization.
    <IfModule mpm_winnt_module>
    SSLMutex "none"
    </IfModule>
    <IfModule !mpm_winnt_module>
    SSLMutex pthread
    </IfModule>
    ##
    ## SSL Virtual Host Context
    ##
    <VirtualHost *:4443>
    <IfModule ossl_module>
    # SSL Engine Switch:
    # Enable/Disable SSL for this virtual host.
    SSLEngine on
    # Client Authentication (Type):
    # Client certificate verification type and depth. Types are
    # none, optional and require.
    SSLVerifyClient None
    # SSL Protocol Support:
    # List the supported protocols.
    SSLProtocol nzos_Version_1_0 nzos_Version_3_0
    # SSL Cipher Suite:
    # List the ciphers that the client is permitted to negotiate.
    SSLCipherSuite SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_DES_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
    # SSL Certificate Revocation List Check
    # Valid values are On and Off
    SSLCRLCheck Off
    #Path to the wallet
    #SSLWallet "${ORACLE_INSTANCE}/config/${COMPONENT_TYPE}/${COMPONENT_NAME}/keystores/default"
    SSLWallet file:/u01/app/oracle/product/ohs_apxd1/owm/wallets/oraapxd1
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory "${ORACLE_INSTANCE}/config/${COMPONENT_TYPE}/${COMPONENT_NAME}/cgi-bin">
    SSLOptions +StdEnvVars
    </Directory>
    BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0
    </IfModule>
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^p=1 [OR]
    RewriteCond %{QUERY_STRING} ^p=4
    RewriteRule ^(.*) - [F]
    </VirtualHost>
    </IfModule>

    変更後 のイメージ

buffer overflow. Use SET command to reduce ARRAYSIZE or increase MAXDATA.

  • 状況
    SQL*PLUS でSQL実行時に、エラーメッセージ”buffer overflow. Use SET command to reduce ARRAYSIZE or increase MAXDATA.”が表示される。

    環境 ー 古いんです (^^;

    SQL*Plus: Release 3.3.4.0.0 - Production on Mon Jun 13 10:56:36 2016

    Copyright (c) Oracle Corporation 1979, 1996.  All rights reserved.
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - Production

    SQL> select * from v$version;
    BANNER
    ----------------------------------------------------------------Oracle8i Enterprise Edition Release 8.1.7.4.0 - ProductionPL/SQL Release 8.1.7.4.0 - ProductionCORE    8.1.7.0.0       ProductionTNS for Solaris: Version 8.1.7.4.0 - ProductionNLSRTL Version 3.4.1.0.0 - Production

  • Solution

    SQL> SET ARRAYSIZE 1

    上記を実行の上、SQLを実行する。

2016/06/09

Data set サンプル - Kaggle

サンプル作成用のデータは、以下から取得

Kaggle - https://www.kaggle.com/


1. TITANIC - タイタニック号の乗客名簿

2. IRIS - アヤメのデータ

カラムの幅を固定する - インタラクティブレポート - APEX

  • Goal  (APEX 5.x 向け、4.xは別の方法)
    インタラクティブレポートにおいて、カラムの幅を固定する。
    改行して2行表示にならないようにする。

  • How
    1. インタラクティブリージョンに、静的IDを設定する


    2. 幅を変更したいカラムに、静的IDを設定する


    3. ページのCSS インラインに以下を追加する

    #T td[headers=NAME]{min-width:200px}
    /*
    #<リージョンの静的ID> td[headers=<列の静的ID>]{min-width:200px}
    */
  • To be
    以下のように拡がる


インタラクティブレポートのセルに画像/アイコンを入れる(リンク 無、動的アクション 無) - APEX

  • Goal
    インタラクティブレポートにおいて、セルの中身を画像に変更する。
    リンク 無し、動的アクション 無しで、単に画像が表示されるだけ。
    フィルターは文字列で検索ができる。
    (To be 例) 性別をアイコンで表示する。
        Icon by http://www.fatcow.com/free-icons

    フィルターはこんな感じ

  • As is

    変更前はこんな感じ

  • How
    0. 共有コンポーネント > 静的アプリケーションファイル に、アイコンをUPLOADする。
     その時に、ファイル名を項目の名前と一致させておく。
     この場合は、"male" と "female"。

    1. リージョン: インタラクティブレポート で 対象の列を選び、
     指定 > タイプ: リンク
     リンク > ターゲット: タイプ = "URL"
                                            URL = "#"
     リンクテキストを以下にする
    </a><img src="#APP_IMAGES#ICON/#SEX#.png" alt="" /><a href="#" class="hideMe508">
    //-- 補足1 #SEX# の欄がインタラクティブレポートの列名
    //-- 補足2 <a href="#" class="hideMe508"> は、理由はよくわかりません。 (^^;)

     
  • Reference
    #全般
    Jari's APEX blog

    #データセット
    Titanic: Machine Learning From Disaster

    #アイコン
    フリーアイコン