nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: proullon/ramsql
Pull request #53 (2021-11-07 20:38:11)

fix: add altervative AUTO_INCREMENT lexeme
Support AUTO_INCREMENT as well as AUTOINCREMENT


Patch:
diff --git a/engine/parser/lexer.go b/engine/parser/lexer.go
index 3a9bbf9..1e52d38 100644
--- a/engine/parser/lexer.go
+++ b/engine/parser/lexer.go
@@ -374,6 +374,10 @@ func (l *lexer) MatchDeleteToken() bool {
 }
 
 func (l *lexer) MatchAutoincrementToken() bool {
+	if l.Match([]byte("auto_increment"), AutoincrementToken) {
+		return true
+	}
+
 	return l.Match([]byte("autoincrement"), AutoincrementToken)
 }
 


Test patch:
diff --git a/driver/autoincrement_test.go b/driver/autoincrement_test.go
index 2c30abe..427a9a7 100644
--- a/driver/autoincrement_test.go
+++ b/driver/autoincrement_test.go
@@ -49,3 +49,46 @@ func TestAutoIncrementSimple(t *testing.T) {
 		t.Fatalf("Last insterted id should be 2, not %d", lastID)
 	}
 }
+
+func TestAutoIncrementAlternativeSimple(t *testing.T) {
+	log.UseTestLogger(t)
+
+	db, err := sql.Open("ramsql", "TestAutoIncrementAlternativeSimple")
+	if err != nil {
+		t.Fatalf("sql.Open : Error : %s\n", err)
+	}
+	defer db.Close()
+
+	_, err = db.Exec("CREATE TABLE account (id INT AUTO_INCREMENT, email TEXT)")
+	if err != nil {
+		t.Fatalf("sql.Exec: Error: %s\n", err)
+	}
+
+	res, err := db.Exec("INSERT INTO account ('email') VALUES ('foo@bar.com')")
+	if err != nil {
+		t.Fatalf("Cannot insert into table account: %s", err)
+	}
+
+	lastID, err := res.LastInsertId()
+	if err != nil {
+		t.Fatalf("Cannot fetch last inserted id: %s\n", err)
+	}
+
+	if lastID != 1 {
+		t.Fatalf("Last insterted id should be 1, not %d", lastID)
+	}
+
+	res, err = db.Exec("INSERT INTO account ('email') VALUES ('roger@gmail.com')")
+	if err != nil {
+		t.Fatalf("Cannot insert into table account: %s", err)
+	}
+
+	lastID, err = res.LastInsertId()
+	if err != nil {
+		t.Fatalf("Cannot fetch last inserted id: %s\n", err)
+	}
+
+	if lastID != 2 {
+		t.Fatalf("Last insterted id should be 2, not %d", lastID)
+	}
+}
Repository: proullon/ramsql
Pull request #71 (2023-02-22 21:03:53)

fix: handles IF NOT EXISTS in CREATE TABLE


Patch:
diff --git a/engine/table.go b/engine/table.go
index 2d8a2d6..634bed1 100644
--- a/engine/table.go
+++ b/engine/table.go
@@ -50,7 +50,7 @@ func createTableExecutor(e *Engine, tableDecl *parser.Decl, conn protocol.Engine
 		return fmt.Errorf("parsing failed, malformed query")
 	}
 
-	// Fetch constrainit (i.e: "IF EXISTS")
+	// Check for specific attribute
 	i = 0
 	for i < len(tableDecl.Decl) {
 
@@ -65,9 +65,12 @@ func createTableExecutor(e *Engine, tableDecl *parser.Decl, conn protocol.Engine
 		i++
 	}
 
+	// Check if 'IF NOT EXISTS' is present
+	ifNotExists := hasIfNotExists(tableDecl)
+
 	// Check if table does not exists
 	r := e.relation(tableDecl.Decl[i].Lexeme)
-	if r != nil {
+	if r != nil && !ifNotExists {
 		return fmt.Errorf("table %s already exists", tableDecl.Decl[i].Lexeme)
 	}
 
@@ -93,3 +96,18 @@ func createTableExecutor(e *Engine, tableDecl *parser.Decl, conn protocol.Engine
 	conn.WriteResult(0, 1)
 	return nil
 }
+
+func hasIfNotExists(tableDecl *parser.Decl) bool {
+	for _, d := range tableDecl.Decl {
+		if d.Token == parser.IfToken {
+			if len(d.Decl) > 0 && d.Decl[0].Token == parser.NotToken {
+				not := d.Decl[0]
+				if len(not.Decl) > 0 && not.Decl[0].Token == parser.ExistsToken {
+					return true
+				}
+			}
+		}
+	}
+
+	return false
+}


Test patch:
diff --git a/driver/driver_test.go b/driver/driver_test.go
index 558fa2f..37c6298 100644
--- a/driver/driver_test.go
+++ b/driver/driver_test.go
@@ -51,6 +51,36 @@ func TestInsertEmptyString(t *testing.T) {
 
 }
 
+func TestCreateTableIfNotExists(t *testing.T) {
+	log.UseTestLogger(t)
+
+	db, err := sql.Open("ramsql", "TestCreateTableIfNotExists")
+	if err != nil {
+		t.Fatalf("sql.Open : Error : %s\n", err)
+	}
+	defer db.Close()
+
+	_, err = db.Exec("CREATE TABLE IF NOT EXISTS account (id INT, email TEXT)")
+	if err != nil {
+		t.Fatalf("sql.Exec: cannot create table: %s\n", err)
+	}
+
+	_, err = db.Exec("CREATE TABLE account (id INT, email TEXT)")
+	if err == nil {
+		t.Fatalf("sql.Exec: table already exists, expected error")
+	}
+
+	_, err = db.Exec("CREATE TABLE IF NOT EXISTS account (id INT, email TEXT)")
+	if err != nil {
+		t.Fatalf("sql.Exec: IF NOT EXISTS is ignored: %s\n", err)
+	}
+
+	err = db.Close()
+	if err != nil {
+		t.Fatalf("sql.Close : Error : %s\n", err)
+	}
+}
+
 func TestInsertTable(t *testing.T) {
 	log.UseTestLogger(t)
 	db, err := sql.Open("ramsql", "TestInsertTable")