| 1 |
<?php |
<?php |
| 2 |
// $Id: stockapi.install,v 1.1.4.1 2007/02/05 15:25:43 oadaeh Exp $ |
// $Id$ |
| 3 |
|
|
| 4 |
|
/* |
| 5 |
|
* Implementation of hook_schema |
| 6 |
|
*/ |
| 7 |
|
function stockapi_schema() { |
| 8 |
|
$schema['stockapi'] = array( |
| 9 |
|
'description' => t('A table to store stock information'), |
| 10 |
|
|
| 11 |
|
'fields' => array( |
| 12 |
|
'symbol' => array( |
| 13 |
|
'description' => t('Stock symbol'), |
| 14 |
|
'type' => 'varchar', |
| 15 |
|
'length' => 10, |
| 16 |
|
'not null' => TRUE, |
| 17 |
|
'default' => '', |
| 18 |
|
), |
| 19 |
|
|
| 20 |
|
'name' => array( |
| 21 |
|
'description' => t('Company symbol'), |
| 22 |
|
'type' => 'varchar', |
| 23 |
|
'length' => 50, |
| 24 |
|
'not null' => TRUE, |
| 25 |
|
'default' => '', |
| 26 |
|
), |
| 27 |
|
|
| 28 |
|
'current_price' => array( |
| 29 |
|
'description' => t('Current price'), |
| 30 |
|
'type' => 'float', |
| 31 |
|
'not null' => TRUE, |
| 32 |
|
'default' => 0.0, |
| 33 |
|
), |
| 34 |
|
|
| 35 |
|
'change_amt' => array( |
| 36 |
|
'description' => t('% Change'), |
| 37 |
|
'type' => 'float', |
| 38 |
|
'not null' => TRUE, |
| 39 |
|
'default' => 0.0, |
| 40 |
|
), |
| 41 |
|
|
| 42 |
|
'opening' => array( |
| 43 |
|
'description' => t('Opening price'), |
| 44 |
|
'type' => 'float', |
| 45 |
|
'not null' => TRUE, |
| 46 |
|
'default' => 0.0, |
| 47 |
|
), |
| 48 |
|
|
| 49 |
|
'high' => array( |
| 50 |
|
'description' => t('High price'), |
| 51 |
|
'type' => 'float', |
| 52 |
|
'not null' => TRUE, |
| 53 |
|
'default' => 0.0, |
| 54 |
|
), |
| 55 |
|
|
| 56 |
|
'low' => array( |
| 57 |
|
'description' => t('Low price'), |
| 58 |
|
'type' => 'float', |
| 59 |
|
'not null' => TRUE, |
| 60 |
|
'default' => 0.0, |
| 61 |
|
), |
| 62 |
|
|
| 63 |
|
'volume' => array( |
| 64 |
|
'description' => t('Volume'), |
| 65 |
|
'type' => 'int', |
| 66 |
|
'not null' => TRUE, |
| 67 |
|
'unsigned' => TRUE, |
| 68 |
|
'default' => 0, |
| 69 |
|
), |
| 70 |
|
|
| 71 |
|
'last_date' => array( |
| 72 |
|
'description' => t('Last date updated'), |
| 73 |
|
'type' => 'varchar', |
| 74 |
|
'length' => 10, |
| 75 |
|
'not null' => TRUE, |
| 76 |
|
'default' => 0, |
| 77 |
|
), |
| 78 |
|
|
| 79 |
|
'last_time' => array( |
| 80 |
|
'description' => t(''), |
| 81 |
|
'type' => 'int', |
| 82 |
|
'unsigned' => TRUE, |
| 83 |
|
'not null' => TRUE, |
| 84 |
|
'default' => 0, |
| 85 |
|
), |
| 86 |
|
|
| 87 |
|
'updated' => array( |
| 88 |
|
'description' => t(''), |
| 89 |
|
'type' => 'int', |
| 90 |
|
'unsigned' => TRUE, |
| 91 |
|
'not null' => TRUE, |
| 92 |
|
'default' => 0, |
| 93 |
|
) |
| 94 |
|
|
| 95 |
|
), |
| 96 |
|
'primary key' => array('symbol') |
| 97 |
|
); |
| 98 |
|
|
| 99 |
|
return $schema; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
|
| 103 |
/** |
/** |
| 104 |
* Implementation of hook_install() |
* Implementation of hook_install() |
| 105 |
* |
* |
| 106 |
* This will automatically install the MySQL database tables for StockAPI. |
* This will automatically install the database tables for StockAPI. |
|
* |
|
|
* TODO: Create pgsql query. |
|
| 107 |
* |
* |
| 108 |
*/ |
*/ |
| 109 |
function stockapi_install() { |
function stockapi_install() { |
| 110 |
switch ($GLOBALS['db_type']) { |
drupal_install_schema('stockapi'); |
|
case 'mysqli': |
|
|
case 'mysql': |
|
|
db_query( |
|
|
"CREATE TABLE {stockapi} ( |
|
|
symbol varchar(10) NOT NULL default '', |
|
|
name varchar(50) NOT NULL default '', |
|
|
current_price float NOT NULL default '0.0', |
|
|
change_amt float NOT NULL default '0.0', |
|
|
opening float NOT NULL default '0.0', |
|
|
high float NOT NULL default '0.0', |
|
|
low float NOT NULL default '0.0', |
|
|
volume int(10) NOT NULL default '0.0', |
|
|
last_date varchar(10) NOT NULL, |
|
|
last_time varchar(8) NOT NULL, |
|
|
updated int(10) NOT NULL default '0', |
|
|
UNIQUE KEY symbol (symbol) |
|
|
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
|
|
break; |
|
|
|
|
|
case 'pgsql': |
|
|
break; |
|
|
} |
|
| 111 |
} |
} |
| 112 |
|
|
| 113 |
/** |
/** |
| 115 |
* |
* |
| 116 |
* This will automatically remove the MySQL database tables for StockAPI. |
* This will automatically remove the MySQL database tables for StockAPI. |
| 117 |
* |
* |
|
* TODO: Create pgsql query. |
|
| 118 |
*/ |
*/ |
| 119 |
function stockapi_uninstall() { |
function stockapi_uninstall() { |
| 120 |
switch ($GLOBALS['db_type']) { |
drupal_uninstall_schema('stockapi'); |
|
case 'mysqli': |
|
|
case 'mysql': |
|
|
db_query('DROP TABLE {stockapi}'); |
|
|
variable_del('stockapi_fetch_last'); |
|
|
variable_del('stockapi_fetch'); |
|
|
variable_del('stockapi_rows'); |
|
|
break; |
|
|
|
|
|
case 'pgsql': |
|
|
break; |
|
|
} |
|
| 121 |
} |
} |