CQL3:How does one avoid string being translated to ASCII? - erlang

I store my message and message id in cassandra database.I use https://github.com/matehat/cqerl client to work with ejabberd server for storing messages in cassandra database.I fetch records from cassandra database by select query using cqerl client:
cqerl:run_query(Pid,"SELECT * FROM CONV_DETAILS;").
I get list of binary integer as output as follows:
[<<0,0,0,9,52,57,49,56,52,48,52,57,55>>,
<<0,0,0,8,0,0,0,14,204,123,132,9>>,
<<0,0,0,2,110,111>>]
for the string "what are you doing now?".
How Can I avoid original string translated into ascii number as above?

Related

InfluxDB where query on tag values

I am trying to write a where clause on InfluxDB where the points are filtered via their key values.
My points have the field ping_to_google.com and the tag key user where user can be raspi-2 or raspi-5. This is a sample output of the database:
> select * from networks where time > now()-1h
name: networks
time ping_to_google.com user
---- ------------------ ----
1645494054000000000 3.528 raspi-2
1645494078000000000 3.578 raspi-2
I am using InfluxDB version 1.8 and InfluxDB shell version 1.6.4
This query will work!
select * from networks where time > now()-1h AND "user"='raspi-2'
According to the documentation of the influxDB you should only single qoute tag values:
Tags
tag_key <operator> ['tag_value']
Single quote tag values in the WHERE clause. Queries with unquoted tag values or double quoted tag values will not return any data and, in most cases, will not return an error.
They don't specify how to write tag keys. It is crazy that the database does not produce any errors in most cases. Also, it's not clear (and very unexpected after reading this documentation) that the tag key should be double-qouted. But this works and is how to do it!

Is there a Way to get Neo4j APOC connection strings to accept spaces or \ characters?

I'm working on attempting to pull process data from OSI PI JDBC into my knowledge graph in Neo4j with the APOC library. Having trouble getting the authentication setup:
With the following CYPHER query I get the error Illegal character in path at index 48 (space between Integrated Security)
CALL apoc.load.jdbc("jdbc:pioledbent://[server]/DataSource=[server];Integrated Security=SSPI;","[AF Database].Asset.Element")
YIELD row
RETURN row.Name;
With this CYPHER query I am able get the JDBC driver to prompt for authentication but it always fails saying Invalid Credentials. Username must be non-empty.
CALL apoc.load.jdbc("jdbc:pioledbent://[server]/DataSource=[Server];DCA=file.dca;ProtocolOrder=https/Soap:5461,NetTcp:5462;","[AF Database].Asset.Element")
YIELD row
RETURN row.Name;
Does anyone know if APOC can accept spaces in the connection string so I can get the Integrated Security=SSPI query working?

grafana-influxdb get multiple rows for last timestamp

I am using telegraf-influxdb-grafana together. But I could not get rows for only last timestamp.
Here is what I am doing;
Collecting DB statistics(Running queries at that time) with Telegraf(exec plugin).
Storing output to influxdb
Trying to monitor running queries over grafana
But I need to get all rows at last timestamp.
Here is what I've tried;
> select * from postgresql_running_queries where time=(select max(time) from postgresql_running_queries)
ERR: error parsing query: found SELECT, expected identifier, string, number, bool at line 1, char 54
Here is what I want to see;
Time DB USER STATE QUERY
2017-06-06 14:25.00 mydb myuser active my_query
2017-06-06 14:25.00 mydb myuser idle in transaction my_query2
2017-06-06 14:25.00 mydb2 myuser2 active my_query3
Can any one help me to achive this?
I am open to any solution.
select last(fieldname) from measurment_name;
Query in this format will return last timestamp data from the InfluxDB.
But I am surprised with the fact that you are expecting 3 values for a single timestamp (unless you have different TAG values, refer this documentation how to store duplicate points). You will a ONLY ONE record for a given timestamp. InfluxDB overwrites previous content if there is another entry for same timestamp, here is why.
Your results will be something like (if you don't have different TAG value):
Time DB USER STATE QUERY
2017-06-06 14:25.00 mydb2 myuser2 active my_query3
EDIT:
Based on comment, my guess is you are using TAGs to differentiate, still above query should work, if not, you may try by adding WHERE clause.

Query Influxdb based on tags?

I have started playing around with Influxdb v0.13 and I have some dummy values in my test db where id is a tag and value is a field:
> SELECT * FROM dummy
name: dummy
--------------
time id value
1468276508161069051 1234 12345
1468276539152853428 613 352
1468276543470535110 613 4899
1468276553853436191 1234 12
I get no results returned when I run this query:
> SELECT * FROM dummy WHERE id=1234
but I do get the following when querying with the field instead:
> SELECT * FROM dummy WHERE value=12
name: dummy
--------------
time id value
1468276553853436191 1234 12
Am I doing something wrong here? I thought the point of tags were to be queried (since they are indexed and fields are not), but they seem to break my queries.
It appears that Influx will treat every tag key and value we insert as string and this is evidently shown in their official documentation.
See: https://docs.influxdata.com/influxdb/v0.13/guides/writing_data/
When writing points, you must specify an existing database in the db
query parameter. See the HTTP section on the Write Syntax page for a
complete list of the available query parameters. The body of the POST
- we call this the Line Protocol - contains the time-series data that you wish to store. They consist of a measurement, tags, fields, and a
timestamp. InfluxDB requires a measurement name. Strictly speaking,
tags are optional but most series include tags to differentiate data
sources and to make querying both easy and efficient. Both tag keys
and tag values are strings.
Note: the text in bold.
Hence to filter by tag key value - the query must be enquoted.
Example:
SELECT * FROM dummy WHERE id='1234'

How can I prevent SQL injections during CSV uploads?

I've just started learning about Rails security, and I'm wondering how I can avoid security issues while allowing users to upload CSV files into our database. We're using Postgres' "copy from stdin" functionality to upload the data from the CSV into a temp table, which is then used for upserts into another table. This is the basic code (thanks to this post):
conn = ActiveRecord::Base.connection_pool.checkout
raw = conn.raw_connection
raw.exec("COPY temp_table (col1, col2) FROM STDIN DELIMITER '|'")
# read column values from the CSV line by line in the following format:
# attributes = {column_1: 'column 1 data', column_2: 'column 2 data'}
# line = "#{attributes.values.join('|')}\n"
rc.put_copy_data line
# wrap up copy process & insert into & update primary table
I am wondering what I can or should do to sanitize the column values. We're using Rails 3.2 and Postgres 9.2.
No action is required; COPY never interprets the values as SQL syntax. Malformed CSV will produce an error due to bad quoting / incorrect column count. If you're sending your own data line-by-line you should probably exclude a line containing a single \. followed by a newline, but otherwise it's rather safe.
PostgreSQL doesn't sanitize the data in any way, it just handles it safely. So if you accept a string ');DROP TABLE customer;-- in your CSV it's quite safe in COPY. However, if your application reads that out of the database, assumes that "because it came from the database not the user it's safe," and interpolates it into an SQL string you're still just as stuffed.
Similarly, incorrect use of PL/PgSQL functions where EXECUTE is used with unsafe string concatenation will create problems. You must use of format and the %I or %L specifiers, use quote_literal / quote_ident, or (for literals) use EXECUTE ... USING.
This is not just true of COPY, it's the same if you do an INSERT of the manipulated data then use it unsafely after reading it back from the DB.

Resources