Add en/0.5.x.md syntax highlighting

This commit is contained in:
vCaesar
2017-05-14 16:03:27 +08:00
parent 76e5d0f3b4
commit dd127671ae
4 changed files with 69 additions and 68 deletions

View File

@@ -15,7 +15,7 @@ I will use the first one in the examples that follow.
## Samples
We create the following SQL:
```sql
CREATE TABLE userinfo
(
uid serial NOT NULL,
@@ -25,9 +25,9 @@ We create the following SQL:
CONSTRAINT userinfo_pkey PRIMARY KEY (uid)
)
WITH (OIDS=FALSE);
```
An example:
```Go
package main
import (
@@ -102,20 +102,20 @@ An example:
panic(err)
}
}
```
Note that PostgreSQL uses the `$1, $2` format instead of the `?` that MySQL uses, and it has a different DSN format in `sql.Open`.
Another thing is that the PostgreSQL driver does not support `sql.Result.LastInsertId()`.
So instead of this,
```Go
stmt, err := db.Prepare("INSERT INTO userinfo(username,departname,created) VALUES($1,$2,$3);")
res, err := stmt.Exec("astaxie", "研发部门", "2012-12-09")
fmt.Println(res.LastInsertId())
```
use `db.QueryRow()` and `.Scan()` to get the value for the last inserted id.
```Go
err = db.QueryRow("INSERT INTO TABLE_NAME values($1) returning uid;", VALUE1").Scan(&lastInsertId)
fmt.Println(lastInsertId)
```
## Links
- [Directory](preface.md)