abscissa / mysql-native-experimental Goto Github PK
View Code? Open in Web Editor NEWOUTDATED: Use the official mysql-native: https://github.com/mysql-d/mysql-native
OUTDATED: Use the official mysql-native: https://github.com/mysql-d/mysql-native
Sorry, that I probably ask obviously questions, but I can't understand how to use isNull
There is also isNull http://semitwist.com/mysql-native-docs/v0.2.0-preview1/mysql/result/Row.html
Yeah, it's seems that I understand what do:
Row row = result.front;
when we do SQL request with query
it code above take only first element, but when we are doing:
Row row = prepared.queryRow();
it's return only one. And we do not do front
. Am I right?
But I still can't get .isNull to work in both cases.
What is the best practice to get from DB array of rows? Only foreach loop? Like:
Row rows = result.front;
foreach(row; rows)
x = row[0]
y = row[1]
....
Or is there any better (native way)?
upd: I tried, but get next error:
Examples of getting single entry show:
Row row = result.front;
what result.front;
is means here?
P.S. Big thanks for you driver!
What is the difference between next 2 functions:
/// Obtain a connection. If one isn't available, a new one will be created.
auto lockConnection() { return m_pool.lockConnection(); }
private Connection createConnection()
{
return new Connection(m_host, m_user, m_password, m_database, m_port, m_capFlags);
}
Why we should create connection in pool:
this.connection = mydb.lockConnection();
instead of:
this.connection = mydb.createConnection();
I want to print query body (possible in Exception text) or maybe after setting prepared args for test purposes.
By code look in next way:
try
{
PerformerStruct performerStruct;
Prepared prepared = prepare(database.connection, `SELECT id, login, password, sex, age, city from performers WHERE id=?`);
I know that I can create text variable with SELECT id, login, password, sex, age, city from performers WHERE id=?
on top of try and than do:
string myVariableWithSQLQuery = "SELECT id, login, password, sex, age, city from performers WHERE id=?"
try{
...
Prepared prepared = prepare(database.connection, myVariableWithSQLQuery);
But it's look ugly. Can I print already prepared query like:
writeln(prepared.SQLContent);
?
Plz look at this topic. I can't figure out why am getting exception
http://stackoverflow.com/questions/42180991/exception-after-connection-to-db-with-mysql-native-driver
And is it's correct to check connection status like this:
if(connection !is null)
As I understood we get data from DB in Variant
format. How I can convert it to standard D data types?
I tried:
Row row = result.front;
user.id = row[1].get!int;
and got error: Variant: attempting to use incompatible types immutable(char)[] and int
I found way:
user.id = row[1].convertsTo!(int);
But can't understand if I used it's as intended?
It can be very covenient to have schema for binding to row fetched from DB like:
// structured row annotations
struct PlaceFull {
uint id;
string name;
@optional string thumbnail; // ok to be null or missing
@optional GeoRef location; // nested fields ok to be null or missing
@optional @as("contact_person") string contact; // optional, and sourced from field contact_person instead
@ignore File tumbnail; // completely ignored
}
And used as:
// after fetchning
auto place = row.toStruct!PlaceFull;
furthure
// automated struct member uncamelcase
@uncamel struct PlaceOwner {
uint placeID; // matches placeID and place_id
uint locationId; // matches locationId and location_id
string ownerFirstName; // matches ownerFirstName and owner_first_name
string ownerLastName; // matches ownerLastName and owner_last_name
string feedURL; // matches feedURL and feed_url
}
subj.
I can't understand by description.
I am trying to do next:
Prepared prepared = prepare(connection, `SELECT id, login, password, group from 'users' WHERE login=?`);
prepared.setArgs(login);
ResultRange result = prepared.queryRow();
But I am getting error message that ResultRange is not callable with queryRow
constructor. Only acceptable is query
What PreparedImpl
is different from simple Prepared
? I tried it, but got message that it's can't be called because annotate as disabled
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.