Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default value caused data missing #609

Closed
elvizlai opened this issue Nov 19, 2015 · 6 comments
Closed

default value caused data missing #609

elvizlai opened this issue Nov 19, 2015 · 6 comments

Comments

@elvizlai
Copy link
Contributor

sorry,the title should be default value caused data missing

1、using goleveldb
2、a column name Pv defined as ``pv BIGINT(20) NULL DEFAULT 1
3、it insert succeed
4、restart db,all data inserted are missing

@ngaut
Copy link
Member

ngaut commented Nov 19, 2015

Thanks for your report, @elvizlai
Any more details ?

@elvizlai
Copy link
Contributor Author

@ngaut sorry, i mis-touched my ''Enter" key.

testing code:

package main
import (
    _ "github.com/pingcap/tidb"
    _ "github.com/go-xorm/tidb"
    "github.com/go-xorm/xorm"
    "fmt"
)

type A struct {
    Id   int
    Name string
    Pv   int `xorm:"default 1"`
}

type B struct {
    Id   int
    Name string
    Pv   int64 `xorm:"default 1"`
}

func main() {
    engine, err := xorm.NewEngine("tidb", "goleveldb://test/tidb")
    if err != nil {
        panic(err)
    }
    //create table
    engine.Sync2(new(A),new(B))

    //query data
    fmt.Println("-------begin query------")
    //should be 0 if the first run---but every time you run the code, it all 0 or 1(very strange)
    fmt.Println(engine.Count(new(A)))
    fmt.Println(engine.Count(new(B)))
    //adding data

    fmt.Println("-------adding data------")
    a := &A{Name:"ElvizLai"}
    b := &B{Name:"ElvizLai"}
    fmt.Println(engine.InsertOne(a))
    fmt.Println(engine.InsertOne(b))
}

@disksing disksing changed the title default value caused default value caused data missing Nov 19, 2015
@ngaut
Copy link
Member

ngaut commented Nov 19, 2015

Have you commit your transaction ?

@elvizlai
Copy link
Contributor Author

@ngaut @disksing am i missed something?

reading tidb log and found out engine.InsertOne can only autocommit when db created. It will not autocommit when the table already exist. Should use session to commit instead. It is not a TiDB bug, so I'll close this iuuse.

@shenli
Copy link
Member

shenli commented Nov 19, 2015

@elvizlai I tested your code with and then check the db with interpreter tool(mv data dir to interpreter dir and start interpreter).
The data is ready in the db.
tidb> select * from a;
+----+----------+----+
| id | name | pv |
+----+----------+----+
| 0 | ElvizLai | 0 |
+----+----------+----+
1 row in set (0.00 sec)
tidb> select * from b;
+----+----------+----+
| id | name | pv |
+----+----------+----+
| 0 | ElvizLai | 0 |
+----+----------+----+
1 row in set (0.00 sec)

@elvizlai
Copy link
Contributor Author

@shenli you are right. It seems that engine.InsertOne autocommit not work when db already exist.(U can run that code twice, but only one line data inserted). I tried using session to commit, and it succeed. I not very sure what caused this issue.

nayuta-yanagisawa added a commit to nayuta-yanagisawa/tidb that referenced this issue Feb 21, 2021
…ngcap#609)

TiDB ignores the TEMPORARY keyword in "CREATE/DROP TEMPORARY TABLE" statements.
Report errors when and only when tidb_enable_noop_functions = OFF.
morgo added a commit that referenced this issue Feb 28, 2021
…) (#22860)

* planner: include "CREATE/DROP TEMPORARY TABLE" to noop functions (##609)

TiDB ignores the TEMPORARY keyword in "CREATE/DROP TEMPORARY TABLE" statements.
Report errors when and only when tidb_enable_noop_functions = OFF.

* Add link to pingcap/parser issue

Co-authored-by: bb7133 <[email protected]>

Co-authored-by: bb7133 <[email protected]>
Co-authored-by: Morgan Tocker <[email protected]>
rleungx pushed a commit to rleungx/tidb that referenced this issue Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants