2020年8月1日 星期六

ACCESS資料成功轉換SQlite方法


最近忙於系統開發研究,今日來談一下有朋友很有才華自行利用ACCESS開發了CRM(客戶關係管理)系統,但僅限於個人使用考量目前大量使用者成長與需求,洽詢我是否能技術支援同時給了我ACCESS檔案參考,但因電腦OFFICE沒有ACCESS可開啟.accdb檔案,相信有許多微軟OFFICE使用者也面臨相同問題,甚至於必須買OFFICE彩盒或OFFICE365才能開啟使用吧!!...但對於開發者而言是不可能利用ACCESS資料庫來開發WEB或手機APP。因此,如何能將客戶給予的ACCESS資料庫檔案轉檔出你想要的格式,再匯入到MS SQL或SQlite等資料庫運用,這篇文章就以如何轉換成SQlite來詳細說明。

首先可參考一個有用的mdbtools工具https://clay-atlas.com/blog/2020/01/12/microsoft-chinese-tutorial-mdb-export-all-csv-access/,透過這工具我們可以將需要的mdb資料庫內的Table表,轉換成CSV檔案,以逗號來區隔欄位和表列資料內容。

  • 電腦中安裝 mdbtools 這個工具,要使用以下各指令安裝:
Windows系統指令
sudo apt-get install mdbtools
Linux系統指令
apt-get install mdbtools
MAC系統指令

brew install mdbtools

以下我使用Ubuntu18.0來演示如何將.accdb檔案轉換成CSV檔案。
步驟一:
依照上述指令完成Tools的安裝,此時會出現在你的Download資料夾底下會出現mdb-export-all-master資料夾,記得要轉檔的.accdb檔案要和mdb-export-all.sh執行檔放在同一資料夾內
 
     
         步驟二: 

         執行mdb-export-all.sh 的 shell 檔執行它,加要轉換的 .mdb 檔名稱,就可以得到CSV轉 換檔案。這邊有一個要特別注意的地方,就是要輸入完整路徑full-path-to-ms-access說明要求完整路徑
       
  • 指令為 bash mdb-export-all.sh full-path-to-ms-access-db.accdb
  • 例如我路徑是/home/ubuntu/Downloads/mdb-export-master/(檔名).access
                
                

        步驟三: 
        
        一旦成功會依據當時ACCESS內設計得Table給予各Table轉換出的CSV檔案。

                


SQLITE資料庫安裝與下載

SQLite是世界上部署最廣泛的數據庫,是嵌入式SQL數據庫引擎。與大多數其他SQL數據庫不同,SQLite沒有單獨的服務器進程。SQLite直接讀取和寫入普通磁盤文件。具有多個表索引,觸發器和視圖的完整SQL數據庫包含在單個磁盤文件中。數據庫文件格式是跨平台的-您可以在32位和64位系統之間或在big-endian和 little-endian 體系結構之間自由複制數據庫 。SQLite數據庫文件是美國國會圖書館推薦的存儲格式認為SQLite不能替代 OracleSQLite是一個緊湊的庫。啟用所有功能後,庫大小可以小於600KiB,具體取決於目標平台和編譯器優化設置。SQLite通常為您提供的內存越多,運行速度就越快。但是,即使在低內存環境下,性能通常也相當不錯。基於以上官網介紹,再補充一下想要IOS環境下使用Swift開發APPLE手機使用的APP,其利用與儲存在手機內的資料庫即為Sqlite,這樣聽起來是否能學會如何使用Sqlite相當重要呢。

想要在Windows環境內能開發與編輯Sqlite資料庫DB-Browser相對重要,介紹一個免費且通用軟體工具ScreenShot官方下載網站如后:https://sqlitebrowser.org/。安裝步驟就不再說明其實很簡單,參考官網持續按下一步驟即可完成安裝。安裝完成後我們啟動ScreenShot這個Browser,選擇[檔案]---[匯入]---[Table from CSV],這時應該大家注意它不應該顯示成灰階無法選取,如有無法選取請先自行新增一個.db資料庫,再回頭執行匯入功能。提供圖示我把資料都先灰階,畢竟別人資料內容要保密安全,將每一個Table檔重複執行匯入點選確認後,就完成我們轉檔作業了。











2019年12月9日 星期一

RESTfulServer安裝設定

                                RESTfulServer安裝設定

  • FHIR_RESTfulAPI功能介紹
  • RESTfulServer_HapiFHIR安裝與設定

    • Oracle JDK8 Install
    • Apache Maven 3.6.3 Install
    • IntelliJ IDEA Install (下載專案)
    • hapi-jpaserver start

RESTfulServer開發主要分成前端的Web App跟後端的Api Server,FB所開發的GraphQL能解決Restful Api資料結構過於分散的問題,後續會開篇章節來詳盡介紹GraphQL指令語法,運用Client API從RESTfulServer下載資料。
  • Restful Api是由三種元件組成的,Nouns、Verb和Content-Types。
    1. Nouns 名詞:用來定義Api接口的網址 URL,每一個Nouns代表著一個Data資源,每一個資源僅有一個唯一的識別位置,例如查詢patirnt的Data,那麼api接口的URL可以會為https://server/path/Patient。
    2. Verbs 動詞:描述了對 Nouns 名詞 (資源 URL) 的操作動作,在 HTTP 1.1 的實作當然就是 HTTP Method。所以對Data的操作動作就是用HTTP的Method,例如Get、Post、Put、Patch、Delete。Web Server必須使用HTTP Method來與Client互動,例如展示某個Nouns名詞內的資料用Get,新增資料時用Post,修改用Put或Patch,刪除則用Delete。
    3. Content Types 資源呈現方式:比如取得某一個 URL 文章的 HTML 格式,常見的格式有JSON、XML、YAML等等,比較常用的是輕量JSON,可以傳送互動式網頁所需的資料,很適合HTTP的傳輸, URL 資源可以由不同型態方式表現。通常Web Server接受的HTTP Response後會透過HTTP Header中的content-type去查看response的資料格式,並呼叫對應的function去解析資料內容,這個動作稱作序列化(Serialization),將一般的檔案格式轉化成,程式語言可以使用的資料結構,例如Array或Hash。
  • 適用FHIR的兩種RESTfulServer介紹


    連結網址https://test.fhir.org/


     連結網址 http://fhirtest.uhn.ca/home


Oracle JDK 8 on Ubuntu Install 

Step1:Download the latest JDK(jdk-8u231-linux-x64.tar.gz) from this official site


Step2:Open the terminal (Ctrl + Alt + T)
sudo mkdir /usr/lib/jvm

Step3:Enter the following command to change the directory.

cd /usr/lib/jvm

Step4:Extract the jdk-8u231-linux-x64.tar.gz file in that directory using this command

sudo tar -xvzf ~/Downloads/jdk-8u231-linux-x64.tar.gz

Step5:Enter the following command to open the environment variables file.

sudo gedit /etc/environment
Step6:In the opened file, add the following bin folders to the existing PATH variable.


/usr/lib/jvm/jdk1.8.0_231/bin
/usr/lib/jvm/jdk1.8.0_231/db/bin
/usr/lib/jvm/jdk1.8.0_231/jre/bin
Notice that the installed JDK version is 1.8 update 231. Depending on your JDK version, the paths can be different.


Add the following environment variables at the end of the file.
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_231/bin:/usr/lib/jvm/jdk1.8.0_231/db/bin:/usr/lib/jvm/jdk1.8.0_231/jre/bin"
J2SDKDIR="/usr/lib/jvm/jdk1.8.0_231"
J2REDIR="/usr/lib/jvm/jdk1.8.0_231/jre"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_231"
DERBY_HOME="/usr/lib/jvm/jdk1.8.0_231/db"

Step7:

Enter the following commands to inform the system about the Java's location. Depending on your JDK version, the paths can be different.


sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_231/bin/java" 0



sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_231/bin/javac" 0



sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_231/bin/java



sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_231/bin/javac

Step8:

To verify the setup enter the following commands and make sure that they print the location of java and javac as you have provided in the previous step.



update-alternatives --list java



update-alternatives --list javac




Step9:
Restart the computer (or just log-out and login) and open the terminal again.
Enter the following command.


java -version

JAVA_HOME環境變數設定

export PATH=$PATH:/usr/lib/jvm/jdk1.8.0_231/bin:/usr/lib/jvm/jdk1.8.0_231/db/bin:/usr/lib/jvm/jdk1.8.0_231/jr

export J2SDKDIR=/usr/lib/jvm/jdk1.8.0_231
export J2REDIR=/usr/lib/jvm/jdk1.8.0_231/jre
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_231



Apache Maven 3.6.3 Install


    Step1: Download Apache Maven 3.6.3 


   
  Step2: 
     1) Unix-based Operating Systems (Linux, Solaris and Mac OS X)
          root#tar zxvf apache-maven-3.0.x.tar.gz
     2) Make sure JAVA_HOME is set to the location of your JDK
     3) Run "mvn --version" to verify that it is correctly installed.

   
  Step3:建立的專案產生target資料夾,並編譯class使專案處於“已編譯”狀態。

    maven定義的生命週期中主要的相位如下:
    1).validate: 驗證專案及相關資訊是否可用。
    2).compile: class程式碼編譯。
    3).test: 進行單元測試。
    4).package: 根據事先指定的格式(比如jar),進行打包。
    5).integration-test: 部署到執行環境中,準備整合測試。
    6).verify: 進行有效性性和質量檢查。
    7).install: 安裝到原生代碼庫。
    8).deploy: 在整合或釋出環境,將包釋出到遠端程式碼庫。

   在“預設”的生命週期之外,還有兩個“階段”,但已完成單元測試後均不會使用:
    1).clean: 清除以前的構建物。
    2).site: 生成專案文件。


我們先從使用HAPI的JPA服務器模塊的範例項目開始安裝測試。

Step1:在GitHub找到hapi-fhir-jpaserver-starter下載後解壓縮。
Step2:進入該資料夾後輸入以下安裝指令(記住資料夾必須為chomd 777可讀寫執行)
$ cd hapi-fhir-jpaserver-example
$ mvn install

Step3:接著在執行啟動Maven伺服服務
$ mvn jetty:run

Step4:通過將瀏覽器指向以下URL來訪問服務器 http://localhost:8080/hapi-fhir-jpaserver/






2019年12月1日 星期日

JavaScript基本知識-比較排序

JavaScript-The Compare Function

比較函數應根據參數返回負,零或正值:

function(a, b){return a - b}
當該sort()函數比較兩個值時,它將這些值發送到compare函數,並根據返回的值(負,零,正)對值進行排序。如果結果是否定的正值,a排序b之前 如果結果為肯定負值,b則排序在a之前如果結果為0,則不會更改兩個值的排序順序。

例:
比較函數比較數組中的所有值,一次比較兩個值(a, b)
比較40和100時,該sort()方法將調用compare函數(40,100)。
該函數計算40-100 (a - b),並且由於結果為負數(-60),因此sort函數會將40排序為小於100的值。
您可以使用以下代碼片段進行數字和字母排序實驗:


<button onclick="myFunction1()">Sort Alphabetically</button>
<button onclick="myFunction2()">Sort Numerically</button>

<p id="demo"></p>


<script>
var points = [40100152510];
document.getElementById("demo").innerHTML = points;

function myFunction1() {
  points.sort();
  document.getElementById("demo").innerHTML = points;
}

function myFunction2() {
  points.sort(function(a, b){return a - b});
  document.getElementById("demo").innerHTML = points;
}
</script>



最小/最大JavaScript方法


Example (Find Max)

function myArrayMax(arr) {
  var len = arr.length;
  var max = -Infinity;
  while (len--) {
    if (arr[len] > max) {
      max = arr[len];
    }
  }
  return max;
}
Example (Find Min)
function myArrayMin(arr) {
  var len = arr.length;
  var min = Infinity;
  while (len--) {
    if (arr[len] < min) {
      min = arr[len];
    }
  }
  return min;
}

排序對像數組


例子
var cars = [
  {type:"Volvo", year:2016},
  {type:"Saab", year:2001},
  {type:"BMW", year:2010}
];


cars.sort(function(a, b){return a.year - b.year});
即使對象具有不同數據類型的屬性,sort()也可以使用方法對數組進行排序。
解決方案是編寫一個compare函數來比較屬性值:
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array Sort</h2>

<p>Click the buttons to sort car objects on age.</p>

<button onclick="myFunction()">Sort</button>

<p id="demo"></p>

<script>
var cars = [
  {type:"Volvo", year:2016},
  {type:"Saab", year:2001},
  {type:"BMW", year:2010}
];

displayCars();

function myFunction() {
  cars.sort(function(a, b){return a.year - b.year});
  displayCars();
}

function displayCars() {
  document.getElementById("demo").innerHTML =
  cars[0].type + " " + cars[0].year + "<br>" +
  cars[1].type + " " + cars[1].year + "<br>" +
  cars[2].type + " " + cars[2].year;
}
</script>
</body>

</html>


比較排序字符串屬性例子:
cars.sort(function(a, b){
  var x = a.type.toLowerCase();
  var y = b.type.toLowerCase();
  if (x < y) {return -1;}
  if (x > y) {return 1;}
  return 0;
});
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Array Sort</h2>
<p>Click the buttons to sort car objects on type.</p>
<button onclick="myFunction()">Sort</button>
<p id="demo"></p>
<script>
var cars = [
  {type:"Volvo", year:2016},
  {type:"Saab", year:2001},
  {type:"BMW", year:2010}
];
displayCars();
function myFunction() {
  cars.sort(function(a, b){
    var x = a.type.toLowerCase();
    var y = b.type.toLowerCase();
    if (x < y) {return -1;}
    if (x > y) {return 1;}
    return 0;
  });
  displayCars();
}
function displayCars() {
  document.getElementById("demo").innerHTML =
  cars[0].type + " " + cars[0].year + "<br>" +
  cars[1].type + " " + cars[1].year + "<br>" +
  cars[2].type + " " + cars[2].year;
}
</script>
</body>
</html>

ACCESS資料成功轉換SQlite方法

最近忙於系統開發研究,今日來談一下有朋友很有才華自行利用ACCESS開發了CRM(客戶關係管理)系統,但僅限於個人使用考量目前大量使用者成長與需求,洽詢我是否能技術支援同時給了我ACCESS檔案參考,但因電腦OFFICE沒有ACCESS可開啟.accdb檔案,相信有許多微軟OFF...