pgAdmin Editor Rails execute SQL from file - ruby-on-rails

Rails Code:
sql = File.read("#{Rails.root}/scripts/refresh.sql")
db_con = ActiveRecord::Base.connection
db_con.execute(sql)
file refresh.sql:
select 1;
If I create or modify file refresh.sql in pgAdmin (Ubuntu or Windows) I will get the following error:
PG::SyntaxError: ERROR: syntax error at or near "select"
LINE 1: select 1;
However, if I copy and paste the sql text into a text editor (sublime or gedit) and overwrite file refresh.sql the code runs

pgAdmin III main window
File => Options => Query file
Uncheck option "Read and write Unicode UTF-8 files"

Related

Cannot run Invoice ninja using docker

this is my first post here in SO, i want to use Invoice in my machine using Docker and access it locally
This are the steps i done
Cloned the repo https://github.com/invoiceninja/dockerfiles.git
Generate the APP_KEY
Question , when i generate the app key i got this error messages, are they suppossed to appear?
In Connection.php line 678:
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = ninja and table_name = accoun
ts and table_type = 'BASE TABLE')
In Exception.php line 18:
SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 38:
SQLSTATE[HY000] [2002] No such file or directory
Edit the env file with the APP_KEY=base64:...
Run the chown -R command
I want to acess Invoice Ninja locally so i changed the APP_URL to http://in5.test:8000
Changed the IP adress in the config/hosts file
-Finally i run docker-compose up and when i entered in5.test in the browser, i get a page not found but if i enter in5.test.localhost i get this page with errors
https://ibb.co/Zzs5w9b
Question, in the compose file there are some lines with
extra_hosts:
- "in5.localhost:192.168.0.124 " #host and ip
I changed the IP adress to match my local IP but when i do that and go to in5.test.localhost i get a 502 bad gateway nginx
Can someone tell me what i am doing wrong?

Does sqflite support query with 'CASE WHEN'?

I try to run a query via sqflite and get the error below:
DatabaseException(no such column: true (code 1): , while compiling: select (case true WHEN true THEN 111 END) xkey1 from tb_path
Here are the SQL steps:
create table tb_path(name text, age text);
db.rawQuery('select (case true WHEN true THEN 111 END) xkey1 from tb_path');
and the error above showed up.
If I try to run the SQL via SqlLite Expert Personal (a windows version SQLITE tool), this works fine.
When I try your steps in sqlite command line (Ubuntu 18.04):
$ select sqlite_version();
3.22.0
$ CREATE TABLE tb_path(from_ text, to_ text);
$ select (case true WHEN true THEN 111 END) xkey1 from tb_path;
Error: no such column: true
If I try with the latest binary download (3.27), I don't get the error:
$ select sqlite_version();
3.27.2
$ CREATE TABLE tb_path(from_ text, to_ text);
$ select (case true WHEN true THEN 111 END) xkey1 from tb_path;
So maybe such statement is only valid for newer sqlite version and since sqflite uses whatever the iOS/Android platform provides, it might not be supported yet (see a good list of shipping sqlite version on Android here: Version of SQLite used in Android?)

Nominatim failes with "Illegal query string"

I'm currently installing Nominatim using the Docker image that can be found at https://github.com/bringnow/docker-nominatim . However, when I send a query I get the following error:
Bad Request
Nominatim has encountered an error with your request.
Details: Illegal query string (not an UTF-8 string): paderborn
When I have a look at the console, I get the following error:
ERROR: relation "query_log" does not exist at character 13
STATEMENT: insert into query_log values ('2018-05-23 15:25:03.9961','paderborn','172.18.0.1')
ERROR: relation "new_query_log" does not exist at character 13
STATEMENT: insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format) values ('search','2018-05-23 15:25:03.9961','q=paderborn&polygon=1&viewbox=','172.18.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0','short_name:de,short_name:en-US,short_name:en,name:de,name:en-US,name:en,place_name:de,place_name:en-US,place_name:en,official_name:de,official_name:en-US,official_name:en,short_name,name,place_name,official_name,ref,type','')
ERROR: function make_standard_name(unknown) does not exist at character 8
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
STATEMENT: select make_standard_name('paderborn') as string
I already found an answer that proposes the following solution:
./utils/setup.php --create-functions --enable-diff-updates
However, this results in an error:
Functions
CREATE FUNCTION
ERROR: could not access file "/app/module/nominatim.so": No such file or directory
When I have a look at the file system, the file nominatim.so exists. So, this error is confusing.
Does anyone know a solution for that?
I found the mistake: We have two docker images, one for nominatim and one for postgis. The file /app/module/nominatim.so is created inside the nominatim image but also needed within the postgis image. The solution is to create a volume that allows to share the file.
Within docker-compose.yaml add the following lines to the nominatim service:
volumes:
- ./volumes/module:/mnt/module
and the following lines within postgis service:
volumes:
- ./volumes/module:/app/module
Further extend the entrypoint.sh:
log_info "==> Copy nominatim.so"
cp /app/module/nominatim.so /mnt/module/nominatim.so
Note that you have to rebuild the nominatim Docker image.

RMySQL not working with a cnf file

I am trying to connect to a MySQL server through R and it works perfect with the follwoing line:
con <- dbConnect(MySQL(), user="user", password="password",dbname="dbname", host="localhost", port=3306)
But, I would like to use a cnf file so that my user/apssword credentials donot appear in my code and tried the following:
rmysql.settingsfile<-"mydefault.cnf"
rmysql.db<-"test_db"
drv<-dbDriver("MySQL")
con<-dbConnect(drv,default.file=rmysql.settingsfile,group=rmysql.db)
And this is how my cnf file looks:
[test_db]
user=user
password=password
database=dbname
host=localhost
port=3306
It is in the same folder as in my R script which is my current working directory. But, I run into the following error:
Error in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'ODBC'#'localhost' (using password: NO)
)
Any suggestions, please?
Thanks so much
I had this problem very recently. RMySQL looks in the root directory for these files so you need to fully qualify the location of the file. i.e.:
rmysql.settingsfile<-"/home/MD-Tech/mydefault.cnf"
or
rmysql.settingsfile<-"c:\Users\MD-Tech\rfiles\mydefault.cnf"
Two things could be going on.
The CNF file should be encrypted, password should say password = ****. The MySQL documentation shows how to create a CNF file. Below would work for your code to create the CNF
shell> mysql_config_editor set --login-path=test_db --host=localhost --user=user --password
press enter without typing password, you will be prompted to enter it
The second thing is that user = NULL and password = NULL are missing as referenced in the src_mysql documentation
rmysql.settingsfile <- "~/.mylogin.cnf"
rmysql.db <- "test_db"
drv <- dbDriver("MySQL")
con <- dbConnect(drv, default.file = rmysql.settingsfile, group = rmysql.db, user = NULL, password = NULL)
When you add these and run the code, you should be set.
Fing something working at: https://www.r-bloggers.com/mysql-and-r/
Not in configuration file... but work.
con <- dbConnect(MySQL(),
user="me", password="nuts2u",
dbname="my_db", host="localhost")
Ya, getting this setup for the first time can be like pulling cats' teeth! Here is what I did while running R on a Droplet (Ubuntu 16.04, MySQL 5.7.16).
First, make sure you can at least login successfully to MySQL through the terminal
mysql -u kevin -p
Next, run R and verify that you can login in directly with dbConnect() using a user name and password
mydb = dbConnect(drv, user='kevin', password='ilovecats', dbname='catnapdb', host='127.0.0.1', port=3306)
Edit your mysql.cnf text file and at the bottom add a new group (exact name of this file and its location will depend on operating system and versions).
[whiskerpatrol]
user = kevin
password = ilovecats
host = 127.0.0.1
port = 3306
database = catnapdb

Using tdbloader.bat to upload a RDF file and querying using tdbquery.bat

I want to upload an RDF file using tdbloader.bat (C:\apache-jena-2.10.0\bat, in my case).
My turtle file is located in C:\apache-jena-2.10.0, and is named test.ttl. What will be the command line to load the turtle file using tdbloader.bat? After it is loaded, what would be a command line to query with tdbquery.bat?
I have used the following command-
tdbloader.bat -loc c:\apache-jena-2.10.0 test.ttl
But it returned a FileNotFound Exception.
The file test.ttl isnt in the same directory as bat files which is causing FileNotFound exception. A correction would be to copy test.ttl to C:\apache-jena-2.10.0\bat. After doing that execute command
tdbloader.bat -loc potato test.ttl.
This would load test.ttl to a folder named potato in same directory as tdbloader.bat. Hope it helps

Resources