วันพุธที่ 22 มิถุนายน พ.ศ. 2554

VBA-Ms Access Create_Batfile


Function Create_Batfile()
Set fs = CreateObject("Scripting.FileSystemObject")
'Set a = fs.CreateTextFile("C:\Zr506\update.sql", True)
'a.writeline ("UPDATE  configuration SET last_date ='" & EngDate(Last_Date) & "';")
'a.Close
txtServer = "localhost"

Set a2 = fs.CreateTextFile("C:\Zr506\update.bat", True)
Set rsz = CurrentDb.OpenRecordset("SELECT * FROM disease ")
Do While Not rsz.EOF
codedz = rsz.Fields("codedz")
    a2.writeline ("" & Postgres_Path & "psql -d " & Postgres_DB & " -f C:\Zr506\sick_r506_" & codedz & ".sql  -U postgres  -h  " & txtServer & "")
    a2.writeline ("" & Postgres_Path & "psql -d " & Postgres_DB & " -f C:\Zr506\death_r506_" & codedz & ".sql  -U postgres  -h  " & txtServer & "")
   
rsz.MoveNext
Loop


a2.writeline ("" & Postgres_Path & "psql -d " & Postgres_DB & " -f C:\Zr506\update.sql -U postgres  -h  " & txtServer & "")
a2.Close
stAppName = "C:\Zr506\update.bat"  '¤Ø³µéͧà»ÅÕè¹ Drive áÅÐ Path ¤ÃѺ
Call Shell(stAppName, 3)
End Function

วันพุธที่ 8 มิถุนายน พ.ศ. 2554

VBA-Ms Access Import_Epe0

Function Import_Epe0(db_file)
If TableExists("EPE0") Then
    CurrentDb.TableDefs.Delete ("EPE0")
End If

DoCmd.TransferDatabase acImport, "Microsoft Access", "" & db_file & "", acTable, "epe0", "epe0", False
End Function

วันจันทร์ที่ 21 กุมภาพันธ์ พ.ศ. 2554

แปลงฐานข้อมูลจาก tis620 ให้เป็น utf8

1. dump ข้อมูลออกมาเป็น tis620 ตามปรกติ
mysqldump -uroot -p --default-character-set=tis620 --all-databases > full.sql

2. เปิดไฟล์ full.sql ค้นหา แทนที่ tis620 ด้วย utf8

3. อ่านไฟล์ full.sql ดู ด้านบนจะมีคำว่า SET NAMES utf8
ให้เปลี่ยนเป็น SET NAMES tis620
ซึ่งไฟล์ที่ได้จะเป็นประมาณนี้

SET NAMES tis620;
CREATE TABLE xxx (
  ...
) CHARSET=utf8

4. ไฟล์ full.sql นี้ ไม่ต้องเปลี่ยน encoding ให้ ANSI หรือ ASCII ต่อไป
5. ถ้าไฟล์มีขนาดใหญ่ คงหาโปรแกรมมาเปิดยากหน่อย
ถ้ามี linux ให้ไปแก้ที่ linux โดยใช้โปรแกรม vi ซึ่งสามารถเปิดไฟล์ใหญ่ ๆ ได้สบาย ๆ

6. คำสั่งค้นหาแทนที่ใน vi คือ
:1,$s/ttis620/utf8/g