diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index 5d023d6205..1429719df2 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -361,13 +361,48 @@ class acp_database break; case 'sqlite': + // This is *not* my fault. The PHP guys forgot a call to finalize when they wrote this function. This forces all the tables to stay locked... + // They finally fixed it in 5.3 but 5.2 still have this so instead, we go and grab the column types by smashing open the sqlite_master table + // and grope around for things that remind us of datatypes... + if (version_compare(phpversion(), '5.3', '>=')) + { + $col_types = sqlite_fetch_column_types($table_name, $db->db_connect_id); + } + else + { + $sql = "SELECT sql + FROM sqlite_master + WHERE type = 'table' + AND name = '" . $table_name . "'"; + $table_data = sqlite_single_query($db->db_connect_id, $sql); + $table_data = preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', '', $table_data); + $table_data = trim($table_data); - $col_types = sqlite_fetch_column_types($table_name, $db->db_connect_id); + preg_match('#\((.*)\)#s', $table_data, $matches); + + $column_list = array(); + $table_cols = explode(',', trim($matches[1])); + foreach($table_cols as $declaration) + { + $entities = preg_split('#\s+#', trim($declaration)); + $column_name = preg_replace('/"?([^"]+)"?/', '\1', $entities[0]); + + // Hit a primary key, those are not what we need :D + if (empty($entities[1])) + { + continue; + } + $col_types[$column_name] = $entities[1]; + } + } + + // Unbueffered query and the foreach make this ultra fast, we wait for nothing. $sql = "SELECT * FROM $table_name"; - $result = $db->sql_query($sql); + $result = sqlite_unbuffered_query($sql, $db->db_connect_id); + $rows = sqlite_fetch_all($result, SQLITE_ASSOC); - while ($row = $db->sql_fetchrow($result)) + foreach ($rows as $row) { $names = $data = array(); foreach ($row as $row_name => $row_data) diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 738eda5101..1ada445770 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -119,7 +119,7 @@ class acp_profile $db->sql_freeresult($result); // Create a temp table and populate it, destroy the existing one - $db->sql_query(preg_replace('#CREATE\s+TABLE\s+' . PROFILE_FIELDS_DATA_TABLE . '#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql'])); + $db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql'])); $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE); $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE); @@ -130,7 +130,7 @@ class acp_profile $column_list = array(); foreach($old_table_cols as $declaration) { - $entities = preg_split('#\s+#', $declaration); + $entities = preg_split('#\s+#', trim($declaration)); if ($entities[0] !== $field_ident) { $column_list[] = $entities[0]; @@ -1023,7 +1023,7 @@ class acp_profile $db->sql_freeresult($result); // Create a temp table and populate it, destroy the existing one - $db->sql_query(preg_replace('#CREATE\s+TABLE\s+' . PROFILE_FIELDS_DATA_TABLE . '#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql'])); + $db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql'])); $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE); $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE); @@ -1034,8 +1034,7 @@ class acp_profile $column_list = array(); foreach($old_table_cols as $declaration) { - $entities = preg_split('#\s+#', $declaration); - var_dump($entities); + $entities = preg_split('#\s+#', trim($declaration)); $column_list[] = $entities[0]; }