-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
�$BK\2H$K�(BRowsColumnTypeDatabaseTypeName�$B$r;H$($k%W%k%j%/$rE,MQ$7…
…$?�(B alexbrainman/odbc#171
- Loading branch information
TAOI Masao
committed
Mar 28, 2022
0 parents
commit 65e3ac9
Showing
33 changed files
with
4,611 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This source code refers to The Go Authors for copyright purposes. | ||
# The master list of authors is in the main Go distribution, | ||
# visible at http://tip.golang.org/AUTHORS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This is the official list of people who can contribute | ||
# (and typically have contributed) code to the Go repository. | ||
# The AUTHORS file lists the copyright holders; this file | ||
# lists people. For example, Google employees are listed here | ||
# but not in AUTHORS, because Google holds the copyright. | ||
# | ||
# The submission process automatically checks to make sure | ||
# that people submitting code are listed in this file (by email address). | ||
# | ||
# Names should be added to this file only after verifying that | ||
# the individual or the individual's organization has agreed to | ||
# the appropriate Contributor License Agreement, found here: | ||
# | ||
# http://code.google.com/legal/individual-cla-v1.0.html | ||
# http://code.google.com/legal/corporate-cla-v1.0.html | ||
# | ||
# The agreement for individuals can be filled out on the web. | ||
# | ||
# When adding J Random Contributor's name to this file, | ||
# either J's name or J's organization's name should be | ||
# added to the AUTHORS file, depending on whether the | ||
# individual or corporate CLA was used. | ||
|
||
# Names should be added to this file like so: | ||
# Name <email address> | ||
# | ||
# An entry with two email addresses specifies that the | ||
# first address should be used in the submit logs and | ||
# that the second address should be recognized as the | ||
# same person when interacting with Rietveld. | ||
|
||
# Please keep the list sorted. | ||
|
||
Alex Brainman <alex.brainman@gmail.com> | ||
Andrew Gerrand <adg@golang.org> | ||
Chris Hines <chris.cs.guy@gmail.com> <github@cs-guy.com> <chines@comscore.com> | ||
Luke Mauldin <lukemauldin@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2012 The Go Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
DB_NAME=test | ||
PASSWORD=Passw0rd | ||
|
||
help: | ||
echo "use start or stop target" | ||
|
||
# Microsoft SQL Server | ||
|
||
MSSQL_DB_FILES=/tmp/mssql_temp | ||
MSSQL_CONTAINER_NAME=mssql_test | ||
MSSQL_SA_PASSWORD=$(PASSWORD) | ||
|
||
start-mssql: | ||
docker run --name=$(MSSQL_CONTAINER_NAME) -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=$(MSSQL_SA_PASSWORD)' -e 'MSSQL_PID=Developer' --cap-add SYS_PTRACE -v $(MSSQL_DB_FILES):/var/opt/mssql -d -p 1433:1433 microsoft/mssql-server-linux | ||
echo -n "starting $(MSSQL_CONTAINER_NAME) "; while ! docker logs $(MSSQL_CONTAINER_NAME) 2>&1 | grep SQL.Server.is.now.ready.for.client.connections >/dev/null ; do echo -n .; sleep 1; done; echo " done" | ||
docker exec $(MSSQL_CONTAINER_NAME) /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '$(MSSQL_SA_PASSWORD)' -Q 'create database $(DB_NAME)' | ||
|
||
test-mssql: | ||
go test -v -mssrv=localhost -msdb=$(DB_NAME) -msuser=sa -mspass=$(MSSQL_SA_PASSWORD) -run=TestMSSQL | ||
|
||
test-mssql-race: | ||
go test -v -mssrv=localhost -msdb=$(DB_NAME) -msuser=sa -mspass=$(MSSQL_SA_PASSWORD) -run=TestMSSQL --race | ||
|
||
stop-mssql: | ||
docker stop $(MSSQL_CONTAINER_NAME) | ||
docker rm $(MSSQL_CONTAINER_NAME) | ||
|
||
# MySQL | ||
|
||
MYSQL_CONTAINER_NAME=mysql_test | ||
MYSQL_ROOT_PASSWORD=$(PASSWORD) | ||
|
||
start-mysql: | ||
docker run --name=$(MYSQL_CONTAINER_NAME) -e 'MYSQL_ROOT_PASSWORD=$(MYSQL_ROOT_PASSWORD)' -d -p 127.0.0.1:3306:3306 mysql | ||
echo -n "starting $(MYSQL_CONTAINER_NAME) "; while ! docker logs $(MYSQL_CONTAINER_NAME) 2>&1 | grep ^Version.*port:.3306 >/dev/null ; do echo -n .; sleep 1; done; echo " done" | ||
docker exec $(MYSQL_CONTAINER_NAME) sh -c 'echo "create database $(DB_NAME)" | MYSQL_PWD=$(MYSQL_ROOT_PASSWORD) mysql -hlocalhost -uroot' | ||
|
||
test-mysql: | ||
go test -v -mydb=$(DB_NAME) -mypass=$(MYSQL_ROOT_PASSWORD) -mysrv=127.0.0.1 -myuser=root -run=MYSQL | ||
|
||
stop-mysql: | ||
docker stop $(MYSQL_CONTAINER_NAME) | ||
docker rm $(MYSQL_CONTAINER_NAME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
odbc driver written in go. Implements database driver interface as used by standard database/sql package. It calls into odbc dll on Windows, and uses cgo (unixODBC) everywhere else. | ||
|
||
To get started using odbc, have a look at the [wiki](../../wiki) pages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2018 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package odbc | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
ole "github.com/go-ole/go-ole" | ||
"github.com/go-ole/go-ole/oleutil" | ||
) | ||
|
||
func TestAccessMemo(t *testing.T) { | ||
tmpdir, err := ioutil.TempDir("", "TestAccessMemo") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpdir) | ||
|
||
dbfilename := filepath.Join(tmpdir, "db.mdb") | ||
createAccessDB(t, dbfilename) | ||
|
||
db, err := sql.Open("odbc", fmt.Sprintf("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=%s;", dbfilename)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer db.Close() | ||
|
||
err = db.Ping() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, err = db.Exec("create table mytable (m memo)") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for s := ""; len(s) < 1000; s += "0123456789" { | ||
_, err = db.Exec("insert into mytable (m) values (?)", s) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func createAccessDB(t *testing.T, dbfilename string) { | ||
err := ole.CoInitialize(0) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer ole.CoUninitialize() | ||
|
||
unk, err := oleutil.CreateObject("adox.catalog") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
cat, err := unk.QueryInterface(ole.IID_IDispatch) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_, err = oleutil.CallMethod(cat, "create", fmt.Sprintf("provider=microsoft.jet.oledb.4.0;data source=%s;", dbfilename)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2012 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package api | ||
|
||
//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zapi_windows.go api.go | ||
|
||
//go:generate sh -c "./mksyscall_unix.pl api.go | gofmt > zapi_unix.go" | ||
|
||
import ( | ||
"unicode/utf16" | ||
) | ||
|
||
type ( | ||
SQL_DATE_STRUCT struct { | ||
Year SQLSMALLINT | ||
Month SQLUSMALLINT | ||
Day SQLUSMALLINT | ||
} | ||
|
||
SQL_TIME_STRUCT struct { | ||
Hour SQLUSMALLINT | ||
Minute SQLUSMALLINT | ||
Second SQLUSMALLINT | ||
} | ||
|
||
SQL_SS_TIME2_STRUCT struct { | ||
Hour SQLUSMALLINT | ||
Minute SQLUSMALLINT | ||
Second SQLUSMALLINT | ||
Fraction SQLUINTEGER | ||
} | ||
|
||
SQL_TIMESTAMP_STRUCT struct { | ||
Year SQLSMALLINT | ||
Month SQLUSMALLINT | ||
Day SQLUSMALLINT | ||
Hour SQLUSMALLINT | ||
Minute SQLUSMALLINT | ||
Second SQLUSMALLINT | ||
Fraction SQLUINTEGER | ||
} | ||
) | ||
|
||
//sys SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (ret SQLRETURN) = odbc32.SQLAllocHandle | ||
//sys SQLBindCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) = odbc32.SQLBindCol | ||
//sys SQLBindParameter(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, inputOutputType SQLSMALLINT, valueType SQLSMALLINT, parameterType SQLSMALLINT, columnSize SQLULEN, decimalDigits SQLSMALLINT, parameterValue SQLPOINTER, bufferLength SQLLEN, ind *SQLLEN) (ret SQLRETURN) = odbc32.SQLBindParameter | ||
//sys SQLCloseCursor(statementHandle SQLHSTMT) (ret SQLRETURN) = odbc32.SQLCloseCursor | ||
//sys SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLWCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLDescribeColW | ||
//sys SQLDescribeParam(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, dataTypePtr *SQLSMALLINT, parameterSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLDescribeParam | ||
//sys SQLDisconnect(connectionHandle SQLHDBC) (ret SQLRETURN) = odbc32.SQLDisconnect | ||
//sys SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLWCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLWCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) = odbc32.SQLDriverConnectW | ||
//sys SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLEndTran | ||
//sys SQLExecute(statementHandle SQLHSTMT) (ret SQLRETURN) = odbc32.SQLExecute | ||
//sys SQLFetch(statementHandle SQLHSTMT) (ret SQLRETURN) = odbc32.SQLFetch | ||
//sys SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) (ret SQLRETURN) = odbc32.SQLFreeHandle | ||
//sys SQLGetData(statementHandle SQLHSTMT, colOrParamNum SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) = odbc32.SQLGetData | ||
//sys SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLWCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLWCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLGetDiagRecW | ||
//sys SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLNumParams | ||
//sys SQLMoreResults(statementHandle SQLHSTMT) (ret SQLRETURN) = odbc32.SQLMoreResults | ||
//sys SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLNumResultCols | ||
//sys SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) = odbc32.SQLPrepareW | ||
//sys SQLRowCount(statementHandle SQLHSTMT, rowCountPtr *SQLLEN) (ret SQLRETURN) = odbc32.SQLRowCount | ||
//sys SQLSetEnvAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) = odbc32.SQLSetEnvAttr | ||
//sys SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) = odbc32.SQLSetConnectAttrW | ||
|
||
// UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s, | ||
// with a terminating NUL removed. | ||
func UTF16ToString(s []uint16) string { | ||
for i, v := range s { | ||
if v == 0 { | ||
s = s[0:i] | ||
break | ||
} | ||
} | ||
return string(utf16.Decode(s)) | ||
} | ||
|
||
// StringToUTF16 returns the UTF-16 encoding of the UTF-8 string s, | ||
// with a terminating NUL added. | ||
func StringToUTF16(s string) []uint16 { return utf16.Encode([]rune(s + "\x00")) } | ||
|
||
// StringToUTF16Ptr returns pointer to the UTF-16 encoding of | ||
// the UTF-8 string s, with a terminating NUL added. | ||
func StringToUTF16Ptr(s string) *uint16 { return &StringToUTF16(s)[0] } |
Oops, something went wrong.