Fix Firebird loading, miscellaneous SQL method improvements

This commit is contained in:
Timothy Warren 2012-04-10 18:51:29 -04:00
parent 4a8dc21cf9
commit db31bd1c26
12 changed files with 143 additions and 59 deletions

View File

@ -128,7 +128,7 @@ foreach(pdo_drivers() as $d)
// Load Firebird if there is support
if(function_exists('fbird_connect'))
{
array_map('do_include', glob($path.'*.php'));
array_map('do_include', glob($path.'firebird/*.php'));
}
// --------------------------------------------------------------------------

View File

@ -0,0 +1,6 @@
auxiliary.org-netbeans-modules-php-editor.dbconn=jdbc:derby://localhost:1527/sample [app on APP]
copy.src.files=false
copy.src.target=
index.file=index.php
run.as=SCRIPT
url=http://localhost/OpenSQLManager/

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
</project-private>

View File

@ -0,0 +1,7 @@
include.path=${php.global.include.path}
php.version=PHP_5
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=true
web.root=.

9
nbproject/project.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>OpenSQLManager</name>
</data>
</configuration>
</project>

View File

@ -45,17 +45,6 @@ class firebird extends DB_PDO {
// --------------------------------------------------------------------------
/**
* Close the link to the database and any existing results
*/
public function __destruct()
{
@fbird_close();
@fbird_free_result($this->statement);
}
// --------------------------------------------------------------------------
/**
* Doesn't apply to Firebird
*/

View File

@ -51,7 +51,7 @@ class Firebird_Result {
switch($fetch_style)
{
case PDO::FETCH_OBJ:
return fbird_fetch_object($this->statement, IBASE_FETCH_BLOBS);
return fbird_fetch_object($this->statement, F_FETCH_BLOBS);
break;
case PDO::FETCH_NUM:
@ -88,6 +88,20 @@ class Firebird_Result {
// --------------------------------------------------------------------------
/**
* Emulate PDOStatement::fetchColumn
*
* @param int $colum_num
* @return mixed
*/
public function fetchColumn($column_num=0)
{
$row = $this->fetch(PDO::FETCH_NUM);
return $row[$column_num];
}
// --------------------------------------------------------------------------
/**
* Run a prepared statement query
*

View File

@ -232,10 +232,9 @@ class Firebird_SQL extends DB_SQL {
public function table_list()
{
return <<<SQL
SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
AND "RDB\$VIEW_BLR" IS NOT NULL
SELECT "RDB\$RELATION_NAME"
FROM "RDB\$RELATIONS"
WHERE "RDB\$SYSTEM_FLAG"=0
ORDER BY "RDB\$RELATION_NAME" ASC
SQL;
}
@ -250,9 +249,10 @@ SQL;
public function system_table_list()
{
return <<<SQL
SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
WHERE "RDB\$RELATION_NAME" LIKE 'RDB$%'
OR "RDB\$RELATION_NAME" LIKE 'MON$%';
SELECT "RDB\$RELATION_NAME"
FROM "RDB\$RELATIONS"
WHERE "RDB\$SYSTEM_FLAG"=1
ORDER BY "RDB\$RELATION_NAME" ASC
SQL;
}
@ -266,10 +266,8 @@ SQL;
public function view_list()
{
return <<<SQL
SELECT "RDB\$RELATION_NAME"
FROM "RDB\$RELATIONS"
WHERE "RDB\$VIEW_BLR" IS NOT NULL
AND ("RDB\$SYSTEM_FLAG" IS NULL OR "RDB\$SYSTEM_FLAG" = 0)
SELECT DISTINCT "RDB\$VIEW_NAME"
FROM "RDB\$VIEW_RELATIONS"
SQL;
}
@ -297,10 +295,7 @@ SQL;
*/
public function function_list()
{
return <<<SQL
SELECT * FROM "RDB\$FUNCTIONS"
WHERE "RDB\$SYSTEM_FLAG" = 0
SQL;
return 'SELECT * FROM "RDB$FUNCTIONS"';
}
// --------------------------------------------------------------------------
@ -312,7 +307,23 @@ SQL;
*/
public function procedure_list()
{
return 'SELECT * FROM "RDB$PROCEDURES"';
return <<<SQL
SELECT "RDB\$PROCEDURE_NAME",
"RDB\$PROCEDURE_ID",
"RDB\$PROCEDURE_INPUTS",
"RDB\$PROCEDURE_OUTPUTS",
"RDB\$DESCRIPTION",
"RDB\$PROCEDURE_SOURCE",
"RDB\$SECURITY_CLASS",
"RDB\$OWNER_NAME",
"RDB\$RUNTIME",
"RDB\$SYSTEM_FLAG",
"RDB\$PROCEDURE_TYPE",
"RDB\$VALID_BLR"
FROM "RDB\$PROCEDURES"
ORDER BY "RDB\$PROCEDURE_NAME" ASC
SQL;
}
// --------------------------------------------------------------------------
@ -328,6 +339,53 @@ SQL;
SELECT "RDB\$GENERATOR_NAME"
FROM "RDB\$GENERATORS"
WHERE "RDB\$SYSTEM_FLAG" = 0
SQL;
}
// --------------------------------------------------------------------------
/**
* Return sql to list columns of the specified table
*
* @param string $table
* @return string
*/
public function column_list($table)
{
return <<<SQL
SELECT r.RDB\$FIELD_NAME AS field_name,
r.RDB\$DESCRIPTION AS field_description,
r.RDB\$DEFAULT_VALUE AS field_default_value,
r.RDB\$NULL_FLAG AS field_not_null_constraint,
f.RDB\$FIELD_LENGTH AS field_length,
f.RDB\$FIELD_PRECISION AS field_precision,
f.RDB\$FIELD_SCALE AS field_scale,
CASE f.RDB\$FIELD_TYPE
WHEN 261 THEN 'BLOB'
WHEN 14 THEN 'CHAR'
WHEN 40 THEN 'CSTRING'
WHEN 11 THEN 'D_FLOAT'
WHEN 27 THEN 'DOUBLE'
WHEN 10 THEN 'FLOAT'
WHEN 16 THEN 'INT64'
WHEN 8 THEN 'INTEGER'
WHEN 9 THEN 'QUAD'
WHEN 7 THEN 'SMALLINT'
WHEN 12 THEN 'DATE'
WHEN 13 THEN 'TIME'
WHEN 35 THEN 'TIMESTAMP'
WHEN 37 THEN 'VARCHAR'
ELSE 'UNKNOWN'
END AS field_type,
f.RDB\$FIELD_SUB_TYPE AS field_subtype,
coll.RDB\$COLLATION_NAME AS field_collation,
cset.RDB\$CHARACTER_SET_NAME AS field_charset
FROM RDB\$RELATION_FIELDS r
LEFT JOIN RDB\$FIELDS f ON r.RDB\$FIELD_SOURCE = f.RDB\$FIELD_NAME
LEFT JOIN RDB\$COLLATIONS coll ON f.RDB\$COLLATION_ID = coll.RDB\$COLLATION_ID
LEFT JOIN RDB\$CHARACTER_SETS cset ON f.RDB\$CHARACTER_SET_ID = cset.RDB\$CHARACTER_SET_ID
WHERE r.RDB\$RELATION_NAME='{$table}'
ORDER BY r.RDB\$FIELD_POSITION
SQL;
}
}

View File

@ -278,5 +278,29 @@ SQL;
SQL;
}
// --------------------------------------------------------------------------
/**
* Return sql to list columns of the specified table
*
* @param string $table
* @return string
*/
public function column_list($table)
{
return <<<SQL
SELECT ordinal_position,
column_name,
data_type,
column_default,
is_nullable,
character_maximum_length,
numeric_precision
FROM information_schema.columns
WHERE table_name = '{$table}'
ORDER BY ordinal_position;
SQL;
}
}
//End of pgsql_manip.php

View File

@ -366,7 +366,7 @@ class DB_Info_Widget extends GtkTable {
$res = $this->settings->add_db($data['name'], $data);
if ( ! $res)
if ($res === FALSE)
{
error("Failed to add database - Connection information invalid");
}

View File

@ -123,7 +123,7 @@ class DB_tabs extends GTKNotebook {
// 'Procedures' Tab
{
self::_add_tab($conn, 'Procedures', 'Procedure name', 'get_procedures');
self::_add_row_tab($conn, 'Procedures', 'get_procedures');
}
// 'Functions' Tab
@ -289,7 +289,7 @@ class DB_tabs extends GTKNotebook {
foreach($tab_data[$i] as $v)
{
$vals[] = ++$j;
$vals[] = $v;
$vals[] = trim($v);
}
call_user_func_array(array($tab_model, 'set'), $vals);
@ -308,32 +308,5 @@ class DB_tabs extends GTKNotebook {
return;
}
/**
* Connects to a different database than the one currently in use
*
* @param type $view
* @param type $path
* @param type $column
* @param type $data
*/
public function _switch_db($view, $path, $column, $data=array())
{
// Get the selected database
$new_db = $view->get(0);
// Get existing connections
$conns = DB_REG::get_connections();
// Get connection info for existing connections
$conn_info = array();
foreach($conns as $c)
{
$conn_info[$c] = Settings::get_instance()->get_db($c);
}
// @todo figure out how to single out the current db connection
}
}
// End of db_tabs.php

Binary file not shown.