Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Implement SHOW CREATE TABLE #406

Closed
erizocosmico opened this issue Oct 5, 2018 · 5 comments
Closed

Implement SHOW CREATE TABLE #406

erizocosmico opened this issue Oct 5, 2018 · 5 comments
Labels
enhancement New feature or request hacktoberfest Ready to pick for Hacktoberfest

Comments

@erizocosmico
Copy link
Contributor

Implement SHOW CREATE TABLE statement.

See: src-d/gitbase#361 (comment)

@erizocosmico erizocosmico added enhancement New feature or request hacktoberfest Ready to pick for Hacktoberfest labels Oct 5, 2018
@ntakouris
Copy link
Contributor

ntakouris commented Oct 7, 2018

I'll try this...

@ntakouris
Copy link
Contributor

  1. I can't find Charset, Auto increment by number and engine. Should ENGINE default to InnoDB, and DEFAULT CHARSET to utf8mb4

I've got to a point where I can print out the basic structure of the statement, but have some issues with the constraints part. Test run image

Can you provide some guidance regarding the constraints part?
My bet is that something similar to the following snippet should happen, where you grab the indices and just print the expressions:
` indexes := i.registry.IndexesByTable(i.db.Name(), i.table)

constrCreateStatements := make([]string, len(indexes), len(indexes))
for indx, index := range indexes {

	createStmtPart := fmt.Sprintf("%s (`%s`)", stripBrackets(index.Expressions()), index.ID())

	if index.Driver() != "" {
		createStmtPart = fmt.Sprintf("%s USING driverid (%s)", createStmtPart, index.Driver())
	}

	constrCreateStatements[indx] = fmt.Sprintf(",\n%s\n", createStmtPart)
}`

Maybe add a switch on this because:
// Expressions returns the indexed expressions. If the result is more than // one expression, it means the index has multiple columns indexed. If it's // just one, it means it may be an expression or a column. Expressions() []string

@ntakouris
Copy link
Contributor

Charset being under conversation on #407

@smola
Copy link
Collaborator

smola commented Oct 9, 2018

ENGINE=InnoDB by default sounds good, it is the default both for MySQL and MariaDB. Although it's completely fake, users will not be expected to use these CREATE TABLE statements within go-mysql-server itself at the moment.

@erizocosmico
Copy link
Contributor Author

@Zarkopafilis constraints should be empty. go-mysql-server does not create primary keys, foreign keys or unique indexes right now, so they should not show up. The kind of indexes created by go-mysql-server shouldn't show up here.

ajnavarro added a commit that referenced this issue Oct 17, 2018
sql: plan: Add SHOW CREATE TABLE [Fix #406]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request hacktoberfest Ready to pick for Hacktoberfest
Projects
None yet
Development

No branches or pull requests

4 participants