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

📄 _mysql.c

📁 python联接mysql驱动 python联接mysql驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
					 &client_flag, &ssl,					 &local_infile					 ))		return -1;	if (!conv) 		conv = PyDict_New();#if PY_VERSION_HEX > 0x02000100	else		Py_INCREF(conv);#endif	if (!conv)		return -1;	self->converter = conv;#define _stringsuck(d,t,s) {t=PyMapping_GetItemString(s,#d);\        if(t){d=PyString_AsString(t);Py_DECREF(t);}\        PyErr_Clear();}		if (ssl) {#if HAVE_OPENSSL		PyObject *value = NULL;		_stringsuck(ca, value, ssl);		_stringsuck(capath, value, ssl);		_stringsuck(cert, value, ssl);		_stringsuck(key, value, ssl);		_stringsuck(cipher, value, ssl);#else		PyErr_SetString(_mysql_NotSupportedError,				"client library does not have SSL support");		return -1;#endif	}	Py_BEGIN_ALLOW_THREADS ;	conn = mysql_init(&(self->connection));	if (connect_timeout) {		unsigned int timeout = connect_timeout;		mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT, 				(char *)&timeout);	}	if (compress != -1) {		mysql_options(&(self->connection), MYSQL_OPT_COMPRESS, 0);		client_flag |= CLIENT_COMPRESS;	}	if (named_pipe != -1)		mysql_options(&(self->connection), MYSQL_OPT_NAMED_PIPE, 0);	if (init_command != NULL)		mysql_options(&(self->connection), MYSQL_INIT_COMMAND, init_command);	if (read_default_file != NULL)		mysql_options(&(self->connection), MYSQL_READ_DEFAULT_FILE, read_default_file);	if (read_default_group != NULL)		mysql_options(&(self->connection), MYSQL_READ_DEFAULT_GROUP, read_default_group);	if (local_infile != -1)		mysql_options(&(self->connection), MYSQL_OPT_LOCAL_INFILE, (char *) &local_infile);#if HAVE_OPENSSL	if (ssl)		mysql_ssl_set(&(self->connection),			      key, cert, ca, capath, cipher);#endif	conn = mysql_real_connect(&(self->connection), host, user, passwd, db,				  port, unix_socket, client_flag);	Py_END_ALLOW_THREADS ;	if (!conn) {		_mysql_Exception(self);		return -1;	}	/*	  PyType_GenericAlloc() automatically sets up GC allocation and	  tracking for GC objects, at least in 2.2.1, so it does not need to	  be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(),	  however.	*/	self->open = 1;	return 0;}static char _mysql_connect__doc__[] ="Returns a MYSQL connection object. Exclusive use of\n\keyword parameters strongly recommended. Consult the\n\MySQL C API documentation for more details.\n\\n\host\n\  string, host to connect\n\\n\user\n\  string, user to connect as\n\\n\passwd\n\  string, password to use\n\\n\db\n\  string, database to use\n\\n\port\n\  integer, TCP/IP port to connect to\n\\n\unix_socket\n\  string, location of unix_socket (UNIX-ish only)\n\\n\conv\n\  mapping, maps MySQL FIELD_TYPE.* to Python functions which\n\  convert a string to the appropriate Python type\n\\n\connect_timeout\n\  number of seconds to wait before the connection\n\  attempt fails.\n\\n\compress\n\  if set, gzip compression is enabled\n\\n\named_pipe\n\  if set, connect to server via named pipe (Windows only)\n\\n\init_command\n\  command which is run once the connection is created\n\\n\read_default_file\n\  see the MySQL documentation for mysql_options()\n\\n\read_default_group\n\  see the MySQL documentation for mysql_options()\n\\n\client_flag\n\  client flags from MySQLdb.constants.CLIENT\n\\n\load_infile\n\  int, non-zero enables LOAD LOCAL INFILE, zero disables\n\\n\";static PyObject *_mysql_connect(	PyObject *self,	PyObject *args,	PyObject *kwargs){	_mysql_ConnectionObject *c=NULL;		c = MyAlloc(_mysql_ConnectionObject, _mysql_ConnectionObject_Type);	if (c == NULL) return NULL;	if (_mysql_ConnectionObject_Initialize(c, args, kwargs)) {		Py_DECREF(c);		c = NULL;	}	return (PyObject *) c;}#if PY_VERSION_HEX >= 0x02020000static int _mysql_ConnectionObject_traverse(	_mysql_ConnectionObject *self,	visitproc visit,	void *arg){	if (self->converter)		return visit(self->converter, arg);	return 0;}#endifstatic int _mysql_ConnectionObject_clear(	_mysql_ConnectionObject *self){	Py_XDECREF(self->converter);	self->converter = NULL;	return 0;}static char _mysql_ConnectionObject_close__doc__[] ="Close the connection. No further activity possible.";static PyObject *_mysql_ConnectionObject_close(	_mysql_ConnectionObject *self,	PyObject *args){	if (args) {		if (!PyArg_ParseTuple(args, "")) return NULL;	}	if (self->open) {		Py_BEGIN_ALLOW_THREADS		mysql_close(&(self->connection));		Py_END_ALLOW_THREADS		self->open = 0;	} else {		PyErr_SetString(_mysql_ProgrammingError,				"closing a closed connection");		return NULL;	}	_mysql_ConnectionObject_clear(self);	Py_INCREF(Py_None);	return Py_None;}static char _mysql_ConnectionObject_affected_rows__doc__ [] ="Return number of rows affected by the last query.\n\Non-standard. Use Cursor.rowcount.\n\";static PyObject *_mysql_ConnectionObject_affected_rows(	_mysql_ConnectionObject *self,	PyObject *args){	if (!PyArg_ParseTuple(args, "")) return NULL;	check_connection(self);	return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection)));}static char _mysql_debug__doc__[] ="Does a DBUG_PUSH with the given string.\n\mysql_debug() uses the Fred Fish debug library.\n\To use this function, you must compile the client library to\n\support debugging.\n\";static PyObject *_mysql_debug(	PyObject *self,	PyObject *args){	char *debug;	if (!PyArg_ParseTuple(args, "s", &debug)) return NULL;	mysql_debug(debug);	Py_INCREF(Py_None);	return Py_None;}static char _mysql_ConnectionObject_dump_debug_info__doc__[] ="Instructs the server to write some debug information to the\n\log. The connected user must have the process privilege for\n\this to work. Non-standard.\n\";static PyObject *_mysql_ConnectionObject_dump_debug_info(	_mysql_ConnectionObject *self,	PyObject *args){	int err;	if (!PyArg_ParseTuple(args, "")) return NULL;	check_connection(self);	Py_BEGIN_ALLOW_THREADS	err = mysql_dump_debug_info(&(self->connection));	Py_END_ALLOW_THREADS	if (err) return _mysql_Exception(self);	Py_INCREF(Py_None);	return Py_None;}static char _mysql_ConnectionObject_autocommit__doc__[] ="Set the autocommit mode. True values enable; False value disable.\n\";static PyObject *_mysql_ConnectionObject_autocommit(	_mysql_ConnectionObject *self,	PyObject *args){	int flag, err;	if (!PyArg_ParseTuple(args, "i", &flag)) return NULL;	Py_BEGIN_ALLOW_THREADS#if MYSQL_VERSION_ID >= 40100	err = mysql_autocommit(&(self->connection), flag);#else	{		char query[256];		snprintf(query, 256, "SET AUTOCOMMIT=%d", flag);		err = mysql_query(&(self->connection), query);	}#endif	Py_END_ALLOW_THREADS	if (err) return _mysql_Exception(self);	Py_INCREF(Py_None);	return Py_None;}		static char _mysql_ConnectionObject_commit__doc__[] ="Commits the current transaction\n\";static PyObject *_mysql_ConnectionObject_commit(	_mysql_ConnectionObject *self,	PyObject *args){	int err;	if (!PyArg_ParseTuple(args, "")) return NULL;	Py_BEGIN_ALLOW_THREADS#if MYSQL_VERSION_ID >= 40100	err = mysql_commit(&(self->connection));#else	err = mysql_query(&(self->connection), "COMMIT");#endif	Py_END_ALLOW_THREADS	if (err) return _mysql_Exception(self);	Py_INCREF(Py_None);	return Py_None;}		static char _mysql_ConnectionObject_rollback__doc__[] ="Rolls backs the current transaction\n\";static PyObject *_mysql_ConnectionObject_rollback(	_mysql_ConnectionObject *self,	PyObject *args){	int err;	if (!PyArg_ParseTuple(args, "")) return NULL;	Py_BEGIN_ALLOW_THREADS#if MYSQL_VERSION_ID >= 40100	err = mysql_rollback(&(self->connection));#else	err = mysql_query(&(self->connection), "ROLLBACK");#endif	Py_END_ALLOW_THREADS	if (err) return _mysql_Exception(self);	Py_INCREF(Py_None);	return Py_None;}		static char _mysql_ConnectionObject_next_result__doc__[] ="If more query results exist, next_result() reads the next query\n\results and returns the status back to application.\n\\n\After calling next_result() the state of the connection is as if\n\you had called query() for the next query. This means that you can\n\now call store_result(), warning_count(), affected_rows()\n\, and so forth. \n\\n\Returns 0 if there are more results; -1 if there are no more results\n\\n\Non-standard.\n\";static PyObject *_mysql_ConnectionObject_next_result(	_mysql_ConnectionObject *self,	PyObject *args){	int err;	if (!PyArg_ParseTuple(args, "")) return NULL;	Py_BEGIN_ALLOW_THREADS#if MYSQL_VERSION_ID >= 40100	err = mysql_next_result(&(self->connection));#else	err = -1;#endif	Py_END_ALLOW_THREADS	if (err > 0) return _mysql_Exception(self);	return PyInt_FromLong(err);}		#if MYSQL_VERSION_ID >= 40100static char _mysql_ConnectionObject_set_server_option__doc__[] ="set_server_option(option) -- Enables or disables an option\n\for the connection.\n\\n\Non-standard.\n\";static PyObject *_mysql_ConnectionObject_set_server_option(	_mysql_ConnectionObject *self,	PyObject *args){	int err, flags=0;	if (!PyArg_ParseTuple(args, "i", &flags))		return NULL;	Py_BEGIN_ALLOW_THREADS	err = mysql_set_server_option(&(self->connection), flags);	Py_END_ALLOW_THREADS	if (err) return _mysql_Exception(self);	return PyInt_FromLong(err);}		static char _mysql_ConnectionObject_sqlstate__doc__[] ="Returns a string containing the SQLSTATE error code\n\for the last error. The error code consists of five characters.\n\'00000' means \"no error.\" The values are specified by ANSI SQL\n\and ODBC. For a list of possible values, see section 23\n\Error Handling in MySQL in the MySQL Manual.\n\\n\Note that not all MySQL errors are yet mapped to SQLSTATE's.\n\The value 'HY000' (general error) is used for unmapped errors.\n\\n\Non-standard.\n\";static PyObject *_mysql_ConnectionObject_sqlstate(	_mysql_ConnectionObject *self,	PyObject *args){	if (!PyArg_ParseTuple(args, "")) return NULL;	return PyString_FromString(mysql_sqlstate(&(self->connection)));}		static char _mysql_ConnectionObject_warning_count__doc__[] ="Returns the number of warnings generated during execution\n\of the previous SQL statement.\n\\n\Non-standard.\n\";static PyObject *_mysql_ConnectionObject_warning_count(	_mysql_ConnectionObject *self,	PyObject *args){	if (!PyArg_ParseTuple(args, "")) return NULL;	return PyInt_FromLong(mysql_warning_count(&(self->connection)));}		#endifstatic char _mysql_ConnectionObject_errno__doc__[] ="Returns the error code for the most recently invoked API function\n\that can succeed or fail. A return value of zero means that no error\n\occurred.\n\";static PyObject *_mysql_ConnectionObject_errno(	_mysql_ConnectionObject *self,	PyObject *args){	if (!PyArg_ParseTuple(args, "")) return NULL;	check_connection(self);	return PyInt_FromLong((long)mysql_errno(&(self->connection)));}static char _mysql_ConnectionObject_error__doc__[] ="Returns the error message for the most recently invoked API function\n\that can succeed or fail. An empty string ("") is returned if no error\n\occurred.\n\";static PyObject *_mysql_ConnectionObject_error(	_mysql_ConnectionObject *self,	PyObject *args){	if (!PyArg_ParseTuple(args, "")) return NULL;	check_connection(self);	return PyString_FromString(mysql_error(&(self->connection)));}static char _mysql_escape_string__doc__[] ="escape_string(s) -- quote any SQL-interpreted characters in string s.\n\\n\Use connection.escape_string(s), if you use it at all.\n\_mysql.escape_string(s) cannot handle character sets. You are\n\probably better off using connection.escape(o) instead, since\n\it will escape entire sequences as well as strings.";static PyObject *_mysql_escape_string(	_mysql_ConnectionObject *self,	PyObject *args){	PyObject *str;	char *in, *out;	int len, size;	if (!PyArg_ParseTuple(args, "s#:escape_string", &in, &size)) return NULL;	str = PyString_FromStringAndSize((char *) NULL, size*2+1);	if (!str) return PyErr_NoMemory();	out = PyString_AS_STRING(str);#if MYSQL_VERSION_ID < 32321	len = mysql_escape_string(out, in, size);#else	check_server_init(NULL);	if (self && self->open)		len = mysql_real_escape_string(&(self->connection), out, in, size);	else		len = mysql_escape_string(out, in, size);#endif	if (_PyString_Resize(&str, len) < 0) return NULL;	return (str);}static char _mysql_string_literal__doc__[] ="string_literal(obj) -- converts object obj into a SQL string literal.\n\This means, any special SQL characters are escaped, and it is enclosed\n\within single quotes. In other words, it performs:\n\\n\\"'%s'\" % escape_string(str(obj))\n\\n\Use connection.string_literal(obj), if you use it at all.\n\_mysql.string_literal(obj) cannot handle character sets.";static PyObject *_mysql_string_literal(	_mysql_ConnectionObject *self,	PyObject *args){	PyObject *str, *s, *o, *d;	char *in, *out;	int len, size;	if (!PyArg_ParseTuple(args, "O|O:string_literal", &o, &d)) return NULL;	s = PyObject_Str(o);	if (!s) return NULL;	in = PyString_AsString(s);	size = PyString_GET_SIZE(s);	str = PyString_FromStringAndSize((char *) NULL, size*2+3);	if (!str) return PyErr_NoMemory();	out = PyString_AS_STRING(str);#if MYSQL_VERSION_ID < 32321	len = mysql_escape_string(out+1, in, size);#else

⌨️ 快捷键说明

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