{ "info": { "author": "Michael Hampton", "author_email": "mirhampt@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "==========\nsql_interp\n==========\n\nSafely and easily interpolate Python variables into SQL based upon context. Most\nof your interaction with this package will be through the ``SQLInterp`` class::\n\n >>> from sql_interp import SQLInterp\n\n >>> person = {'last_name': 'Doe'}\n >>> criteria = {'first_name': ['Jane', 'John']}\n\n # Create an instance of SQLInterp and use the interp method to get the SQL and bind\n # variables ready to pass to your database cursor.\n >>> sqli = SQLInterp()\n >>> sqli.interp(\"UPDATE people SET\", person, \"WHERE\", criteria)\n ('UPDATE people SET last_name = ? WHERE first_name IN (?, ?)', ('Doe', 'Jane', 'John'))\n\nCaution\n========\n\nsql_interp works by assuming that any non-string variables passed to ``interp`` need\nto be treated as bind variables. This means that any arguments passed that are strings\nwill be treated as raw SQL. If you are not careful, this could lead to a SQL injection\nattack. To avoid this, if there is any chance at all that a variable is a string, you\nmust tell sql_interp that it is not raw SQL. You can do this with the ``esc`` method of\nthe ``SQLInterp`` object.\n\nHere is an example::\n\n >>> sqli = SQLInterp()\n >>> first_name = 'John'\n\n # The following is wrong! This could lead to a SQL injection attack.\n >>> sqli.interp(\"SELECT * FROM table WHERE first_name =\", first_name)\n ('SELECT * FROM table WHERE first_name = John', ())\n\n # This is the correct way.\n >>> sqli.interp(\"SELECT * FROM table WHERE first_name =\", sqli.esc(first_name))\n ('SELECT * FROM table WHERE first_name = ?', ('John',))\n\nThis does not apply if the string is a value in a list or dictionary as in the other\nexamples in this documentation.\n\nExamples\n========\n\nThe ``SQLInterp`` object can handle interpolating many different types::\n\n >>> age = 25\n >>> first_names = ['Jenny', 'John', 'Jeremy']\n >>> sqli.interp(\"UPDATE people SET age =\", age, \"WHERE first_names IN\", first_names)\n ('UPDATE people SET age = ? WHERE first_names IN (?, ?, ?)', (25, 'Jenny', 'John', 'Jeremy'))\n\nInterpolation is context sensitive, so the same type will be interpreted into SQL\ncorrectly for its usage::\n\n >>> punk_rockers = {'hair': 'pink', 'tattoos': 'three'}\n >>> accessories = {'piercings': 6, 'pants': 'vinyl'}\n >>> sqli.interp(\"UPDATE people SET\", accessories, \"WHERE\", punk_rockers)\n ('UPDATE people SET pants = ?, piercings = ? WHERE hair = ? AND tattoos = ?', ('vinyl', 6, 'pink', 'three'))\n\nAcknowledgments\n===============\n\nThis project is an indirect port of Perl's `SQL::Interp `_.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://bitbucket.org/mirhampt/sql_interp/", "keywords": "sql interpolation database", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "sql_interp", "package_url": "https://pypi.org/project/sql_interp/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/sql_interp/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://bitbucket.org/mirhampt/sql_interp/" }, "release_url": "https://pypi.org/project/sql_interp/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Interpolate Python variables into SQL statements.", "version": "0.1.0" }, "last_serial": 799998, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "9489cd96261ea3776cdb39d2e0fec7ff", "sha256": "86f7a656d3024c9175ebb8426cb8eb9c927561a48776316672f8369a34e154e7" }, "downloads": -1, "filename": "sql_interp-0.1.0.tar.gz", "has_sig": false, "md5_digest": "9489cd96261ea3776cdb39d2e0fec7ff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5237, "upload_time": "2010-04-08T03:58:54", "url": "https://files.pythonhosted.org/packages/f1/b5/a292548130f0262a2ed981791655974ab150dea4610794b9f03ad0b9cf75/sql_interp-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9489cd96261ea3776cdb39d2e0fec7ff", "sha256": "86f7a656d3024c9175ebb8426cb8eb9c927561a48776316672f8369a34e154e7" }, "downloads": -1, "filename": "sql_interp-0.1.0.tar.gz", "has_sig": false, "md5_digest": "9489cd96261ea3776cdb39d2e0fec7ff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5237, "upload_time": "2010-04-08T03:58:54", "url": "https://files.pythonhosted.org/packages/f1/b5/a292548130f0262a2ed981791655974ab150dea4610794b9f03ad0b9cf75/sql_interp-0.1.0.tar.gz" } ] }