在MySQL中运行dplyr,grepl(Running dplyr, grepl in MySQL)
我在SQL中有一个表,我正在测试
dplyr
。 我有两个输入日期范围和一个公司文本字段我在下面运行以下R代码
# Filter on the Customer and the date range the user selects mydf <- db %>% tbl(table) %>% filter(TableDate >= start_date & TableDate <= end_date) %>% filter(grepl('company', company_name)) %>% collect()
因此理论上,这应该从公司
company
start_date
和end_date
之间的单个表中选择信息, 如模糊匹配,因为公司名称包含X行业和Y合并的内容我收到如下错误
.local(conn,statement,...)出错:无法运行语句:执行命令被拒绝用户'闪亮'@'%'用于例程'mydb.GREPL'
当我看看sql
myDF <- tbl(db,table) myDF1 <- filter(myDF, TableDate >= start_date & TableDate <= end_date) myDF2 <- filter(myDF1, grepl('company', company_name)) explain(myDF2)
我得到了输出
<SQL> SELECT * FROM (SELECT * FROM `table` WHERE (`TableDate ` >= '2015-01-01' AND `TableDate ` <= '2015-06-01')) `lpknlorhcn` WHERE (GREPL('company', `company_name`))
.local(conn,statement,...)出错:无法运行语句:执行命令被拒绝用户'闪亮'@'%'用于例程'mydb.GREPL'
出于隐私原因,我已稍微修改了代码和输出
问题
有谁知道如何正确设置它(我知道它在mysql端的权限事项,但我不知道用户闪亮的执行访问权限在哪里
为什么解释计划中的SQL看起来如此有趣(例如它有两个where子句)以及什么是
lpknlorhcn
谢谢你的帮助
I have a table in SQL that I'm testing out
dplyr
. I have two inputs a date range and a text field which is a companyI run the following R code below
# Filter on the Customer and the date range the user selects mydf <- db %>% tbl(table) %>% filter(TableDate >= start_date & TableDate <= end_date) %>% filter(grepl('company', company_name)) %>% collect()
So in theory this should select information from a single table between
start_date
andend_date
for the companycompany
like a fuzzy match as the company names contain things like X industries and Y incorporatedI get an error like follows
Error in .local(conn, statement, ...) : could not run statement: execute command denied to user 'shiny'@'%' for routine 'mydb.GREPL'
when i have a look at the sql
myDF <- tbl(db,table) myDF1 <- filter(myDF, TableDate >= start_date & TableDate <= end_date) myDF2 <- filter(myDF1, grepl('company', company_name)) explain(myDF2)
I get the output
<SQL> SELECT * FROM (SELECT * FROM `table` WHERE (`TableDate ` >= '2015-01-01' AND `TableDate ` <= '2015-06-01')) `lpknlorhcn` WHERE (GREPL('company', `company_name`))
Error in .local(conn, statement, ...) : could not run statement: execute command denied to user 'shiny'@'%' for routine 'mydb.GREPL'
I have modified the code and output slightly for privacy reasons
Questions
Does anyone know how to set this up correctly (I know its a permissions thing on the mysql side but im not sure where as the user shiny has execute access
Why does the SQL in the explain plan look so funny (it has two where clauses for instance) and what is
lpknlorhcn
Thank you kindly for your help
原文:https://stackoverflow.com/questions/39618827
最满意答案
问题是你的
onreadystatechange
处理程序是一个闭包,它引用XHR
和element
的当前值。 由于这些更改在每个循环迭代中进行,每个处理程序在执行时都会引用XHR
和element
的最新值。 由于循环可能在第一个请求完成之前退出,所有处理程序都会引用最后分配的值。 为了解决这个问题,你需要在声明处理程序时捕获XHR
和element
的当前值。 最简单的方法是使用IIFE (您也可以创建一个单独的函数来返回所需的函数,并避免使用错误的变量创建闭包):XHR.onreadystatechange = (function(elt, req) { return function() { if (req.readyState == 4 && req.status == 200) { elt.innerHTML = friendlyExpress(JSON.parse(req.responseText).shares); } }; }(element, XHR));
The problem is that your
onreadystatechange
handler is a closure that refers to the current values ofXHR
andelement
. Since those change at each loop iteration, each handler, when it executes, refers to the latest values ofXHR
andelement
. Since the loop probably exits before the first request completes, all the handlers reference the last assigned values. To fix this, you need to capture the current values ofXHR
andelement
when declaring the handler. The easiest is with an IIFE (you could also create a separate function to return the required function and avoid creating the closure with the wrong variables):XHR.onreadystatechange = (function(elt, req) { return function() { if (req.readyState == 4 && req.status == 200) { elt.innerHTML = friendlyExpress(JSON.parse(req.responseText).shares); } }; }(element, XHR));
相关问答
更多-
对象内的XMLHttpRequest:如何保持对“this”的引用(XMLHttpRequest inside an object: how to keep the reference to “this”)[2024-02-16]
最简单的方法通常是将其值存储在本地变量中: myObject.prototype = { ajax: function (url) { // (url argument missing ?) var instance = this; // <-- store reference to the `this` value this.foo = 1; var req = new XMLHttpRequest(); req.open('GET', url, true); ... -
终于搞定了这个。 将其添加到顶部。 我想它应该适用于覆盖任何课程。 var FakeXMLHTTPRequests = require('fakexmlhttprequest') var requests = [] XMLHttpRequest = function() { var r = new FakeXMLHTTPRequests(arguments) requests.push(r) return r } 感谢这篇文章帮助我思考这个问题。 http://www.as ...
-
你的第二次尝试是非常接近的,但是你需要为每个请求创建一个单独的 XMLHttpRequest对象,在IIFE中,用***注释看到重定位的行: var idArray = ['1', '2', '3', '4', '5']; for(var i = 0;i < idArray.length;i++) { (function(i) { var xhr = new XMLHttpRequest(); // *** xhr.open('PUT', 'https://www. ...
-
JavaScript有一个自动内置垃圾收集器。 您可能想阅读这篇文章: JavaScript has an automatic built-in garbage collector. You might want to read this article:
-
块不会在JavaScript中创建范围; 只有功能。 因此,循环的每次迭代都共享相同的“xhr”变量,并且在每次迭代时都会覆盖其值。 要解决此问题,您可以创建一个单独的函数来执行xhr工作: function doXHR(fn) { var xhr = null; try {xhr = new XMLHttpRequest()} catch (e) {xhr = new ActiveXObject('Microsoft.XMLHTTP')} xhr.onreadystat ...
-
问题是你的onreadystatechange处理程序是一个闭包,它引用XHR和element的当前值。 由于这些更改在每个循环迭代中进行,每个处理程序在执行时都会引用XHR和element的最新值。 由于循环可能在第一个请求完成之前退出,所有处理程序都会引用最后分配的值。 为了解决这个问题,你需要在声明处理程序时捕获XHR和element的当前值。 最简单的方法是使用IIFE (您也可以创建一个单独的函数来返回所需的函数,并避免使用错误的变量创建闭包): XHR.onreadystatechange = ...
-
有人可以解释我为什么吗? 我如何获得我需要的所有JSON? 为了发送第二个请求,您需要等待第一个完成。 因此,如果您有兴趣按照数组顺序获取响应,则可以循环访问每个数组元素,并且只有在获得响应时才可以循环使用其余元素: var index = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"]; var request = new XMLHtt ...
-
那么XMLHTTPRequest()应该只返回javascript还是html? 它可以返回你喜欢的任何文本(也可能是二进制数据,但我从来没有见过这样的尝试,所以我不会发誓) 它可以不返回纯json文件吗? 它可以。 我认为相同的源策略不适用于XMLHttpRequest()调用。 相同的原产地政策绝对适用于XHR 为什么需要在DOM中注入标签以拨打第三方服务器? 通过从另一个来源加载脚本(带有嵌入数据)可以绕过同一个来源策略。 这是因为您没有使用JavaScript读取远程资源。 您正在执行一些附带嵌入数 ...
-
Rob W说:“你所展示的代码在各方面都表现得相同。” 没有人质疑,我也没有相反的证据,所以我接受这个作为答案。 谢谢Rob。 Rob W stated "The code you've shown behaves identical in all respects.". No-one contested that, and I have no evidence to the contrary, so I'm accepting that as the answer. Thanks Rob.
-
XMLHttpRequest无法加载(XMLHttpRequest cannot load)[2022-01-16]
遗憾的是,无法将XMLHttpRequest调用到本地资源,即使HTML本地存储也是如此。 因为你可以以编程方式读取本地文件的内容并将它们发送到网络中,这是不允许的。 i have found the answer of my question i have changed my script to function load_home(){ document.getElementById("content").innerHTML='