Como saber nome do banco default

Forum sobre SQL.

Moderador: Moderadores

Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Como saber nome do banco default

Mensagem por JoséQuintas »

Estou querendo passar algumas funções para stored function, mas esbarrei nisso.

por exemplo, saber se tabela existe:

Código: Selecionar todos

METHOD TableExists( cTable ) CLASS ADOClass

   LOCAL nQtd

   ::cSQL := "SELECT COUNT(*) AS QTD FROM information_schema.TABLES WHERE table_schema=" + StringSQL( Lower( AppEmpresaApelido() ) ) + ;
      " AND table_name=" + StringSQL( cTable )
   ::Execute()
   nQtd := ::Value( "QTD" )
   ::CloseRecordset()

   RETURN nQtd > 0
Do lado do servidor, eu não vou ter o nome do banco de dados usado na conexão.
Tem como obter isso?
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Como saber nome do banco default

Mensagem por JoséQuintas »

Resolvido.

Código: Selecionar todos

CREATE FUNCTION ze_TableExists( cName VARCHAR(50) )
RETURNS int(11)
BEGIN
DECLARE nYes INT(11) ;
SET nYes = ( SELECT COUNT(*) from information_schema.tables 
             where table_schema=DATABASE() AND TABLE_NAME = cName );
RETURN IF( nYes > 0, 1, 0 );
END
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Como saber nome do banco default

Mensagem por JoséQuintas »

Testar se coluna existe

Código: Selecionar todos

CREATE FUNCTION ze_ColumnExists(
	`cField` VARCHAR(50),
	`cTable` VARCHAR(50)
)
RETURNS int(11)
BEGIN
DECLARE nYes INT(11) ;
SET nYes = ( SELECT COUNT(*) from information_schema.columns 
             where table_schema = DATABASE() AND TABLE_NAME = cTable
				 AND COLUMN_NAME = cField );
RETURN IF( nYes > 0, 1, 0 );
END
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Como saber nome do banco default

Mensagem por JoséQuintas »

existe.png
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder