我有两张表,一张是Information,一张是WorkForce
信息
劳动力
WorkForce中的twf column用来获取Information的id,假设return为1 ,但返回值0。如果Information中的id是 5,twf也应该是5。
首先我用a来表示选中的行数,然后将a的参数添加到addWorkForce中。 toast 总是显示 0 。
a=addInformation(name,weather,date2,status,first1[1],last1[1]);
Toast.makeText(getApplicationContext(),a+"",Toast.LENGTH_LONG).show();
addWorkForce(Sub, NoP, NoH,a);
添加信息功能
public long addInformation( final String name, final String weather, final String date2, final String status, final String timeIn, final String timeOut)
{
class AddInfo extends AsyncTask<String, Void, String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(WorkDetailsTable.this, "Please Wait",null, true, true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(String... params) {
HashMap<String, String> data = new HashMap<String,String>();
data.put(Config.KEY_USER_NAME,name);
data.put(Config.KEY_WEATHER,weather);
data.put(Config.KEY_DATE,date2);
data.put(Config.KEY_STATUS,status);
data.put(Config.KEY_TIMEIN,timeIn);
data.put(Config.KEY_TIMEOUT,timeOut);
RequestHandler rh=new RequestHandler();
String result = rh.sendPostRequest(Config.ADD_INFORMATION,data);
return result;
}
}
AddInfo ru = new AddInfo();
ru.execute(name,weather,date2,status,timeIn,timeOut);
return 0;
}
有人可以帮我解决问题吗?
addInformation.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting values
$name = $_POST['name'];
$weather = $_POST['weather'];
$date = $_POST['date'];
$status = $_POST['status'];
$timeIn = $_POST['timeIn'];
$timeOut = $_POST['timeOut'];
//Creating an sql query
$sql = "INSERT INTO information(name, weather, date, status, time_in, time_out) VALUES ('$name','$weather','$date', '$status', '$timeIn', '$timeOut')";
//Importing our db connection script
require_once('dbConnect.php');
//Executing query to database
if(mysqli_query($con,$sql)){
echo 'Information Added Successfully';
}else{
echo 'Could Not Add Information';
}
//Closing the database
mysqli_close($con);
}
?>
这就是我使用代码将行插入到 sqlite 中的方式,它可以工作
a = ts.insertTimeSheet(name, weather, date2, status, first1[1], last1[1]);
时间表
public long insertTimeSheet(String name, String weather, String date, String status, String TimeIn, String TimeOut) {
database = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(MyDatabaseHelper.Name, name);
values.put(MyDatabaseHelper.Weather, weather);
values.put(MyDatabaseHelper.Date, date);
values.put(MyDatabaseHelper.Status, status);
values.put(MyDatabaseHelper.TimeIn_Info, TimeIn);
values.put(MyDatabaseHelper.TimeOut_Info, TimeOut);
return database.insert(MyDatabaseHelper.TABLE_INFO, null, values); // if the id in Information is 5, twf display 5 too
最佳答案
根据您的代码添加信息:
a=addInformation(name,weather,date2,status,first1[1],last1[1]);
这里,您在主线程上调用 addInformation 并将返回值保存到变量 a。但问题是,您添加信息的实际实现是在 AsyncTask 的 doInBackground 中完成的,它实际上在工作线程(异步调用)上完成了这项工作,所以你总是会得到a=0 的默认值(因为 a 很长)。
您需要做的是将您的代码移动到 AsyncTask 的 onPostExecute 函数,如下所示:
public void addInformation( final String name, final String weather, final String date2, final String status, final String timeIn, final String timeOut)
{
class AddInfo extends AsyncTask<String, Void, String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(WorkDetailsTable.this, "Please Wait",null, true, true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
addWorkForce(Sub, NoP, NoH,a);
}
@Override
protected String doInBackground(String... params) {
HashMap<String, String> data = new HashMap<String,String>();
data.put(Config.KEY_USER_NAME,name);
data.put(Config.KEY_WEATHER,weather);
data.put(Config.KEY_DATE,date2);
data.put(Config.KEY_STATUS,status);
data.put(Config.KEY_TIMEIN,timeIn);
data.put(Config.KEY_TIMEOUT,timeOut);
RequestHandler rh=new RequestHandler();
String result = rh.sendPostRequest(Config.ADD_INFORMATION,data);
return result;
}
}
AddInfo ru = new AddInfo();
ru.execute(name,weather,date2,status,timeIn,timeOut);
}
还有另一种使用回调的方法。实现一个接口(interface),在你的 AsyncTask 完成后,你可以发送回调来做另一个工作。
关于php - 值总是返回 0,它应该返回插入的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34534111/
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我正在学习Rails,并阅读了关于乐观锁的内容。我已将类型为integer的lock_version列添加到我的articles表中。但现在每当我第一次尝试更新记录时,我都会收到StaleObjectError异常。这是我的迁移:classAddLockVersionToArticle当我尝试通过Rails控制台更新文章时:article=Article.first=>#我这样做:article.title="newtitle"article.save我明白了:(0.3ms)begintransaction(0.3ms)UPDATE"articles"SET"title"='dwdwd
我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案
所以我开始关注ruby,很多东西看起来不错,但我对隐式return语句很反感。我理解默认情况下让所有内容返回self或nil但不是语句的最后一个值。对我来说,它看起来非常脆弱(尤其是)如果你正在使用一个不打算返回某些东西的方法(尤其是一个改变状态/破坏性方法的函数!),其他人可能最终依赖于一个返回对方法的目的并不重要,并且有很大的改变机会。隐式返回有什么意义?有没有办法让事情变得更简单?总是有返回以防止隐含返回被认为是好的做法吗?我是不是太担心这个了?附言当人们想要从方法中返回特定的东西时,他们是否经常使用隐式返回,这不是让你组中的其他人更容易破坏彼此的代码吗?当然,记录一切并给出
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
为什么以下不同?Time.now.end_of_day==Time.now.end_of_day-0.days#falseTime.now.end_of_day.to_s==Time.now.end_of_day-0.days.to_s#true 最佳答案 因为纳秒数不同:ruby-1.9.2-p180:014>(Time.now.end_of_day-0.days).nsec=>999999000ruby-1.9.2-p180:015>Time.now.end_of_day.nsec=>999999998
在Ruby1.9.3(可能还有更早的版本,不确定)中,我试图弄清楚为什么Ruby的String#split方法会给我某些结果。我得到的结果似乎与我的预期相反。这是一个例子:"abcabc".split("b")#=>["a","ca","c"]"abcabc".split("a")#=>["","bc","bc"]"abcabc".split("c")#=>["ab","ab"]在这里,第一个示例返回的正是我所期望的。但在第二个示例中,我很困惑为什么#split返回零长度字符串作为返回数组的第一个值。这是什么原因呢?这是我所期望的:"abcabc".split("a")#=>["bc"
我一直在研究RubyKoans,我发现about_open_classes.rbkoan很有趣。特别是他们修改Integer#even?方法的最后一个测试。我想尝试一下这个概念,所以我打开了Irb并尝试运行Integer.respond_to?(:even?),但令我惊讶的是我得到了错误。然后我尝试了Fixnum.respond_to?(:even?)并得到了错误。我还尝试了Integer.respond_to?(:respond_to?)并得到了true,当我执行2.even?时,我也得到了true。我不知道发生了什么。谁能告诉我缺少什么? 最佳答案
使用rspec-rails3.0+,测试设置分为spec_helper和rails_helper我注意到生成的spec_helper不需要'rspec/rails'。这会导致zeus崩溃:spec_helper.rb:5:in`':undefinedmethod`configure'forRSpec:Module(NoMethodError)对thisissue最常见的回应是需要'rspec/rails'。但这是否会破坏仅使用spec_helper拆分rails规范和PORO规范的全部目的?或者这无关紧要,因为Zeus无论如何都会预加载Rails?我应该在我的spec_helper中做