Database dump parser

Описание: Инклуды
Модератор: SJplayer

Дим M
Автор темы, Администратор
Администратор
Аватара
Дим M
Автор темы, Администратор
Администратор
Сообщения: 1608
Зарегистрирован: 5 апреля 2013
С нами: 10 лет 11 месяцев

#1 Дим » 15 января 2014, 17:13

Изображение


Введение
Анализирует базы данных (. SQL файлы) в базу данных MySQL. Он будет искать файл для любых таблиц, а также создавать те, решают, как и любые соответствующие данные таблицы, и дополнительные запросы.

Какой в ​​этом смысл?
Дело в том, что он может сохранить вам время. Вы можете разобрать запросы легко, без необходимости входа в PhpMyAdmin , и может быть полезным для некоторых владельцев серверов .

Установка
Просто загрузите "SQL-parser.inc" и добавить его в начале вашего скрипта:

Код: Выделить всё

#include <sql-parser> 


Пример с "mysql_parse":

Код: Выделить всё

new
    
handle mysql_connect("127.0.0.1""root""my_database""");

if (
fexist("db_dump.sql"))
{
    
mysql_parse("db_dump.sql"handle);
    
fremove("db_dump.sql");


Совместимые версии
Это совместимо с MySQL R7 и более новых версиях (благодаря IZN).
Автор: Emmet_

Инклуд

Код: Выделить всё

// MySQL parser by Emmet_
// R33+ compatability by iZN

#tryinclude <a_mysql>

#if !defined MAX_QUERY_BUFFER
    #define MAX_QUERY_BUFFER (8192)
#endif

static stock
    g_QueryString
[MAX_QUERY_BUFFER] = "";

stock mysql_parse(const file[], connectionHandle 1)
{
    new
        
File:fHandle fopen(fileio_read),
        
string[200],
        
pos = -1
    
;
    if (
fHandle)
    {
        new
            
#if defined PARSER_DEBUG
                
iQueries,
                
iTables,
                
iRows,
            
#endif
            
bool:bCreateTable,
            
bool:bInsertRow
        
;
        while (
fread(fHandlestringsizeof(string)))
        {
            
// Most likely a comment, let's skip it.
            
if ((string[0] == '-' && string[1] == '-'))
                continue;

            
// Check to see if one of the last characters is a semi-colon.
            // Some queries are spread out within the database dump.
            
for (new len strlen(string), len; -->= 0; )
            {
                if (
string[i] <= ' ')
                    continue;

                if (
string[i] == ';' && (len i) >= 10)
                {
                    
pos i;
                    break;
                }
            }
            if (
pos != -&& (!bCreateTable && !bInsertRow))
            {
                
// We've found a result, so let's cut off the rest of the string.
                
string[pos 1] = '\0';

                
// Execute the query.
                #if defined mysql_tquery
                    
mysql_tquery(connectionHandlestring"""");
                
#elseif defined mysql_function_query
                    
mysql_function_query(ConnectionHandlestringfalse"""");
                
#endif
                // Reset "pos" back to -1.
                
pos = -1;

                
#if defined PARSER_DEBUG
                    
iQueries++;
                
#endif
            
}
            if (
strfind(string"CREATE TABLE"true) != -1) {
                
bCreateTable true;
            }
            else if (
strfind(string"INSERT INTO"true) != -1) {
                
bInsertRow true;
            }
            if (
bCreateTable || bInsertRow)
            {
                
strcat(g_QueryStringstring);

                
// Find the last semi-colon in the string.
                // If "bCreateTable or "bInsertRow" is true, it's most likely a huge query we're processing.
                
for (new strlen(string); -->= 0; )
                {
                    
// Strip leading spaces.
                    
if (string[i] <= ' ')
                        continue;

                    if (
string[i] == ';')
                    {
                        
// Execute the query.
                        #if defined mysql_tquery
                            
mysql_tquery(connectionHandleg_QueryString"""");
                        
#elseif defined mysql_function_query
                            
mysql_function_query(ConnectionHandleg_QueryStringfalse"""");
                        
#endif

                        // Reset the variables back to false.
                        
if (bCreateTable)
                        {
                            
#if defined PARSER_DEBUG
                                
iTables++;
                            
#endif
                            
bCreateTable false;
                        }
                        if (
bInsertRow)
                        {
                            
#if defined PARSER_DEBUG
                                
iRows++;
                            
#endif
                            
bInsertRow false;
                        }
                        
// Reset the string by blanking the cell.
                        
g_QueryString[0] = '\0';
                    }
                }
            }
        }
        
fclose(fHandle);

        
#if defined PARSER_DEBUG
            
printf("[sql-parser] %d queries, %d tables and %d rows executed successfully."iQueriesiTablesiRows);
        
#endif
    
}
    return 
1;
}

#undef MAX_QUERY_BUFFER 
[center]i love you [s]mxIni[/s] Mysql[/center]


Вернуться в «Include»

Кто сейчас на форуме (по активности за 5 минут)

Сейчас этот раздел просматривают: 6 гостей