- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经尝试根据我在这个网站上找到的建议编辑我的代码,但似乎没有任何效果..我仍然不断收到以下 logcat 错误:
03-24 11:44:27.037: E/AndroidRuntime(1809): Caused by: android.database.sqlite.SQLiteException:
ambiguous column name: _id (code 1): , while compiling:
CREATE VIEW customerView AS SELECT _id AS _id, fName, lName, customerMeterId, customerMeterNumber, customerPlotNumber, _id FROM customers AS customers
INNER JOIN meters AS meters ON customerMeterId =_id
上面在logcat中引用的类:
public class ViewCustomers {
public static final String TABLE_CUSTOMER_VIEW = "customerView";
public static final String CUSTOMER_VIEW_ID = CustomerTableDetails.KEY_CUSTOMER_ID;
public static final String CUSTOMER_VIEW_FIRSTNAME = CustomerTableDetails.KEY_FIRST_NAME;
public static final String CUSTOMER_VIEW_LASTNAME = CustomerTableDetails.KEY_LAST_NAME;
public static final String CUSTOMER_VIEW_METER = CustomerTableDetails.KEY_METER_NUMBER;
public static final String CUSTOMER_VIEW_PLOT = CustomerTableDetails.KEY_PLOT_NUMBER;
public static final String CUSTOMER_VIEW_KEY_METER_ID = CustomerTableDetails.KEY_METER_ID;
private static final String CREATE_CUSTOMER_VIEW = ""
+ "CREATE VIEW " + TABLE_CUSTOMER_VIEW
+ " AS SELECT "+ CustomerTableDetails.KEY_CUSTOMER_ID+" AS _id,"+
" "+CustomerTableDetails.KEY_FIRST_NAME+","+
" "+CustomerTableDetails.KEY_LAST_NAME+","+
" "+CustomerTableDetails.KEY_METER_ID+","+
" "+CustomerTableDetails.KEY_METER_NUMBER+","+
" "+CustomerTableDetails.KEY_PLOT_NUMBER+","+
" "+MeterTableDetails.METER_ID+""+
" FROM "+CustomerTableDetails.TABLE_CUSTOMERS+" AS customers "+" INNER JOIN "+MeterTableDetails.TABLE_METERS+" AS meters"+
" ON "+CustomerTableDetails.KEY_METER_ID+" ="+MeterTableDetails.METER_ID;
public static void onCreate(SQLiteDatabase database) {
database.execSQL(CREATE_CUSTOMER_VIEW);
}
public static void onUpgrade(SQLiteDatabase database, int oldVersion,
int newVersion) {
Log.w(ViewCustomers.class.getName(), "Upgrading database from version "
+ oldVersion + " to " + newVersion
+ ", which will destroy all old data");
database.execSQL("DROP VIEW IF EXISTS " + ViewCustomers.TABLE_CUSTOMER_VIEW);
onCreate(database);
}
我什至使用了别名,但仍然没有解决方案。现在我不知道如何解决它。
编辑
更正后:
private static final String CREATE_CUSTOMER_VIEW = ""
+ "CREATE VIEW " + TABLE_CUSTOMER_VIEW
+ " AS SELECT "+MeterTableDetails.TABLE_METERS+"."+MeterTableDetails.METER_ID+""+" AS "+ MeterTableDetails.TABLE_METERS+"."+MeterTableDetails.METER_ID +","+
" "+CustomerTableDetails.KEY_FIRST_NAME+","+
" "+CustomerTableDetails.KEY_LAST_NAME+","+
" "+CustomerTableDetails.KEY_METER_ID+","+
" "+CustomerTableDetails.KEY_METER_NUMBER+","+
" "+CustomerTableDetails.KEY_PLOT_NUMBER+","+
" "+CustomerTableDetails.TABLE_CUSTOMERS+"."+ CustomerTableDetails.KEY_CUSTOMER_ID+
" FROM "+CustomerTableDetails.TABLE_CUSTOMERS+" AS customers "+" INNER JOIN "+MeterTableDetails.TABLE_METERS+" AS meters"+
" ON "+CustomerTableDetails.KEY_METER_ID+" ="+MeterTableDetails.TABLE_METERS+"."+MeterTableDetails.METER_ID;
编辑 2
03-24 13:58:24.687: I/create statement(3098): CREATE VIEW customerView AS SELECT meters._id AS meters._id, fName, lName, customerMeterId, customerMeterNumber,
customerPlotNumber, customers._id FROM customers AS customers
INNER JOIN meters AS meters ON customerMeterId = meters._id
最佳答案
使用 tablename._id 来引用上面查询中的 _id
改变:
CREATE VIEW customerView AS SELECT _id AS _id,
fName, lName, customerMeterId, customerMeterNumber,
customerPlotNumber, _id FROM customers AS customers
INNER JOIN meters AS meters ON customerMeterId =_id
到
CREATE VIEW customerView AS SELECT customers._id AS _id,
fName, lName, customerMeterId, customerMeterNumber, customerPlotNumber,
_id FROM customers AS customers
INNER JOIN meters AS meters ON
customerMeterId =customers._id // or meters._id -> whatever you think suits
或
CREATE VIEW customerView AS SELECT meters._id AS _id,
fName, lName, customerMeterId, customerMeterNumber, customerPlotNumber,
_id FROM customers AS customers
INNER JOIN meters AS meters ON customerMeterId =meters._id
关于android - android中反复出现不明确的列名_id sqlite错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22604721/
这个问题已经有答案了: node.js mongodb .. the (immutable) field '_id' was found to have been altered (5 个回答) 已关
db.books.update({bookId:"123461"},{$set:{"bookPrice":"6.23"}}) 我收到错误: update { q: { bookId: "1234
使用典型的 _id 列并连接表并在创建游标时选择所有列,将导致包含多个 _id 列的游标。 要访问特定的 _id 列,则需要使用实际偏移量,而不是列名。 使用硬编码的偏移量可能会有问题,它使代码更难阅
我使用 ASP .NET MVC4 WebAPI 并且我有一些类(class) public class Recipe { [BsonId] [BsonRepresentation(B
我正在尝试为 MongoDB 中的 _id 字段使用 UUID。 我有一个包装器结构来保存我的记录,如下所示: type mongoWrapper struct { ID uuid.
在 CodeIgniter 的 MongoDB 中进行更新时,出现以下错误: Type: MongoWriteConcernException Message: localhost:27017: Af
我想启动分片。如您所知,分片键非常重要。我发现,MongoDB doesn't ensure unique _id field values when using a shard key other
当我在ES 6.3.2上使用以下内容进行搜索时,没有问题: {“查询”:{“match_phrase_prefix”:{“_ id”:“ZX-bLmsBFOiwdS-Iwr24”}}} 但是,当我在E
我想运行以下查询: Group.find({program: {$in: [...]}}).lean().select('_id') 然后不得到回复: [{_id: ...}, {_id: ...},
我已将我的 ID 重命名为 _id,但仍然得到列“_id”不存在 ...我错过了什么吗? MyDatabaseelper.java public class MyDatabaseHelper exte
所以当我使用 int location = cursor.getColumnIndex(_ID) 它总是返回零,尽管 long locationId = cursor.getlong(getColum
我有一个看起来像这样的路径 path: '/speakers/singleDetails/:_id' 和一个具有这样的字段的架构 speakerId: { type: String,
userSchema={ username: { type: String, required: true, unique: true }, password: {
我正在尝试使用 updateOne 方法更新文档: UpdateResult r = coll.updateOne( eq("_id", id), this.getMapper().m
例如: 我有一个收藏“故事”其中每个文档的形式为: { '_id': 'story': } 现在每当我有一个故事时,如果它已经存在于“故事”中,我想要它的“_id”,否则插入一个带有“故事
这是我的 users.js(routes) for(var zz =0;zz < d.length; zz++){ temp
我在 Nodejs 中有一个数组,其中包含需要检索的 mongoDB 文档的 document _id 值。因此,我需要以这样的方式查询 mongoDB,使其返回 _id 值与我想要传入查询的数组中至
正如您在 NodeJS 代码中看到的那样,我正在从 URL 中提供的 Postman token 中获取用户,但我正在努力从给定的 token 号中取回 _id 属性。我想要的是decoded._id
我是 Android 新手。我有一个 SQLite 后端,其中每一行都是唯一的(想想一个人)。然后,我在每个人的 ListView 中显示这些数据。单击 ListView 项时,它将转到 subvie
他们是否都引用了联系人的同一个唯一 contactId? 最佳答案 他们应该这样做,但不能保证联系人是否已同步或聚合。您可能想尝试使用 LOOKUP_KEY相反。 关于Android dev : Ph
我是一名优秀的程序员,十分优秀!