Code Monkey home page Code Monkey logo

Comments (3)

shueybubbles avatar shueybubbles commented on May 16, 2024

We have a sqlcmd script execution package at https://github.com/microsoft/go-sqlcmd/pkg/sqlcmd that might be appropriate. If you provide the sqlcmd instance with your own implementation of Formatter you'll get access to the driver data.

from go-mssqldb.

comsma avatar comsma commented on May 16, 2024

would I replace the go-mssql import? This is how i'm currently using the package

package main

import (
	"database/sql"
	"fmt"
	_ "github.com/microsoft/go-mssqldb"
	"math"
	"os"
)

var db *sql.DB

func main() {

	files, _ := os.ReadDir(".")

	openDb("sqlserver://xxx")

	batches := len(files) / 500
	batches = int(math.Round(float64(batches)))
	fmt.Println(batches)

	for batch := 0; batch < batches; batch++ {
		sendScriptsAsQuery(files[(batch*500)+0 : (batch*500)+500])
	}

	sendScriptsAsQuery(files[2000:2500])
	defer db.Close()

}

func openDb(connectionUrl string) {
	var err error
	db, err = sql.Open("mssql", connectionUrl)
	if err != nil {
		fmt.Println("Cannot connect: ", err.Error())
		return
	}
	err = db.Ping()
	if err != nil {
		fmt.Println("Cannot connect: ", err.Error())
		return
	}
}

func sendScriptsAsQuery(scripts []os.DirEntry) {

	for s := 0; s < len(scripts); s++ {
		data, _ := os.ReadFile(scripts[s].Name())

		_, errs := db.Exec(string(data[:]))
		if errs != nil {
			fmt.Printf("%s \n", errs)
		}
	}

}

from go-mssqldb.

shueybubbles avatar shueybubbles commented on May 16, 2024

if you are trying to run the scripts without examining the output, you could just run sqlcmd in the shell instead of writing your own app to do it. We have releases for most platforms.
Otherwise you would use import the github.com/microsoft/go-sqlcmd/pkg/sqlcmd package and use the IncludeFile method.

Like this test: https://github.com/microsoft/go-sqlcmd/blob/9b59da694f9cbdf87acf70589e4c680589917f1a/pkg/sqlcmd/sqlcmd_test.go#L145

from go-mssqldb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.