String of username, password, firstname , last name, finding the string of names using index - neo4j-javascript

Index should not be less than 0 and not greater than 3
Index must be input to find the other details.
Enter the index:2
Username: step263
Password:5691youth
Firstname: Stephen
Lastname: curry

Related

Returning VALUE or NULL in Azure Cosmos DB subquery

The structure of the Person document I store in Azure Cosmos DB looks like this:
{
"id": "some-id",
"firstName": "John",
"lastName": "Doe",
"emails": [
{
"id": "email1",
"email": "test#testsite.com",
"isPrimary": true
},
{
"id": "email2",
"email": "test2#testsite.com",
"isPrimary": false
}
]
},
{
"id": "some-other-id",
"firstName": "Jane",
"lastName": "Doe",
"emails": []
}
I'm trying to return the basic info of a person, including his/her primary email if they have one and NULL for email if there isn't a primary email.
This is the SQL statement I'm using but it's not returning Jane Doe at all because "I think" the JOIN is making the email required data.
SELECT c.id, c.firstName, c.lastName, email
FROM c JOIN (SELECT e.email FROM e IN c.emails WHERE e.isPrimary = true) AS email
I also tried the following but that doesn't Jane Doe at all.
SELECT c.id, c.firstName, c.lastName, e.email
FROM c JOIN e IN c.emails
WHERE e.isPrimary = true
I thought the following worked but that also seems to filter out some documents where there's an email but not a primary one.
SELECT c.id, c.firstName, c.lastName, e.email
FROM c JOIN e IN c.emails
WHERE ARRAY_LENGTH(c.emails) = 0 OR e.isPrimary = true
Just to reiterate the requirements: I want ALL persons. If the person has one or more emails and one is the primary one, I want to include only the primary email in the result. If the person doesn't have any emails or has emails but not a primary one, I still want the person in the results but email should be NULL for that particular person.
It's easy to do a SELECT * FROM c but I only want to get the primary email if the person has one or a NULL if they don't.
SELECT c.firstName, c.lastName,
ARRAY(SELECT VALUE e.email FROM e in c.emails WHERE e.isPrimary = true or ARRAY_LENGTH(c.emails) = 0) as email
FROM c

How do i get sqlite to preserve string-type when it contains numbers only?

When i create a table with a STRING field with the nativescript-sqlite plugin, and enter a string "000123" (any string containing numbers only), and later fe3tch the record from the DB, it returns an int (123) and does not persist the string type. Is there any trick for this ? I enclose the code i use for creating, saving and returning the field....
creating the table ( the code has been abreviated )
var Name = 'users';
var TableDef = MedID INT, Naam STRING ,Pin STRING';
db.execSQL("CREATE TABLE IF NOT EXISTS " + Name +
"(id INTEGER PRIMARY KEY AUTOINCREMENT," + TableDef + " )")
.then(result => {...} );
Inserting a record
db.execSQL( "INSERT INTO users (MedID,Naam,Pin) VALUES (?, ?,?)",
[1,'John Doe','000123'] )
.then(id => {...} );
returning the pincode
var db_name = "scanapp.db";
new sqlite(db_name).then(db =>
{
db.all('select MedID, Naam, Pin from users order by ID ')
.then (rows => { console.log (rows[0][2]); });
});
The problem is in your table definition. Your Pin column was given a type of STRING.
In Sqlite, a column type is used to set the affinity of that column and control the preferred way to store values in that column. If you look at the rules for determining affinity type based on column type, you'll see that the type STRING defaults to the NUMERIC affinity, which means:
A column with NUMERIC affinity may contain values using all five storage classes. When text data is inserted into a NUMERIC column, the storage class of the text is converted to INTEGER or REAL (in order of preference) if such conversion is lossless and reversible.
The interesting thing here is the lossless and reversible bit, because this clearly isn't thanks to the leading 0's being stripped. I suspect that's a bug.
Anyways, the fix is to change your table definition to use types that have TEXT affinity - like TEXT, CHAR, etc, instead of the current STRING:
sqlite> create table foo(bar text, baz string);
sqlite> insert into foo values ('0012', '0012');
sqlite> select bar, typeof(bar), baz, typeof(baz) from foo;
bar typeof(bar) baz typeof(baz)
---------- ----------- ---------- -----------
0012 text 12 integer
Does the INSERT command execute without throwing any exceptions? I'm asking because you are explicitly inserting the MedID which is the table's primary AUTOINCREMENT field.
Your INSERT statement should be like:
db.execSQL("insert into users (Naam, Pin) values (?, ?)", ["John Doe", "000123"], function(err, id) {
console.log("The new record id is:", id);
});
Always check the err to make sure whether your command is successfully executed or not.
if (err) {
console.error("Failed to insert!", err);
} else {
console.log("The new record id is:", id);
}
Please check the NativeScript sqlite documentation for much more useful info.
Good luck.

Get custom field in sqlite

I have two tables
Signers:
CREATE TABLE signers (idSigner INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT, idNumber TEXT, rol TEXT)
and signatures:
CREATE TABLE signatures (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, documentId text, page INTEGER, coords TEXT, date TEXT, content TEXT, image TEXT, idSigner TEXT)
I want a select, that returns all the signers, and a custom column, with a true value, if the idSigner exists in the signatures table, and a false if not.
I have tryied with INNER JOINS, but I haven't achieved anything.
Expected result
idSigner name signed
1234 name1 true
2345 name2 false
3456 name3 false
Thanks!
To check whether a row exists, use EXISTS:
SELECT idSigner,
name,
EXISTS (SELECT 1
FROM signatures
WHERE idSigner = signers.idSigner
) AS signed
FROM signers;

sqlite FTS query issue

That's my query:
SELECT firstName, lastName FROM users WHERE users MATCH 'firstName:joh*'
I want to get all rows where lastName's length is 1+ (not null)
How should I modify my query?
This cannot be done with FTS; just use a normal expression:
SELECT firstName, lastName
FROM users
WHERE users MATCH 'firstName:joh*'
AND length(lastName) >= 1
(Please note that NULL and '' (empty string) are distinct values, and are both excluded.)

insert phone number in a table

How to insert a phone number into a table using asp.net?
string insertquery =
"insert customer (
id, name, address, gender, DOB, contactno, email, userid, password)
values
(#custid, #custname, #custaddress, #gender, #custdob,
#custcno, #custemail, #custuserid, #custpassword)";
Here custcno is the phone number.
sc.Parameters.AddWithValue("#custcno",Convert.ToInt32(txtcustcno.Text));
While running I'm getting error Input string was not in a correct format.
in table contactno is varchar(50)
The code is trying to convert the telephone number string to a number here:
Convert.ToInt32(txtcustcno.Text)
So, if it contains any non-numeric characters like dashes of parentheses then it'll throw an exception.
To just insert the string without first converting it, do this:
sc.Parameters.AddWithValue("#custcno", txtcustcno.Text);
I am not sure from the question: why Convert.ToInt32? many phone number formats have spaces, dashes, ( & ). these will cause Convert.ToInt32 to throw Input string was not in a correct format.
Preform input validation using ASP.NET validation controls (or whatever) and do this:
sc.Parameters.AddWithValue("#custcno",txtcustcno.Text);
Don't convert the phone number to an int. Change your parameter to:
sc.Parameters.AddWithValue("#custcno",txtcustcno.Text);

Resources