1// +build future
2
3/*
4Copyright 2014 SAP SE
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17*/
18
19package driver_test
20
21import (
22	"database/sql"
23	"log"
24
25	"github.com/SAP/go-hdb/driver"
26)
27
28// ExampleBulkInsert inserts 1000 integer values into database table test.
29// Precondition: the test database table with one field of type integer must exist.
30// The insert SQL command is "bulk insert" instead of "insert".
31// After the insertion of the values a final stmt.Exec() without parameters must be executed.
32func Example_bulkInsert() {
33	db, err := sql.Open(driver.DriverName, "hdb://user:password@host:port")
34	if err != nil {
35		log.Fatal(err)
36	}
37	defer db.Close()
38
39	stmt, err := db.Prepare("bulk insert into test values (?)") // Prepare bulk query.
40	if err != nil {
41		log.Fatal(err)
42	}
43	defer stmt.Close()
44
45	for i := 0; i < 1000; i++ {
46		if _, err := stmt.Exec(i); err != nil {
47			log.Fatal(err)
48		}
49	}
50	// Call final stmt.Exec().
51	if _, err := stmt.Exec(); err != nil {
52		log.Fatal(err)
53	}
54}
55