| 748 | | function maybe_create_table($table_name, $create_ddl) { |
|---|
| 749 | | global $wpdb; |
|---|
| 750 | | foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) { |
|---|
| 751 | | if ($table == $table_name) { |
|---|
| 752 | | return true; |
|---|
| 753 | | } |
|---|
| 754 | | } |
|---|
| 755 | | //didn't find it try to create it. |
|---|
| 756 | | $q = $wpdb->query($create_ddl); |
|---|
| 757 | | // we cannot directly tell that whether this succeeded! |
|---|
| 758 | | foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) { |
|---|
| 759 | | if ($table == $table_name) { |
|---|
| 760 | | return true; |
|---|
| 761 | | } |
|---|
| 762 | | } |
|---|
| 763 | | return false; |
|---|
| 764 | | } |
|---|
| 785 | | /** |
|---|
| 786 | | ** maybe_add_column() |
|---|
| 787 | | ** Add column to db table if it doesn't exist. |
|---|
| 788 | | ** Returns: true if already exists or on successful completion |
|---|
| 789 | | ** false on error |
|---|
| 790 | | */ |
|---|
| 791 | | function maybe_add_column($table_name, $column_name, $create_ddl) { |
|---|
| 792 | | global $wpdb, $debug; |
|---|
| 793 | | foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { |
|---|
| 794 | | if ($debug) echo("checking $column == $column_name<br />"); |
|---|
| 795 | | if ($column == $column_name) { |
|---|
| 796 | | return true; |
|---|
| 797 | | } |
|---|
| 798 | | } |
|---|
| 799 | | //didn't find it try to create it. |
|---|
| 800 | | $q = $wpdb->query($create_ddl); |
|---|
| 801 | | // we cannot directly tell that whether this succeeded! |
|---|
| 802 | | foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { |
|---|
| 803 | | if ($column == $column_name) { |
|---|
| 804 | | return true; |
|---|
| 805 | | } |
|---|
| 806 | | } |
|---|
| 807 | | return false; |
|---|
| 808 | | } |
|---|
| 809 | | |
|---|
| 810 | | |
|---|