Is librdf_model_add writing the statements into the hash-storage?
I am having problem to run a sparql query to retrieve them. The db files are probably populated as their file size keep increasing, but when I attempt to perform sparql query to them I don't seem to get any result. Do I need to load the statements from the storage into the model manually before issuing a query?
the statement that issue the query
$query = librdf_new_query(
$world,
'sparql',
NULL,
<<<SPARQL
PREFIX sensei: <http://coolsilon.com/flickr_schema/>
SELECT ?a ?c
WHERE {?a ?b ?c}
SPARQL
,
NULL
);
$result = librdf_query_execute($query, $model);
var_dump(librdf_query_results_get_count($result)); // returns 0
I am using PHP (5.3.5) language binding, and my redland version is 1.0.12 running under Ubuntu Natty.
p/s: I checked again with postgresql storage, and the above code works :/
This is better asked on semantic overflow or the redland-dev list.
The most likely thing is the model has no data.
Use some of the librdf functions to print out the model or use a serializer.
Try the test.php for pointers in https://github.com/dajobe/redland-bindings/tree/master/php
Related
We have some very simple (id INTEGER PRIMARY KEY, data BYTE)-tables that I'm trying to retrieve the data from, but seem to run into some kind of data corruption. When accessing or retrieving the data-column e.g. via SELECT data FROM foobar WHERE id = 42 or SELECT LENGTH(data) FROM foo WHERE id = 42 I get
[HY000] [Informix][Informix ODBC Driver][Informix]Text/Byte subscript error. (-607) (SQLFetch)
which is obviously weird, as no byte subscript operator is used. It rather seems to me Informix is running into some kind of data corruption issue and is unable to retrieve the underlying BLOB. The query works if I explicitly exclude the offending row, so SELECT SUM(LENGTH(data)) FROM foo fails with the above error, while SELECT SUM(LENGTH(data)) FROM foo WHERE id NOT IN (42,...) succeeds.
For other rows, I retrieve an error
[01004] [Informix][Informix ODBC Driver]Data truncated. (-11003) (SQLGetData)
which also can only be mitigated by (finding and) excluding the offending row via their primary key.
First of all, is there a way to tell if this is a driver/odbc error or if the underlying data is actually corrupted? Is there a way to check the tables for data corruption, instead of running into this kind of problem one by one?
This is IBM Informix Dynamic Server Version 14.10.FC5WE
It sounds to me like running the same query, but using different tool or method, would give you an idea if it's the driver or the data itself.
If the data is corrupted, you can use the following to confirm the checksum value and identify:
CHECKSUM TABLE foobar;
Also, obviously updating the driver version is given, have you tried that?
I have a problem which I have been trying to resolve since yesterday. I am trying to pass an SQL Query via $wpdb on wordpress but I keep getting an empty array when I try to echo the result.
I have tried print_r and var_dump and both are giving me empty values. I would appreciate if someone can help as I cannot seem to get this thing sorted.
I have also tried calling the table via the db prefix with still no success.
Below is the code I have been using
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT CURRENT FROM upper_winds WHERE LVL=&level AND REGION=®ion AND VALID=&valid");
echo $results;
?>
P.S I have also tried get_var with the same problems.
Thanks
I noticed you weren't accounting for the wordpress database prefix, which could be why your results aren't showing up. You can prepend the prefix to your table name by using $wpdb->prefix.
I would suggest trying the following code:
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."upper_winds WHERE LVL = 'level' AND REGION = 'region' AND VALID = 'valid'");
echo $results;
I also just wanted to point out that it's important to use $wpdb->prepare to protect against SQL Injection attacks. Any time you are writing your own SQL, you need to use $wpdb->prepare. However when you use methods like $wpdb->insert or $wpdb->update that don't require you to write any SQL, then you do not need to use $wpdb->prepare because those functions take care of SQL Escaping for you. I can't provide sample code without knowing which of your values are strings and which values are integers.
See: http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks
you need to prefix your table more than likely this is wp_ etc..
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM `wp_upper_winds`
WHERE `LVL`='$level'
AND `REGION`='$region'
AND `VALID`='$valid'
");
var_dump ($results);
?>
you are looking for strings in your columns but using the &?
Thanks for your great advice and input. Eventually I got it to work.
The problem was not only in the code as I had been changing my code many times to try to find the solution. Eventually the main problem was nailed down to the table. Within one of the columns I had data which was something like this 'EU-VFR'. Apparently $wpdb did not pick up values with a '-'. Luckily with your help and some debugging I realised.
Here is what I got now http://howtoflyahelicopter.com/upper-winds-and-temp/
Thanks again :)
i have this query:
insert into orders (customers_id, customers_name) values ('51064', 'Šample Šample')
If i execute this query from PHP, my database record become
[51604, '?ample ?ample'] (if executed with MySQLi) or
[51604, 'Šample Šample'] (with mysql_query)
I also noticed that if i use the value from $_GET
insert into orders (customers_id, customers_name) values ('51064', {$_GET['name']})
it becomes [51064, 'Åample Åample']
BUT if i insert manually the query using software like 'Navicat' it saves the query with the correct character (so i think that the charset is the right one)
I need to save the character Š (and many others) in the right way from PHP.
Set the charset to be used when sending data back and forth from the database server.
$mysqli->set_charset("utf8")
This is preferred over
// Will not affect $mysqli->real_escape_string();
$mysqli->query("SET NAMES utf8");
See http://www.php.net/manual/en/mysqli.set-charset.php and http://www.php.net/manual/en/mysqlinfo.concepts.charset.php
set Mysql encoding before using the DB.
mysql_query("SET NAMES 'utf8'");
OR use the utf8 utf8_encode() utf8_decode() functions
LuaSQL, which seems to be the canonical library for most SQL database systems in Lua, doesn't seem to have any facilities for quoting/escaping values in queries. I'm writing an application that uses SQLite as a backend, and I'd love to use an interface like the one specified by Python's DB-API:
c.execute('select * from stocks where symbol=?', t)
but I'd even settle for something even dumber, like:
conn:execute("select * from stocks where symbol=" + luasql.sqlite.quote(t))
Are there any other Lua libraries that support quoting for SQLite? (LuaSQLite3 doesn't seem to.) Or am I missing something about LuaSQL? I'm worried about rolling my own solution (with regexes or something) and getting it wrong. Should I just write a wrapper for sqlite3_snprintf?
I haven't looked at LuaSQL in a while but last time I checked it didn't support it. I use Lua-Sqlite3.
require("sqlite3")
db = sqlite3.open_memory()
db:exec[[ CREATE TABLE tbl( first_name TEXT, last_name TEXT ); ]]
stmt = db:prepare[[ INSERT INTO tbl(first_name, last_name) VALUES(:first_name, :last_name) ]]
stmt:bind({first_name="hawkeye", last_name="pierce"}):exec()
stmt:bind({first_name="henry", last_name="blake"}):exec()
for r in db:rows("SELECT * FROM tbl") do
print(r.first_name,r.last_name)
end
LuaSQLite3 as well an any other low level binding to SQLite offers prepared statements with variable parameters; these use methods to bind values to the statement parameters. Since SQLite does not interpret the binding values, there is simply no possibility of an SQL injection. This is by far the safest (and best performing) approach.
uroc shows an example of using the bind methods with prepared statements.
By the way in Lua SQL there is an undocumented escape function for the sqlite3 driver in conn:escape where conn is a connection variable.
For example with the code
print ("con:escape works. test'test = "..con:escape("test'test"))
the result is:
con:escape works. test'test = test''test
I actually tried that to see what it'd do. Apparently there is also such a function for their postgres driver too. I found this by looking at the tests they had.
Hope this helps.
I want to output the query generated by a symfony propel select for testing purposes. Is there any way to do this? I know I can use the sf_debug bar, but sometimes I need to see the statement in a situation where the sf_debug bar hasn't loaded yet, or isn't going to load at all.
Timmow is right that there is a Criteria::toString() method, but it's not the magic _toString() method that's automatically called when the object is referenced as a string.
If you want to see the SQL you have to explicitly call Criteria::toString().
$c = new Criteria();
// HERE: add criteria
// what's it do?
echo $c->toString(); // oh, that's what it does
Propel Criteria objects have a toString method, so you should simply be able to echo / var_dump / log to a file the criteria object you are interested in
It also might be helpful to take a look at Day 6 of the Jobeet Tutorial, Debugging Propel generated SQL. If you're in the debug environment, the raw queries are output to the log files. Not 100% sure as I use Doctrine.
You'll get the generated SQL statement that way after you've build the criteria :
$params= array();
$resulting_sql_statement = BasePeer::createSelectSql($criteria,$params);