{"id":189,"date":"2012-12-14T16:11:00","date_gmt":"2012-12-14T13:11:00","guid":{"rendered":"http:\/\/blog.successionua.com\/?p=189"},"modified":"2012-12-14T16:11:00","modified_gmt":"2012-12-14T13:11:00","slug":"sqlalchemy-%d0%b2-python","status":"publish","type":"post","link":"https:\/\/geckich.space\/?p=189","title":{"rendered":"SQLAlchemy \u0432 Python"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\u0412 python \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <b>MySQL<\/b> \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043a\u0430 <b><span style=\"color: #e69138;\">SQLAlchemy<\/span><\/b>.<\/p>\n<div>\u0423 \u043d\u0435\u0451 \u043c\u043d\u043e\u0433\u043e \u0432\u0441\u044f\u043a\u0438\u0445 \u0444\u0438\u0448\u0435\u043a-\u043f\u043b\u044e\u0448\u0435\u043a, \u043d\u043e \u044f \u0432 \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #6ab825; font-weight: bold;\">from<\/span> <span style=\"color: #447fcf; text-decoration: underline;\">sqlalchemy<\/span> <span style=\"color: #6ab825; font-weight: bold;\">import<\/span> <span style=\"color: #d0d0d0;\">create_engine<\/span><br \/><span style=\"color: #d0d0d0;\">b_connection_string<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #ed9d13;\">'mysql:\/\/user:password@localhost\/db_name'<\/span><br \/><span style=\"color: #d0d0d0;\">user<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #ed9d13;\">\"admin\"<\/span><br \/><span style=\"color: #d0d0d0;\">db<\/span> <span style=\"color: #d0d0d0;\">=<\/span>  <span style=\"color: #d0d0d0;\">create_engine(db_connection_string)<\/span><br \/><span style=\"color: #6ab825; font-weight: bold;\">for<\/span> <span style=\"color: #d0d0d0;\">row<\/span> <span style=\"color: #6ab825; font-weight: bold;\">in<\/span> <span style=\"color: #d0d0d0;\">db.execute(<\/span><span style=\"color: #ed9d13;\">\"select Permissions from users where Name = \"%s\"\"<\/span><span style=\"color: #d0d0d0;\">%(user)):<\/span><br \/>    <span style=\"color: #d0d0d0;\">result.append(<\/span><span style=\"color: #24909d;\">str<\/span><span style=\"color: #d0d0d0;\">(row))<\/span><br \/><\/pre>\n<\/div>\n<div>\u0413\u0434\u0435 \u0432 1\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043c\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0411\u0414, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0430\u043a\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435):<\/p>\n<p>[&#8220;(&#8216;On, Off, Bla-bla&#8217;,)&#8221;]<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043b\u0430\u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 , \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #d0d0d0;\">result<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">result[<\/span><span style=\"color: #3677a9;\">0<\/span><span style=\"color: #d0d0d0;\">].replace(<\/span><span style=\"color: #ed9d13;\">\"('\"<\/span><span style=\"color: #d0d0d0;\">,<\/span><span style=\"color: #ed9d13;\">\"\"<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><span style=\"color: #d0d0d0;\">result<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">result.replace(<\/span><span style=\"color: #ed9d13;\">\"',)\"<\/span><span style=\"color: #d0d0d0;\">,<\/span><span style=\"color: #ed9d13;\">\"\"<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><span style=\"color: #d0d0d0;\">result<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">result.replace(<\/span><span style=\"color: #ed9d13;\">\", \"<\/span><span style=\"color: #d0d0d0;\">,<\/span> <span style=\"color: #ed9d13;\">\",\"<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><\/pre>\n<\/div>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0432 result: &nbsp;&#8216;On, Off, Bla-bla&#8217;<\/div>\n<\/div>\n<\/div>\n<div>http:\/\/geckich.blogspot.com\/<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 python \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 MySQL \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043a\u0430 SQLAlchemy. \u0423 \u043d\u0435\u0451 \u043c\u043d\u043e\u0433\u043e \u0432\u0441\u044f\u043a\u0438\u0445 \u0444\u0438\u0448\u0435\u043a-\u043f\u043b\u044e\u0448\u0435\u043a, \u043d\u043e \u044f \u0432 \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430: from sqlalchemy import create_engineb_connection_string = &#8216;mysql:\/\/user:password@localhost\/db_name&#8217;user = &#8220;admin&#8221;db = create_engine(db_connection_string)for row in db.execute(&#8220;select Permissions from users where Name = &#8220;%s&#8221;&#8221;%(user)): result.append(str(row)) \u0413\u0434\u0435 \u0432 1\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043c\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 &hellip; <a href=\"https:\/\/geckich.space\/?p=189\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">SQLAlchemy \u0432 Python<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-189","post","type-post","status-publish","format-standard","hentry","category-programming"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=189"}],"version-history":[{"count":0,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions"}],"wp:attachment":[{"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}