所以我在phpMyAdmin中看到了很多触发器示例,但语法对我来说没有意义......我太过于简单了。
我想在phpMyAdmin上创建一个约束。我有两个表,一个是基金,一个是Fund_Shares_Purchased。在基金中,有一个属性“total_available”,它是可以购买的股票总数。在Fund_Shares_Purchased中,有一个属性“quantity”,即某人已购买的股票数量。这两个表与“Fund_Name”属性相关。
我尝试了以下内容......
CREATE TRIGGER limitFundShares
BEFORE INSERT ON Fund_Shares_Purchased
BEGIN
IF (Fund.total_shares < NEW.quantity)
THEN
RAISERROR("You can't buy that many shares of the fund!")
END IF;
END;
非常感谢任何帮助或指导!
答案 0 :(得分:0)
以下是使用MySQL命令行客户端的测试示例:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.tab_fragment_1, container, false);
}
@SuppressLint("WrongViewCast")
@Override
public void onStart() {
super.onStart();
ParseUser currentUser = ParseUser.getCurrentUser();
String struser = currentUser.getUsername().toString();
iv = (ImageView) getView().findViewById(R.id.imageView1);
button1 = (Button) getView().findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECTED_PICTURE);
}
});
TextView txtUser = (TextView) getView().findViewById(R.id.txtuser);
txtUser.setText(struser);
logout = (Button) getView().findViewById(R.id.Logout);
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(v.getContext()); // set title
alertDialogBuilder.setTitle("Logout!");
// set dialog message
alertDialogBuilder
.setMessage("Do you want to logout with your account ? ")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
ConnectivityManager cManager = (ConnectivityManager) getActivity()
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cManager.getActiveNetworkInfo();
if (nInfo != null && nInfo.isConnected()) {
ParseUser.logOut();
getActivity().finish();
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Check your internet connection", Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode,resultCode, data);
switch (requestCode){
case SELECTED_PICTURE :
if (requestCode == SELECTED_PICTURE && resultCode == Activity.RESULT_OK){
Uri uri = data.getData();
String[]projection={MediaStore.Images.Media.DATA};
Cursor cursor=getActivity().getContentResolver().query(uri, projection, null, null, null);
cursor.moveToFirst();
int columnIndex=cursor.getColumnIndex(projection[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap YourSelectedImage= BitmapFactory.decodeFile(filePath);
Drawable d=new BitmapDrawable(YourSelectedImage);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
iv.setImageURI(Uri.parse(filePath));
}
}
break;
default:
break;
}
}
}
你应该能够将触发器创建语句粘贴到phpMyAdmin中,尽管我还没有测试过。