VenderID and ProductID - hid

In this code:
The follow Const is set as Integers.
Private Const VendorID As Integer = &H1234 'Replace with your device's
Private Const ProductID As Integer = &H1234 'product and vendor IDs
Some product and vendor IDs have characters in them. Is this code for specific devices?
Thanks
Ralph

This is how you write hexadecimal values in VB.NET;
&H1234 is a hexadecimal value corresponding to 0x1234 in C#.

Related

How do I prevent the conversion of my STRING datatype into INT in sqflite? (flutter)

onCreate: (db, version) {
// Run the CREATE TABLE statement on the database.
return db.execute(
'CREATE TABLE favourites(id STRING PRIMARY KEY, stop STRING, stop_name STRING, bus STRING)',
);
//id shall consist of both stop and bus numbers
},
This is a segment of my code I used to create the table.
Future<List<Favourite>> getFavourites() async {
// Get a reference to the database.
final db = await database();
// Query the table for all The Dogs.
final List<Map<String, dynamic>> maps = await db.query('favourites');
print('maps line 165: $maps');
// Convert the List<Map<String, dynamic> into a List<Dog>.
return List.generate(maps.length, (i) {
return Favourite(
id: maps[i]['id'],
stop: maps[i]['stop'],
stopName: maps[i]['stopName'],
bus: maps[i]['bus'],
);
});
}
This function above is what I used to retrieve my data. However I got this error instead.
"Unhandled Exception: type 'int' is not a subtype of type 'String'". This means that the numbers that I had inserted into the table as String were converted to int. For example, stop = "09038" would be converted to 9038 as an int.
All my objects were in String.
String id = '0';
String stop = '0';
String stopName = '0';
String bus = '0';
Any solution to this?
There is no STRING data type in SQLite but it is allowed to be used because SQLite allows anything to be used as a data type.
When you define a column as STRING it is actually considered to have NUMERIC affinity as it is described in Determination Of Column Affinity.
From Type Affinity:
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 the text is a well-formed integer or real literal,
respectively.....
See a simplified demo.
All you have to do is define the columns that you want to behave as strings with the proper data type which is TEXT:
CREATE TABLE favourites(
id TEXT PRIMARY KEY,
stop TEXT,
stop_name TEXT,
bus TEXT
);

Why there is no "OR" operator in "...WhereInput" anymore? (prisma 1.25.4)

Prisma 1.23 had "OR,AND" in "...WhereInput", but in version 1.25.4 there is no "OR" operator, it's just "AND"
The database is mongodb
input ProvinceWhereInput {
AND: [ProvinceWhereInput!]
id: ID
id_not: ID
id_in: [ID!]
id_not_in: [ID!]
id_lt: ID
id_lte: ID
id_gt: ID
id_gte: ID
id_contains: ID
id_not_contains: ID
id_starts_with: ID
id_not_starts_with: ID
id_ends_with: ID
id_not_ends_with: ID
name: String
name_not: String
name_in: [String!]
name_not_in: [String!]
name_lt: String
name_lte: String
name_gt: String
name_gte: String
name_contains: String
name_not_contains: String
name_starts_with: String
name_not_starts_with: String
name_ends_with: String
name_not_ends_with: String
cities_some: CityWhereInput
}
These were disabled to allow for a quicker implementation of relational filters towards non-embedded types (cities_some in your case if it is a non-embedded type would not have been available in 1.23 for example).
You can follow this issue to get notified once they get reenabled.
https://github.com/prisma/prisma/issues/3897

MongoDb lte/ lt query behaving unexpectedly

I have connected to mongoDb using Spring. While creating query using Criteria, lt/ lte are not behaving the way they should i.e they are giving random outputs.
I want to Find a store within "x" miles of a zipcode
Query Creation/ execution code:
System.out.println("Please Enter your zipCode");
String zipCode = br.readLine();
System.out.println("Enter the distance (miles) to find store");
Integer distance = br.read();
Query query = new Query();
query.addCriteria(Criteria.where("storeDistance").lt(distance).and("storezipCode").is(zipCode));
List<Store>storeList = mongoOperation.find(query, Store.class);
if(storeList.isEmpty()){
System.out.println("Oops...no store found nearby...!!");
}else{
for(int idx=0; idx<storeList.size(); idx++){
System.out.println(storeList.get(idx).storeIdentificationumber+"\t"+storeList.get(idx).storeDistance);
}
}
Store model class
package com.storeApp.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
#Document(collection= "stores")
public class Store {
#Id
public String storeIdentificationumber;
public String storeName;
public String storezipCode;
public String storeCity;
public Integer storeDistance;
public Store(){}
public Store(String id, String name, String city, String zipCode, Integer distance){
this.storeIdentificationumber = id;
this.storeName = name;
this.storezipCode = zipCode;
this.storeCity = city;
this.storeDistance = distance;
}
}
Entries in Database :
{
"_id" : "store1",
"storeName" : "store One",
"storezipCode" : "123",
"storeCity" : "city",
"storeDistance" : 51
}
{
"_id" : "store03",
"storeName" : "Store Three",
"storezipCode" : "123",
"storeCity" : "city",
"storeDistance" : 54
}
Input :
Welcome to Store Application....!!
Please select choice from menu below
1. Add a Store
2. Find a Store
3. Remove a Store
2
Please Enter your zipCode
123
Enter the distance (miles) to find store
50
Expected Output :
Oops...no store found nearby...!!
Actual Output :
store1 51
According to the criteria and database, there should be no store whose distance is less than 50 miles, but still one record is being returned.
Issue is with Integer distance = br.read(); Assuming br is instance of BufferedReader. read method just reads a single character and gives the integer value of that character. You can verify by printing the distance variable.
You need to use readLine and convert the String number using Integer.parseInt
Yeah It's little weird, thing is if you want to add multiple options in your query, you should keep adding Criteria, One Criteria cannot take multiple fields.
In your case storezipCode is removing storeDistance from the Criteria chief field.
Try this
Query query = new Query();
query.addCriteria(Criteria.where("storeDistance").lt(distance));
query.addCriteria(Criteria.where("storezipCode").is(zipCode));
So question is in what scenario you would use 'and', You need to lookout for examples but it doesn't work the way we want it to work.

Data type of Github User ID

I'm using Github's API to fetch a user using https://api.github.com/user giving me something like this:
{
"login": "someuser123",
"id": 1234567,
"avatar_url": "https://avatars.githubusercontent.com/u/...",
...
}
but what is the data type for the id field? I can't seem to find any info on this in the API guides.
Found a bit of C# in the Octokit.net codebase that seems to indicate that User id is a 32-bit integer. From the User constructor (id is buried in the middle of the parameter list):
public User(string avatarUrl, string bio, string blog, int collaborators, string company, DateTimeOffset createdAt, int diskUsage, string email, int followers, int following, bool? hireable, string htmlUrl, int totalPrivateRepos, int id, string location, string login, string name, int ownedPrivateRepos, Plan plan, int privateGists, int publicGists, int publicRepos, string url, bool siteAdmin)
JSON has a limited set of data types, see https://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_example.
As the id is not null, true or false and not in quotes, it is a number. I won't expect decimal points, so it's something like an integer.

Is it possible to be able to accept many matrix parameters in my rest URL without having to declare them in my code?

I am developing a Restful WS which does the simple job of querying a DB and bringing back some data. The table that is querying has around 20 columns.
I want to be able to filter the my returned records by using the matrix parameters in the WHERE clause of my SQL statements.
For Example:
Lets say that we have the table People with the columns id, firstname, lastname
I want the URL http://localhost:808/myservice/people;firstname=nick
to bring me back all the people with firstname equals Nick (select * from people where firsname='Nick').
First of all, is this the correct practice to do that?
Second, in my tablet that I have 20 columns I must create a method in my Java code that will contain all the possible matrix parameters (see below) or there is a better way to do this?
public Response getPeople(#MatrixParam("id") String id,
#MatrixParam("firstname") String firstname,
#MatrixParam("lastname") String lastname,
#MatrixParam("antoherColumn") String antoherColumn,
#MatrixParam("antoherColumn") String antoherColumn,
#MatrixParam("antoherColumn") String antoherColumn,
#MatrixParam("antoherColumn") String antoherColumn,
#MatrixParam("antoherColumn") String antoherColumn,
#MatrixParam("antoherColumn") String antoherColumn,
#MatrixParam("antoherColumn") String antoherColumn,
#MatrixParam("antoherColumn") String antoherColumn,) {
}
Thanks in advance
First of all do not create your query by concatenating strings:
String q = "select * from where firstName = " + firstName //BAD!
You are asking for troubles like SQL injection attacks. If you use JDBC, use query parameters.
Since probably you want to use GET request, you can stick to your approach, use query parameters instead (#QueryParam). You might also consider the following approach:
http://localhost:808/myservice/people?filter=firstname:nick,lastName:smith
and method:
public Response getPeople(#QueryParam("filter") String filter) {
//if filter is not null, tokenize filter string by ',' then by ':'
//to get needed parameters
}
You should use #BeanParam in order to map the MatrixParam to an object.
This way you can keep the resource pretty simple, but still have the possibility to add more matrix parameters. Also, adding matrix params doesn't involve changing the resource at all. The #BeanParam works also with #PathParam and #QueryParam.
Example:
Consider this:
http://localhost:8081/myservice/people;firstname=nick,lastName=smith/?offset=3&limit=4
and then the resource:
#GET
public Response get(#BeanParam Filter filter, #BeanParam Paging paging) {
return Response.ok("some results").build();
}
and the Filter class looks like:
public class Filter {
public Filter(#MatrixParam("firstname") String firstname, #MatrixParam("lastname") String lastname) {}
}
and the Paging class:
public class Paging {
public Paging(#QueryParam("offset") int offset, #QueryParam("limit") int limit) { }
}
You can also use more filters, like Filter1, Filter2 etc in order to keep it more modular.
Using the matrix parameters the biggest advantage is caching. It makes even more sense if you have more than one level in you API, like ../animals;size=medium/mamals;fur=white/?limit=3&offset=4, because the query params would apply otherwise to all collections.