(ctx *sql.Context, name string, schema sql.PrimaryKeySchema, collation sql.CollationID, comment string, temporary bool)
| 125 | |
| 126 | return tbls, nil |
| 127 | } |
| 128 | |
| 129 | // Name implements sql.Database. |
| 130 | func (d *Database) Name() string { |
| 131 | return d.name |
| 132 | } |
| 133 | |
| 134 | func (d *Database) createAllTable(ctx *sql.Context, name string, schema sql.PrimaryKeySchema, collation sql.CollationID, comment string, temporary bool) error { |
| 135 | var columns []string |
| 136 | var columnCommentSQLs []string |
| 137 | var fullTableName string |
| 138 | |
| 139 | if temporary { |
| 140 | fullTableName = FullTableName("temp", "main", name) |
| 141 | } else { |
| 142 | fullTableName = FullTableName(d.catalog, d.name, name) |
| 143 | } |
| 144 | |
| 145 | var sequenceName, fullSequenceName string |
| 146 | |
| 147 | for _, col := range schema.Schema { |
| 148 | typ, err := DuckdbDataType(col.Type) |
| 149 | if err != nil { |
| 150 | return err |
| 151 | } |
| 152 | colDef := fmt.Sprintf(`"%s" %s`, col.Name, typ.name) |
| 153 | if col.Nullable { |
| 154 | colDef += " NULL" |
| 155 | } else { |
| 156 | colDef += " NOT NULL" |
| 157 | } |
| 158 | |
| 159 | if col.Default != nil { |
| 160 | typ.mysql.Default = col.Default.String() |
| 161 | defaultExpr, err := parseDefaultValue(typ.mysql.Default) |
| 162 | if err != nil { |
| 163 | return err |
| 164 | } |
| 165 | colDef += " DEFAULT " + defaultExpr |
| 166 | } else if col.AutoIncrement { |
| 167 | typ.mysql.AutoIncrement = true |
| 168 | |
| 169 | // Generate a random sequence name. |
| 170 | // TODO(fan): Drop the sequence when the table is dropped or the column is removed. |
| 171 | uuid, err := uuid.NewRandom() |
| 172 | if err != nil { |
| 173 | return err |
| 174 | } |
| 175 | sequenceName = SequenceNamePrefix + uuid.String() |
| 176 | if temporary { |
| 177 | fullSequenceName = `temp.main."` + sequenceName + `"` |
| 178 | } else { |
| 179 | fullSequenceName = InternalSchemas.SYS.Schema + `."` + sequenceName + `"` |
| 180 | } |
| 181 | |
| 182 | defaultExpr := `nextval('` + fullSequenceName + `')` |
| 183 | colDef += " DEFAULT " + defaultExpr |
| 184 | } |
no test coverage detected