MySQLで以下のようなエラーコードが出てきます
TypeError: this.onResult is not a function
どうやらこのSQL文を作った途端に発生するようです
sql.query('INSERT jinnjya(ID) VALUES (',i,');');
これは何が原因なのでしょうか?
一応下に、ソースコードを貼っておきます
/*eslint-env es6*/ //Node.js const requestPromise = require('request-promise'); const cheerio = require('cheerio'); //APIキー const {Client} = require("@googlemaps/google-maps-services-js"); const client = new Client({}); //MYSQL var mysql = require('mysql2'); var sql = mysql.createConnection({ host: 'localhost', user: 'root', password: 'root', port: '33306' }); sql.query('USE kekkai'); sql.query('SELECT * FROM jinnjya'); //初期設定 var first = 0; var end = 0; var name; var genn_jyuusyo; var touji_jyuusyo; var jyuusyo; var lat; var lng; var kami; (async () => { for(i = 1;i < 10;i++){ // httpリクエストを投げる const url = 'https://www.jinja-net.jp/jinja-all/jsearch3all.php?jinjya='+i; const response = await requestPromise(url); let $ = cheerio.load(response); // 取得したいデータのタグを指定する let title = $.text(); if(title.indexOf("検索条件のエラーです") != -1 || title.indexOf("条件に合ったデータは有りません") != -1){ }else{ console.log(i); sql.query('INSERT jinnjya(ID) VALUES (',i,');'); first = title.indexOf("神社名/通称")+6; end = title.indexOf("(フリガナ)"); name = title.substring(first, end); console.log(name); first = title.indexOf("現鎮座地")+4; end = title.indexOf("鎮座地調査年"); genn_jyuusyo = title.substring(first, end); first = title.indexOf("当時鎮座地")+5; end = title.indexOf("氏子地域"); touji_jyuusyo = title.substring(first, end); if(genn_jyuusyo.length < touji_jyuusyo.length){ jyuusyo = touji_jyuusyo; }else{ jyuusyo = genn_jyuusyo; } console.log(jyuusyo); //経度緯度を調べる client .geocode({ params: { address: jyuusyo, key: "AIzaSyAhyQa-JyxvarT47FNLLwj9gm2AOzV3Fzs", }, timeout:1000, // milliseconds }) .then((r) => { lat = r.data.results[0].geometry.location.lat; lng = r.data.results[0].geometry.location.lng; console.log(lat); console.log(lng); }) .catch((e) => { console.log(e.response.data.error_message); }); first = title.indexOf("主祭神")+3; end = title.lastIndexOf("フリガナ"); kami = title.substring(first, end); console.log(kami); } } })();
よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。