⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sql_dbcreator.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */#include "common/setup_before.h"#ifdef WITH_SQL#include <stdio.h>#ifdef STDC_HEADERS# include <stdlib.h>#else# ifdef HAVE_MALLOC_H#  include <malloc.h># endif#endif#ifdef HAVE_STRING_H# include <string.h>#else# ifdef HAVE_STRINGS_H#  include <strings.h># endif#endif#define  SQL_DBCREATOR_INTERNAL_ACCESS#include "sql_dbcreator.h"#undef   SQL_DBCREATOR_INTERNAL_ACCESS#include "storage_sql.h"#include "common/eventlog.h"#include "common/util.h"#include "compat/strdup.h"#include "common/list.h"#include "common/xalloc.h"#include "common/xstr.h"#include "prefs.h"#include "common/setup_after.h"t_elem  * curr_table  = NULL;t_elem  * curr_column = NULL;t_elem  * curr_cmd    = NULL;t_db_layout * db_layout;static void sql_escape_command(char *escape, const char *from, int len);t_column * create_column(char * name, char * value, char * mode, char * extra_cmd){  t_column * column;    if (!(name))    {      eventlog(eventlog_level_error,__FUNCTION__,"got NULL column name");      return NULL;    }    if (!(value))    {      eventlog(eventlog_level_error,__FUNCTION__,"got NULL column value");      return NULL;    }    column = xmalloc(sizeof(t_column));  column->name  = xstrdup(name);  column->value = xstrdup(value);  if (mode && extra_cmd)  {	  column->mode      = xstrdup(mode);	  column->extra_cmd = xstrdup(extra_cmd);  }  else  {	  column->mode      = NULL;	  column->extra_cmd = NULL;  }  return column;};void dispose_column(t_column * column){  if (column)    {      if (column->name)      xfree((void *)column->name);      if (column->value)     xfree((void *)column->value);      if (column->mode)      xfree((void *)column->mode);      if (column->extra_cmd) xfree((void *)column->extra_cmd);      xfree((void *)column);    }}t_sqlcommand * create_sqlcommand(char * sql_command, char * mode, char * extra_cmd){  t_sqlcommand * sqlcommand;    if (!(sql_command))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL sql_command");    return NULL;  }    sqlcommand = xmalloc(sizeof(t_sqlcommand));  sqlcommand->sql_command = xstrdup(sql_command);  if (mode && extra_cmd)  {    sqlcommand->mode      = xstrdup(mode);    sqlcommand->extra_cmd = xstrdup(extra_cmd);  }  else  {    sqlcommand->mode      = NULL;    sqlcommand->extra_cmd = NULL;  }  return sqlcommand;}void dispose_sqlcommand(t_sqlcommand * sqlcommand){  if (sqlcommand)  {    if (sqlcommand->sql_command) xfree((void *)sqlcommand->sql_command);    if (sqlcommand->mode) xfree((void *)sqlcommand->mode);    if (sqlcommand->extra_cmd) xfree((void *)sqlcommand->extra_cmd);    xfree(sqlcommand);  }}t_table * create_table(char * name){  t_table * table;    if (!(name))    {      eventlog(eventlog_level_error,__FUNCTION__,"got NULL table name");      return NULL;    }    table = xmalloc(sizeof(t_table));  table->name = xstrdup(name);  table->columns = list_create();  table->sql_commands = list_create();    return table;}void dispose_table(t_table * table){  t_elem * curr;  t_column * column;  t_sqlcommand * sql_command;    if (table)    {      if (table->name) xfree((void *)table->name);      // free list      if (table->columns)        {          LIST_TRAVERSE(table->columns,curr)	    {	      if (!(column = elem_get_data(curr)))		{		  eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list");		  continue;		}	      dispose_column(column);	      list_remove_elem(table->columns,&curr);	    }	  	  list_destroy(table->columns);        }      if (table->sql_commands)        {          LIST_TRAVERSE(table->sql_commands,curr)	    {	      if (!(sql_command = elem_get_data(curr)))		{		  eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list");		  continue;		}	      dispose_sqlcommand(sql_command);	      list_remove_elem(table->sql_commands,&curr);	    }	  	  list_destroy(table->sql_commands);        }                  xfree((void *)table);    }}void table_add_column(t_table * table, t_column * column){  if ((table) && (column))    {      list_append_data(table->columns,column);    }}void table_add_sql_command(t_table * table, t_sqlcommand * sql_command){  if ((table) && (sql_command))    {      list_append_data(table->sql_commands,sql_command);    }}t_db_layout * create_db_layout(){  t_db_layout * db_layout;    db_layout = xmalloc(sizeof(t_db_layout));  db_layout->tables = list_create();    return db_layout;}void dispose_db_layout(t_db_layout * db_layout){  t_elem  * curr;  t_table * table;   if (db_layout)    {      if (db_layout->tables)        {          LIST_TRAVERSE(db_layout->tables,curr)	    {	      if (!(table = elem_get_data(curr)))		{		  eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list");		  continue;		}	      dispose_table(table);	      list_remove_elem(db_layout->tables,&curr);	    }          list_destroy(db_layout->tables);        }      xfree((void *)db_layout);    }  }void db_layout_add_table(t_db_layout * db_layout, t_table * table){  if ((db_layout) && (table))    {      list_append_data(db_layout->tables,table);    }}t_table * db_layout_get_first_table(t_db_layout * db_layout){  t_table * table;  curr_column = NULL;  if (!(db_layout))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL db_layout");    return NULL;  }  if (!(db_layout->tables))  {    eventlog(eventlog_level_error,__FUNCTION__,"found NULL db_layout->tables");    return NULL;  }  if (!(curr_table = list_get_first(db_layout->tables)))  {    eventlog(eventlog_level_error,__FUNCTION__,"db_layout has no tables");    return NULL;  }  if (!(table = elem_get_data(curr_table)))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list");    return NULL;  }  return table;}t_table * db_layout_get_next_table(t_db_layout * db_layout){  t_table * table;  curr_column = NULL;  if (!(curr_table))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL curr_table");    return NULL;  }  if (!(curr_table = elem_get_next(db_layout->tables, curr_table))) return NULL;  if (!(table = elem_get_data(curr_table)))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list");    return NULL;  }  return table;}t_column * table_get_first_column(t_table * table){  t_column * column;  if (!(table))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL table");    return NULL;  }  if (!(table->columns))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL table->columns");    return NULL;  }  if (!(curr_column = list_get_first(table->columns)))  {    eventlog(eventlog_level_error,__FUNCTION__,"table has no columns");    return NULL;  }  if (!(column = elem_get_data(curr_column)))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list");    return NULL;  }  return column;}t_column * table_get_next_column(t_table * table){  t_column * column;  if (!(curr_column))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL curr_column");    return NULL;  }  if (!(curr_column = elem_get_next(table->columns, curr_column))) return NULL;  if (!(column = elem_get_data(curr_column)))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list");    return NULL;  }  return column;}t_sqlcommand * table_get_first_sql_command(t_table * table){  t_sqlcommand * sql_command;  if (!(table))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL table");    return NULL;  }  if (!(table->sql_commands))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL table->sql_commands");    return NULL;  }  if (!(curr_cmd = list_get_first(table->sql_commands)))  {    return NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -