MySQL- Руководство разработчика



              

Пример простого встроенного сервера - часть 3


void db_do_query(MYSQL *db, const char *query, enum on_error on_error) { char *err = 0;

if (mysql_query(db, query) != 0) goto err; if (mysql_field_count(db) > 0) { if ((err = show_query(db))) goto err; } else if (mysql_affected_rows(db)) printf("Affected rows: %lld [%s]\n", mysql_affected_rows(db),query); return; err: switch (on_error) { case E_okay: break; case E_warn: fprintf(stderr, "db_do_query failed: %s [%s]\n", err ? err : mysql_error(db), query); break; case E_fail: die(db, "db_do_query failed: %s [%s]", err ? err : mysql_error(db), query); break; } }

Файл GNUmakefile: # Set this to your mysql source directory m := ../mysql-4.0 CC := cc CPPFLAGS := -I$m/include -D_THREAD_SAFE -D_REENTRANT CFLAGS := -g -W -Wall LDFLAGS := -static LDLIBS = $(embed_libs) -lz -lm -lcrypt

ifneq (,$(shell grep FreeBSD /COPYRIGHT 2>/dev/null)) # FreeBSD LDFLAGS += -pthread else # Assume Linux LDLIBS += -lpthread endif

# Standard libraries embed_libs := \ $m/libmysqld/.libs/libmysqld.a \ $m/isam/libnisam.a \ $m/myisam/libmyisam.a \ $m/heap/libheap.a \ $m/merge/libmerge.a \ $m/myisammrg/libmyisammrg.a

# Optionally-built libraries ifneq (,$(shell test -r $m/innobase/usr/libusr.a && echo "yes")) embed_libs += \ $m/innobase/usr/libusr.a \ $m/innobase/odbc/libodbc.a \ $m/innobase/srv/libsrv.a \ $m/innobase/que/libque.a \ $m/innobase/srv/libsrv.a \ $m/innobase/dict/libdict.a \ $m/innobase/ibuf/libibuf.a \ $m/innobase/row/librow.a \ $m/innobase/pars/libpars.a \ $m/innobase/btr/libbtr.a \ $m/innobase/trx/libtrx.a \ $m/innobase/read/libread.a \ $m/innobase/usr/libusr.a \ $m/innobase/buf/libbuf.a \ $m/innobase/ibuf/libibuf.a \ $m/innobase/eval/libeval.a \ $m/innobase/log/liblog.a \ $m/innobase/fsp/libfsp.a \ $m/innobase/fut/libfut.a \ $m/innobase/fil/libfil.a \ $m/innobase/lock/liblock.a \ $m/innobase/mtr/libmtr.a \ $m/innobase/page/libpage.a \ $m/innobase/rem/librem.a \ $m/innobase/thr/libthr.a \ $m/innobase/com/libcom.a \ $m/innobase/sync/libsync.a \ $m/innobase/data/libdata.a \ $m/innobase/mach/libmach.a \ $m/innobase/ha/libha.a \ $m/innobase/dyn/libdyn.a \ $m/innobase/mem/libmem.a \ $m/innobase/sync/libsync.a \ $m/innobase/ut/libut.a \ $m/innobase/os/libos.a \ $m/innobase/ut/libut.a endif

ifneq (,$(shell test -r $m/bdb/build_unix/libdb.a && echo "yes")) embed_libs += $m/bdb/build_unix/libdb.a endif

# Support libraries embed_libs += \ $m/mysys/libmysys.a \ $m/strings/libmystrings.a \ $m/dbug/libdbug.a \ $m/regex/libregex.a

# Optionally built support libraries ifneq (,$(shell test -r $m/readline/libreadline.a && echo "yes")) embed_libs += $m/readline/libreadline.a endif

# This works for simple one-file test programs sources := $(wildcard *.c) objects := $(patsubst %c,%o,$(sources)) targets := $(basename $(sources))

all: $(targets)

clean: rm -f $(targets) $(objects) *.core




Содержание  Назад  Вперед