// mainSQL is the main entry point for sql command.
321576
func mainSQL(ctx *cli.Context) error {
	var (
		csvHdrs []string
		selOpts SelectObjectOpts
		query   string
	)
	// Parse encryption keys per command.
	encKeyDB, err := getEncKeys(ctx)
	fatalIf(err, "Unable to parse encryption keys.")

	// validate sql input arguments.
	checkSQLSyntax(ctx)
	// extract URLs.
	URLs := ctx.Args()
	writeHdr := true
	for _, url := range URLs {
		if !isAliasURLDir(url, encKeyDB) {
			if writeHdr {
				query, csvHdrs, selOpts = getAndValidateArgs(ctx, encKeyDB, url)
			}
			errorIf(sqlSelect(url, query, encKeyDB, selOpts, csvHdrs, writeHdr).Trace(url), "Unable to run sql")
			writeHdr = false
			continue
		}
		targetAlias, targetURL, _ := mustExpandAlias(url)
		clnt, err := newClientFromAlias(targetAlias, targetURL)
		if err != nil {
			errorIf(err.Trace(url), "Unable to initialize target `"+url+"`.")
			continue
		}

		for content := range clnt.List(ctx.Bool("recursive"), false, DirNone) {
			if content.Err != nil {
				errorIf(content.Err.Trace(url), "Unable to list on target `"+url+"`.")
				continue
			}
			if writeHdr {
				query, csvHdrs, selOpts = getAndValidateArgs(ctx, encKeyDB, targetAlias+content.URL.Path)
			}
			contentType := mimedb.TypeByExtension(filepath.Ext(content.URL.Path))
			for _, cTypeSuffix := range supportedContentTypes {
				if strings.Contains(contentType, cTypeSuffix) {
					errorIf(sqlSelect(targetAlias+content.URL.Path, query,
						encKeyDB, selOpts, csvHdrs, writeHdr).Trace(content.URL.String()), "Unable to run sql")
				}
				writeHdr = false
			}
		}
	}

	// Done.
	return nil
}
1316951
func SplitSQL(sql string) []string {
	parts := strings.Split(sql, ";")
	out := make([]string, 0, len(parts))
	for _, p := range parts {
		clean := strings.TrimSpace(p)
		if len(clean) > 0 {
			out = append(out, clean)
		}
	}
	return out
}
1074068
func SanitizeSQL(sql string, args ...interface{}) (string, error) {
	query, err := NewQuery(sql)
	if err != nil {
		return "", err
	}
	return query.Sanitize(args...)
}
140602
func main() {
	serverID := "abc123"
	var version string
	err := retro.DoWithRetry(func() error {
		var e error
		version, e = getServer(serverID)
		if e != nil {
			return e
		}
		fmt.Printf("Server version %s\n", version)
		return nil
	})
	if err != nil {
		fmt.Printf("FATAL: Failed to get server info %s\n", err.Error())
		os.Exit(1)
	}

	err = retro.DoWithRetry(func() error {
		return useServer(serverID, version)
	})
	if err != nil {
		fmt.Printf("FATAL: Failed to use server %s\n", err.Error())
		os.Exit(1)
	}

}
286170
func (db DB) SQL() SqlStmts {
	driver := db.DriverName()

	if h, ok := helpers[driver]; ok {
		return h.SQL()
	} else {
		panic("No helper registered for " + driver)
	}
}
831996
func main() {

	// init a connection
	s, err := solr.Init("localhost", 8983, "collection-name")

	if err != nil {
		fmt.Println(err)
		return
	}

	// define a solr query string
	q := "q=*:*"

	// perform a query    
	res, err := s.SelectRaw(q)

	if err != nil {
		fmt.Println(err)
		return
	}

	// grab results for ease of use later on
	results := res.Results

	// print a summary and loop over results, priting the "title" and "latlng" fields
	fmt.Println(
		fmt.Sprintf("Query: %#v\nHits: %d\nNum Results: %d\nQtime: %d\nStatus: %d\n\nResults\n-------\n",
			q,
			results.NumFound,
			results.Len(),
			res.QTime,
			res.Status))

	for i := 0; i < results.Len(); i++ {
		fmt.Println("Some field:", results.Get(i).Field("id"))
		fmt.Println("Some other field:", results.Get(i).Field("title"))

		fmt.Println("")
	}

}
893235
func (l *NSQLookupd) Main() error {
	ctx := &Context{l}

	exitCh := make(chan error)
	var once sync.Once
	exitFunc := func(err error) {
		once.Do(func() {
			if err != nil {
				l.logf(LOG_FATAL, "%s", err)
			}
			exitCh <- err
		})
	}

	tcpServer := &tcpServer{ctx: ctx}
	l.waitGroup.Wrap(func() {
		exitFunc(protocol.TCPServer(l.tcpListener, tcpServer, l.logf))
	})
	httpServer := newHTTPServer(ctx)
	l.waitGroup.Wrap(func() {
		exitFunc(http_api.Serve(l.httpListener, httpServer, "HTTP", l.logf))
	})

	err := <-exitCh
	return err
}
603314
func (session *Session) Sql(query string, args ...interface{}) *Session {
	return session.SQL(query, args...)
}
799982
func (j *Jujuc) Main(req Request, resp *exec.ExecResponse) error {
	if req.CommandName == "" {
		return badReqErrorf("command not specified")
	}
	if !filepath.IsAbs(req.Dir) {
		return badReqErrorf("Dir is not absolute")
	}
	c, err := j.getCmd(req.ContextId, req.CommandName)
	if err != nil {
		return badReqErrorf("%s", err)
	}
	var stdin io.Reader
	if req.StdinSet {
		stdin = bytes.NewReader(req.Stdin)
	} else {
		// noStdinReader will error with ErrNoStdin
		// if its Read method is called.
		stdin = noStdinReader{}
	}
	var stdout, stderr bytes.Buffer
	ctx := &cmd.Context{
		Dir:    req.Dir,
		Stdin:  stdin,
		Stdout: &stdout,
		Stderr: &stderr,
	}
	j.mu.Lock()
	defer j.mu.Unlock()
	// Beware, reducing the log level of the following line will lead
	// to passwords leaking if passed as args.
	logger.Tracef("running hook tool %q %q", req.CommandName, req.Args)
	logger.Debugf("running hook tool %q", req.CommandName)
	logger.Tracef("hook context id %q; dir %q", req.ContextId, req.Dir)
	wrapper := &cmdWrapper{c, nil}
	resp.Code = cmd.Main(wrapper, ctx, req.Args)
	if errors.Cause(wrapper.err) == ErrNoStdin {
		return ErrNoStdin
	}
	resp.Stdout = stdout.Bytes()
	resp.Stderr = stderr.Bytes()
	return nil
}
847278
func HandleWithSQL() (*SQLMapper, error) {
	sqlConf, sqlConfErr := GetSQLConf()
	if sqlConfErr == nil {
		s := &SQLMapper{conf: sqlConf}

		db, err := sql.Open(s.conf.driver, s.conf.openStr)
		if err != nil {
			panic(err)
		}

		s.sqlConn = db
		return s, err
	}

	return nil, sqlConfErr
}
728278
func main() {
	driver := cli.New(flag.ContinueOnError)

	rootCmd := &cmd.Root{
		Help: `Usage: ryu COMMAND [args]

A madeup CLI to demonstrate this framework.

Ryu is a character from Street Fighter II`,
		SubCommandList: []cli.Command{

			&PunchCmd{},

			// A simple command so you don't have to implement all the methods
			// of cli.Command
			&cmd.Default{
				NameStr:      "version",
				ShortHelpStr: "Print out a version string",
				ExecuteFunc: func(args []string) bool {
					fmt.Println("v0.0.1")

					// since this command doesn't take any arguments it doesn't
					// need a LongHelp() since we always return a successful
					// execution
					return true
				},
			},
		},
	}

	if err := driver.RegisterRoot(rootCmd); err != nil {
		panic(err)
	}

	if err := driver.ParseInput(); err != nil {
		panic(err)
	}
}
151250
func (me *DefaultAdapter) CompoundsSql(buf *SqlBuilder, compounds []CompoundExpression) error {
	for _, compound := range compounds {
		if err := me.Literal(buf, compound); err != nil {
			return err
		}
	}
	return nil
}
1362639
func main() {
	Tables := []interface{}{
		&promotion.Discount{},
		&promotion.Rule{},
		&promotion.Benefit{},
		&promotion.Coupon{},
		&promotion.BenefitRecord{},
		&enterprise.QorMicroSite{},
	}

	TruncateTables(Tables...)
	createPromotion()
	createMicroSite()
}
90688
func ToSQL(cond interface{}) (string, []interface{}, error) {
	switch cond.(type) {
	case Cond:
		return condToSQL(cond.(Cond))
	case *Builder:
		return cond.(*Builder).ToSQL()
	}
	return "", nil, ErrNotSupportType
}
119649
func main() {
	// Init DB and plan to close it at the end of the programme
	dbconn.Connect()
	defer dbconn.DB.Close()

	// Set GIN in production mode if run in production
	if !config.GDevEnv {
		gin.SetMode(gin.ReleaseMode)
	}

	// Init router
	router := gin.Default()
	router.Use(cors.New(apitool.DefaultCORSConfig()))

	// User component
	userComponent := user.New(rest.New(service.New(repo.New())))
	userComponent.AttachPublicAPI(router.Group("/api/v1"))
	userComponent.AttachPrivateAPI(router.Group("/api/private-v1"))

	// Start router
	go log.Println("Service user started: Navigate to " + config.GAppUrl)
	router.Run(":" + config.GPort)
}
1034916
func (statement *Statement) SQL(query interface{}, args ...interface{}) *Statement {
	switch query.(type) {
	case (*builder.Builder):
		var err error
		statement.RawSQL, statement.RawParams, err = query.(*builder.Builder).ToSQL()
		if err != nil {
			statement.Engine.logger.Error(err)
		}
	case string:
		statement.RawSQL = query.(string)
		statement.RawParams = args
	default:
		statement.Engine.logger.Error("unsupported sql type")
	}

	return statement
}
1048704
func Main(params base.Parameters, args []string) int {
	// Enable not-yet-standard Starlark features.
	resolve.AllowLambda = true
	resolve.AllowNestedDef = true
	resolve.AllowFloat = true
	resolve.AllowSet = true

	// A hack to allow '#!/usr/bin/env lucicfg'. On Linux the shebang line can
	// have at most two arguments, so we can't use '#!/usr/bin/env lucicfg gen'.
	if len(args) == 1 {
		if _, err := os.Stat(args[0]); err == nil {
			args = []string{"generate", args[0]}
		}
	}

	return subcommands.Run(GetApplication(params), fixflagpos.FixSubcommands(args))
}