{ "info": { "author": "Exotic Objects LLC", "author_email": "git@extc.co", "bugtrack_url": null, "classifiers": [], "description": "# django-sql-server-bcp\nA utility for using mssql-tools BCP command with Django models.\n\n## Installation\n\n`pip install django-sql-server-bcp`\n\n## Requirements\n\nIf on Linux or Mac, install mssql-tools\n\n- For Mac: https://blogs.technet.microsoft.com/dataplatforminsider/2017/04/03/sql-server-command-line-tools-for-mac-preview-now-available/\n- For Linux: https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools\n\n\n1. On Linux, you must use Microsoft's driver in your odbc.ini. Otherwise, you'll get error `The DSN specified an unsupported driver.`.\nIf you're using pyodbc, your driver might look like:\n\n```\n[my_dsn_name]\nDriver = /usr/local/lib/libtdsodbc.so\n\n```\n\nChange it to (e.g. on Ubuntu):\n\n```\n[my_dsn_name]\nDriver = /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.6.0\n```\n\n2. Make sure `bcp` is is accessible to execute\n\n `sudo ln -s /opt/mssql-tools/bin/bcp /usr/local/bin/bcp`\n\n3. On Windows, using BCP via ODBC DNS name has proven to be painful or straight up broken. *django-sql-server-bcp* will prefer to connect via server HOST if available. So please set `HOST` in your django DATABSAES settings if you're having problems with getting BCP to work on Windows. You can leave `dsn` name in your django settings.\n\n\n## Usage\n\nExample Django model:\n\n\n```python\nfrom django.db import models\n\nclass StockPrice(models.Model):\n\n id = models.AutoField(primary_key=True)\n symbol = models.CharField(max_length=50)\n price = models.DecimalField(max_digits=15, decimal_places=4)\n timestamp = models.DateTimeField()\n\n\n```\n\n**Example BCP usage with `StockPrice` Model.**\n\nCreate a dict with the properties of your model. Then save via BCP:\n\n```python\nfrom random import random\nfrom models import StockPrice\n\n\nrows = []\nfor i in range(1, row_count):\n rows.append(dict(\n symbol='GOOG',\n price='%.2f' % (100 * random()),\n timestamp=str(datetime.datetime.now())\n ))\n\nbcp = BCP(StockPrice)\nbcp.save(rows)\nprint cp.save(rows)\n\n\n```\n\nYou should see output similar to the following:\n\n```\nStarting copy...\n\n499 rows copied.\nNetwork packet size (bytes): 4096\nClock Time (ms.) Total : 10 Average : (49900.0 rows per sec.)\n```\n\n## Caveats\n\n- String data cannot contain commas or newlines because bulk data file format is flimsy CSV.\n- Untested with long strings, dates, binary data.\n- Can't be used in a django transaction involving the same table that BCP is accessing - you'll end up locking the table and BCP won't be able to get a lock on it and BCP will wait indefinitely.\n\n## Troublehooting\n\n\n### The DSN specified an unsupported driver\n\n- On Linux, see Requirements above\n- On Windows, when you setup your ODBC data source in Windows, select \"SQL Server Native Client XX\". Not \"SQL Server\" or \"ODBC Driver XX for SQL Server\". For more info: https://docs.microsoft.com/en-us/sql/relational-databases/native-client-odbc-bulk-copy-operations/performing-bulk-copy-operations-odbc\n\n### The specified DSN contains an architecture mismatch between the Driver and Application\n\nIn Windows, This usually means BCP is 32-bit and you've trying to use a 64-bit ODBC connection. Add your ODBC connection under both 32-bit and 64-bit ODBC managers.\n\n### Could not find stored procedure 'sp_describe_first_result_set'.\n\nhttps://connect.microsoft.com/SQLServer/feedback/details/2777154/attempt-to-use-bcp-2016-to-export-from-sql-2008-or-earlier-fails-with-obscure-error-message\n\n> This error is due to the version of ODBC driver you are using: version 13. You can resolve this issue buy uninstalling the version from Program and features, and install the version 13.1 you can find: https://www.microsoft.com/en-us/download/details.aspx?id=53339\n\n### Unable to open BCP host data-file\nOn Linux, if www-data can't create a format file, it's a real pain to troubleshoot. `bcp` wants to access a few files covertly and fails without telling you why.\n - To turn on file access auditing, you may discover that `bcp` is trying to create a `/var/www/.odbc.ini` or access `/etc/localtime`\n\n```bash\n # install auditd\n sudo apt install auditd\n # Turn on file access auditing for all files where success=0\n sudo auditctl -w / -k bcp_debug\n # Run bcp commend as www-data\n # Then search audit log for failures\n sudo ausearch --interpret --exit -13\n```\n\nSearch the log for `success=no` and try to see what files bcp is being denied access to\n\n- For some reason, bcp tries to create `.odbc.ini` in www-data's home folder (e.g. /var/www/.odbc.ini). Make sure www-data's home folder is writeable by www-data\n- Another problem was that Microsoft docs say to pass `nul` to format command which, on Windows is a nul file but on Linux, bcp will try to open file named `nul` and fails with permission error. On Linux, pass `/dev/null` instead of `nul`.\n\n### BCP is hanging, stuck at \"Starting copy...\"\n\n- Make sure you are not calling BCP from within a django transaction that accessing the same table as BCP\n- Make sure you do not have any active transactions locking the table or hung transactions locking the table\n\nCheck for transaction:\n\n```sql\nSELECT S.*\nFROM sys.dm_exec_requests R\nINNER JOIN sys.dm_exec_sessions S\nON S.session_id = R.blocking_session_id;\n```", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ExoticObjects/django-sql-server-bcp", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-sql-server-bcp", "package_url": "https://pypi.org/project/django-sql-server-bcp/", "platform": "", "project_url": "https://pypi.org/project/django-sql-server-bcp/", "project_urls": { "Homepage": "https://github.com/ExoticObjects/django-sql-server-bcp" }, "release_url": "https://pypi.org/project/django-sql-server-bcp/0.1.10/", "requires_dist": null, "requires_python": "", "summary": "Utility for using mssql-tools BCP command with Django models", "version": "0.1.10" }, "last_serial": 3050976, "releases": { "0.1.10": [ { "comment_text": "", "digests": { "md5": "bc8c65fb99ead839db83d8ca664e774b", "sha256": "0ccdfe6141c5f7dc0586566d3bef0fb60b80b630b9f359c9f726e0e3ccda92b9" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.10.tar.gz", "has_sig": false, "md5_digest": "bc8c65fb99ead839db83d8ca664e774b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6689, "upload_time": "2017-07-26T20:11:55", "url": "https://files.pythonhosted.org/packages/2e/88/8cc72ce10d53a7a73cd794eca4eec161da1b3202c4aa7c567ff8a4859a7e/django-sql-server-bcp-0.1.10.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "734c057947d602d78c2e824e29758eb2", "sha256": "033b0762433f1c875958b1ccd19c0e1d81d8fb1b96206a5999eed8eec5249eb3" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.2.tar.gz", "has_sig": false, "md5_digest": "734c057947d602d78c2e824e29758eb2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3808, "upload_time": "2017-04-30T20:11:35", "url": "https://files.pythonhosted.org/packages/3e/42/ab2c7264017169916aebea4e411a563330f8502b77a5f87238a97c9b9aa3/django-sql-server-bcp-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "bd37a4733e091dd87ca64078088722f9", "sha256": "ced119c41c60c68a81921c05e50a58b548c6fca1e3b56bb228e8a3258570ecc1" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.3.tar.gz", "has_sig": false, "md5_digest": "bd37a4733e091dd87ca64078088722f9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4026, "upload_time": "2017-04-30T20:50:58", "url": "https://files.pythonhosted.org/packages/49/5f/39c91a69fcb6bc3572d13f59325d799f947581da698dbe3b34a9f212cbe3/django-sql-server-bcp-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "c980ffdb0b54607d0c692f88b3cc69e5", "sha256": "4bb8056bfe0c2c0075ee11d5ba367ba123734bf9a52f1ba9616e2cdbeffe2baa" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.4.tar.gz", "has_sig": false, "md5_digest": "c980ffdb0b54607d0c692f88b3cc69e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4567, "upload_time": "2017-04-30T23:34:05", "url": "https://files.pythonhosted.org/packages/7d/f8/0a4e47f8321fe8a4b45eeb515f4ad9b5ce69dbe155c4d4ffd9a9d7880e5c/django-sql-server-bcp-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "4b7a24ee5d7ce56f1e5bcf3d0126069f", "sha256": "357e31b6ae5ad474c5f882ecdff08df830f92a216a3a40ff321b7c7c4ab6bb5b" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.5.tar.gz", "has_sig": false, "md5_digest": "4b7a24ee5d7ce56f1e5bcf3d0126069f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5693, "upload_time": "2017-05-01T04:32:08", "url": "https://files.pythonhosted.org/packages/44/42/50e0c3a6d793e6f821536fc1dd30fa72d4677be87f7d8ba6e2fbfb958cea/django-sql-server-bcp-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "d401f7d60c46bec1e1aedd5ffd2ff248", "sha256": "9331f4ffab2d575e96cef3a54820eaada0600a9ec220b4fefcacb96b8f319d87" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.6.tar.gz", "has_sig": false, "md5_digest": "d401f7d60c46bec1e1aedd5ffd2ff248", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6548, "upload_time": "2017-05-01T22:38:57", "url": "https://files.pythonhosted.org/packages/20/54/d5213f87052547c95ed5b6baba537e7ccbedadf6b5f7d552479df23aeb6d/django-sql-server-bcp-0.1.6.tar.gz" } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "e08732d2d4fe57ce65af41bd62c9fc8d", "sha256": "6b9bbefaa20fcf45dd28a7ca2b81f67b8b0a89ab4a8863d1f39dced3026736d6" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.7.tar.gz", "has_sig": false, "md5_digest": "e08732d2d4fe57ce65af41bd62c9fc8d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6657, "upload_time": "2017-05-05T16:35:31", "url": "https://files.pythonhosted.org/packages/8b/6c/fbcfca8aafc9345551ff7f0442c89bd6ad8505ff340f5b814542593d3a63/django-sql-server-bcp-0.1.7.tar.gz" } ], "0.1.8": [ { "comment_text": "", "digests": { "md5": "a3a7778b8da0e6588ee8e3b2f9e69915", "sha256": "06c4275e43d215a04c610d7eca6872f8165b2c11e149f926b1bbbed66647434f" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.8.tar.gz", "has_sig": false, "md5_digest": "a3a7778b8da0e6588ee8e3b2f9e69915", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6700, "upload_time": "2017-05-19T03:55:41", "url": "https://files.pythonhosted.org/packages/81/ae/115467a4c97f75bbdf16bc2a405676297a55d234b904c0cab0a0bd072da9/django-sql-server-bcp-0.1.8.tar.gz" } ], "0.1.9": [ { "comment_text": "", "digests": { "md5": "8bc648e187c16aff2cb6a10ad6676f6b", "sha256": "e52c5f69bf444f532a62e5fa3e0c6ef01f00b8bc1f956d3d8a948c6679b46379" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.9.tar.gz", "has_sig": false, "md5_digest": "8bc648e187c16aff2cb6a10ad6676f6b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6695, "upload_time": "2017-07-26T19:59:20", "url": "https://files.pythonhosted.org/packages/ad/3a/b869a60d3822d70f7333cf2e7738981cfbd8a1e295eeff0a09815fc7cbbf/django-sql-server-bcp-0.1.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bc8c65fb99ead839db83d8ca664e774b", "sha256": "0ccdfe6141c5f7dc0586566d3bef0fb60b80b630b9f359c9f726e0e3ccda92b9" }, "downloads": -1, "filename": "django-sql-server-bcp-0.1.10.tar.gz", "has_sig": false, "md5_digest": "bc8c65fb99ead839db83d8ca664e774b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6689, "upload_time": "2017-07-26T20:11:55", "url": "https://files.pythonhosted.org/packages/2e/88/8cc72ce10d53a7a73cd794eca4eec161da1b3202c4aa7c567ff8a4859a7e/django-sql-server-bcp-0.1.10.tar.gz" } ] }