ms_access

package module
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2025 License: MIT Imports: 6 Imported by: 1

README

ms_access

This repo provides a command line tool to run common SQL commands to an MS Access (R) database via an ODBC connection. But it also contains a library to do the same.

It should run on Windows, Linux and Unix.

Usage

Install the tool with

git clone gitlab.com/golang-utils/ms_access
cd cmd/ms_access
go install .

Set the help with:

ms_access help

Here is an example, how to use the library:

get it with

go get gitlab.com/golang-utils/ms_access@latest

Then

package main

import (
  "os"
  "fmt"
  "database/sql"
  "gitlab.com/golang-utils/ms_access"
)

func main() {
  err := run()
  if err != nil {
    fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
    os.Exit(1)
  }

  os.Exit(0)
}

func run() error {
  mydns := "foo"
  mypasswd := "bar"

  conn := ms_access.NewConnection(mydns, mypasswd)
  err := conn.Open()
  if err != nil {
    return fmt.Errorf("could not open ODBC connection %q: %v", dns, err)
	}
	
  defer conn.Close()
  
	row := db.QueryRow("select 1 + 4;")
  var val int
  err = row.Scan(&val)
  if err != nil {
    return err
  }

  fmt.Printf("1 + 4 = %v\n", val)
  return nil
}

Documentation

see https://pkg.go.dev/gitlab.com/golang-utils/ms_access

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddField

func AddField(table string, f Field) string

func AlterField

func AlterField(table string, f Field) string

func CreateTable

func CreateTable(name string, fields ...Field) string

CreateTable creates a table

func DeleteRow

func DeleteRow(table string, where map[Field]any) string

DeleteRow deletes a row

func DropField

func DropField(table, field string) string

func DropTable

func DropTable(name string) string

DropTable removes a table

func InsertRow

func InsertRow(table string, values map[Field]any) string

InsertRow inserts a row

func InsertRows

func InsertRows(table string, fields []Field, rows [][]any) (string, error)

InsertRows inserts several rows, the order and length of the fields and each row must match

func QuoteString

func QuoteString(s string) (sql string)

func UpdateRow

func UpdateRow(table string, values map[Field]any, where map[Field]any) string

UpdateRow updates a row

Types

type Connection

type Connection struct {
	DSN                    string
	PW                     string
	UID                    string
	DontMaintainConnection bool
}

func NewConnection

func NewConnection(dsn, passwd string) *Connection

NewConnection creates a new ODBC connection

func (*Connection) Open

func (m *Connection) Open() (*sql.DB, error)

Open opens the odbc connection

type Field

type Field struct {
	Name string
	Type Type
	Null bool
	Size [2]int
}

func (Field) Sql

func (f Field) Sql() string

type Type

type Type string
var (
	Type_COUNTER  Type = "COUNTER"
	Type_BYTE     Type = "BYTE"
	Type_SMALLINT Type = "SMALLINT"
	Type_INTEGER  Type = "INTEGER"
	Type_REAL     Type = "REAL"
	Type_FLOAT    Type = "FLOAT"
	// Type_DECIMAL(18,5) FieldType = "DECIMAL(18,5)"
	Type_MONEY            Type = "MONEY"
	Type_VARCHAR          Type = "VARCHAR"
	Type_MEMO             Type = "MEMO"
	Type_DATETIME         Type = "DATETIME"
	Type_BIT              Type = "BIT"
	Type_IMAGE            Type = "IMAGE"
	Type_UNIQUEIDENTIFIER Type = "UNIQUEIDENTIFIER"
)

Directories

Path Synopsis
cmd
ms_access Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL